Skip to content
Snippets Groups Projects
Unverified Commit 2994caf4 authored by Alexander Rose's avatar Alexander Rose Committed by GitHub
Browse files

Merge pull request #779 from MadCatX/restore-vertex-array-per-program

Fix broken rendering caused by changes in 291d7abb
parents 2d0b17d9 e157993a
Branches
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ Note that since we don't clearly distinguish between a public and private interf ...@@ -9,6 +9,7 @@ Note that since we don't clearly distinguish between a public and private interf
- Avoid `renderMarkingDepth` for fully transparent renderables - Avoid `renderMarkingDepth` for fully transparent renderables
- Remove `camera.far` doubling workaround - Remove `camera.far` doubling workaround
- Add `ModifiersKeys.areNone` helper function - Add `ModifiersKeys.areNone` helper function
- Fix rendering issues caused by VAO reuse
- Add "Zoom All", "Orient Axes", "Reset Axes" buttons to the "Reset Camera" button - Add "Zoom All", "Orient Axes", "Reset Axes" buttons to the "Reset Camera" button
- Improve trackball move-state handling when key bindings use modifiers - Improve trackball move-state handling when key bindings use modifiers
......
...@@ -53,7 +53,7 @@ describe('renderer', () => { ...@@ -53,7 +53,7 @@ describe('renderer', () => {
scene.commit(); scene.commit();
expect(ctx.stats.resourceCounts.attribute).toBe(ctx.isWebGL2 ? 4 : 5); expect(ctx.stats.resourceCounts.attribute).toBe(ctx.isWebGL2 ? 4 : 5);
expect(ctx.stats.resourceCounts.texture).toBe(9); expect(ctx.stats.resourceCounts.texture).toBe(9);
expect(ctx.stats.resourceCounts.vertexArray).toBe(ctx.extensions.vertexArrayObject ? 1 : 0); expect(ctx.stats.resourceCounts.vertexArray).toBe(ctx.extensions.vertexArrayObject ? 6 : 0);
expect(ctx.stats.resourceCounts.program).toBe(6); expect(ctx.stats.resourceCounts.program).toBe(6);
expect(ctx.stats.resourceCounts.shader).toBe(12); expect(ctx.stats.resourceCounts.shader).toBe(12);
......
...@@ -144,7 +144,10 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode: ...@@ -144,7 +144,10 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode:
elementsBuffer = resources.elements(elements.ref.value); elementsBuffer = resources.elements(elements.ref.value);
} }
let vertexArray: VertexArray | null = vertexArrayObject ? resources.vertexArray(programs, attributeBuffers, elementsBuffer) : null; const vertexArrays: Record<string, VertexArray | null> = {};
for (const k of renderVariants) {
vertexArrays[k] = vertexArrayObject ? resources.vertexArray(programs[k], attributeBuffers, elementsBuffer) : null;
}
let drawCount: number = values.drawCount.ref.value; let drawCount: number = values.drawCount.ref.value;
let instanceCount: number = values.instanceCount.ref.value; let instanceCount: number = values.instanceCount.ref.value;
...@@ -170,6 +173,7 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode: ...@@ -170,6 +173,7 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode:
program.setUniforms(uniformValueEntries); program.setUniforms(uniformValueEntries);
program.bindTextures(textures, sharedTexturesCount); program.bindTextures(textures, sharedTexturesCount);
} else { } else {
const vertexArray = vertexArrays[variant];
if (program.id !== state.currentProgramId || program.id !== currentProgramId || if (program.id !== state.currentProgramId || program.id !== currentProgramId ||
materialId === -1 || materialId !== state.currentMaterialId materialId === -1 || materialId !== state.currentMaterialId
) { ) {
...@@ -291,9 +295,12 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode: ...@@ -291,9 +295,12 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode:
} }
if (valueChanges.attributes || valueChanges.defines || valueChanges.elements) { if (valueChanges.attributes || valueChanges.defines || valueChanges.elements) {
// console.log('program/defines or buffers changed, update vao'); // console.log('program/defines or buffers changed, update vaos');
for (const k of renderVariants) {
const vertexArray = vertexArrays[k];
if (vertexArray) vertexArray.destroy(); if (vertexArray) vertexArray.destroy();
vertexArray = vertexArrayObject ? resources.vertexArray(programs, attributeBuffers, elementsBuffer) : null; vertexArrays[k] = vertexArrayObject ? resources.vertexArray(programs[k], attributeBuffers, elementsBuffer) : null;
}
} }
for (let i = 0, il = textures.length; i < il; ++i) { for (let i = 0, il = textures.length; i < il; ++i) {
...@@ -341,8 +348,9 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode: ...@@ -341,8 +348,9 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode:
if (!destroyed) { if (!destroyed) {
for (const k of renderVariants) { for (const k of renderVariants) {
programs[k].destroy(); programs[k].destroy();
} const vertexArray = vertexArrays[k];
if (vertexArray) vertexArray.destroy(); if (vertexArray) vertexArray.destroy();
}
textures.forEach(([k, texture]) => { textures.forEach(([k, texture]) => {
// lifetime of textures with kind 'texture' is defined externally // lifetime of textures with kind 'texture' is defined externally
if (schema[k].kind !== 'texture') texture.destroy(); if (schema[k].kind !== 'texture') texture.destroy();
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import { ProgramProps, createProgram, Program, Programs } from './program'; import { ProgramProps, createProgram, Program } from './program';
import { ShaderType, createShader, Shader, ShaderProps } from './shader'; import { ShaderType, createShader, Shader, ShaderProps } from './shader';
import { GLRenderingContext } from './compat'; import { GLRenderingContext } from './compat';
import { Framebuffer, createFramebuffer } from './framebuffer'; import { Framebuffer, createFramebuffer } from './framebuffer';
...@@ -60,7 +60,7 @@ export interface WebGLResources { ...@@ -60,7 +60,7 @@ export interface WebGLResources {
shader: (type: ShaderType, source: string) => Shader shader: (type: ShaderType, source: string) => Shader
texture: (kind: TextureKind, format: TextureFormat, type: TextureType, filter: TextureFilter) => Texture, texture: (kind: TextureKind, format: TextureFormat, type: TextureType, filter: TextureFilter) => Texture,
cubeTexture: (faces: CubeFaces, mipmaps: boolean, onload?: () => void) => Texture, cubeTexture: (faces: CubeFaces, mipmaps: boolean, onload?: () => void) => Texture,
vertexArray: (programs: Programs, attributeBuffers: AttributeBuffers, elementsBuffer?: ElementsBuffer) => VertexArray, vertexArray: (program: Program, attributeBuffers: AttributeBuffers, elementsBuffer?: ElementsBuffer) => VertexArray,
getByteCounts: () => ByteCounts getByteCounts: () => ByteCounts
...@@ -142,8 +142,8 @@ export function createResources(gl: GLRenderingContext, state: WebGLState, stats ...@@ -142,8 +142,8 @@ export function createResources(gl: GLRenderingContext, state: WebGLState, stats
cubeTexture: (faces: CubeFaces, mipmaps: boolean, onload?: () => void) => { cubeTexture: (faces: CubeFaces, mipmaps: boolean, onload?: () => void) => {
return wrap('cubeTexture', createCubeTexture(gl, faces, mipmaps, onload)); return wrap('cubeTexture', createCubeTexture(gl, faces, mipmaps, onload));
}, },
vertexArray: (programs: Programs, attributeBuffers: AttributeBuffers, elementsBuffer?: ElementsBuffer) => { vertexArray: (program: Program, attributeBuffers: AttributeBuffers, elementsBuffer?: ElementsBuffer) => {
return wrap('vertexArray', createVertexArray(gl, extensions, programs, attributeBuffers, elementsBuffer)); return wrap('vertexArray', createVertexArray(gl, extensions, program, attributeBuffers, elementsBuffer));
}, },
getByteCounts: () => { getByteCounts: () => {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import { Programs } from './program'; import { Program } from './program';
import { ElementsBuffer, AttributeBuffers } from './buffer'; import { ElementsBuffer, AttributeBuffers } from './buffer';
import { WebGLExtensions } from './extensions'; import { WebGLExtensions } from './extensions';
import { idFactory } from '../../mol-util/id-factory'; import { idFactory } from '../../mol-util/id-factory';
...@@ -41,7 +41,7 @@ export interface VertexArray { ...@@ -41,7 +41,7 @@ export interface VertexArray {
destroy: () => void destroy: () => void
} }
export function createVertexArray(gl: GLRenderingContext, extensions: WebGLExtensions, programs: Programs, attributeBuffers: AttributeBuffers, elementsBuffer?: ElementsBuffer): VertexArray { export function createVertexArray(gl: GLRenderingContext, extensions: WebGLExtensions, program: Program, attributeBuffers: AttributeBuffers, elementsBuffer?: ElementsBuffer): VertexArray {
const id = getNextVertexArrayId(); const id = getNextVertexArrayId();
let vertexArray = getVertexArray(extensions); let vertexArray = getVertexArray(extensions);
let vertexArrayObject = getVertexArrayObject(extensions); let vertexArrayObject = getVertexArrayObject(extensions);
...@@ -49,7 +49,7 @@ export function createVertexArray(gl: GLRenderingContext, extensions: WebGLExten ...@@ -49,7 +49,7 @@ export function createVertexArray(gl: GLRenderingContext, extensions: WebGLExten
function update() { function update() {
vertexArrayObject.bindVertexArray(vertexArray); vertexArrayObject.bindVertexArray(vertexArray);
if (elementsBuffer) elementsBuffer.bind(); if (elementsBuffer) elementsBuffer.bind();
for (const p of Object.values(programs)) p.bindAttributes(attributeBuffers); program.bindAttributes(attributeBuffers);
vertexArrayObject.bindVertexArray(null); vertexArrayObject.bindVertexArray(null);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment