Browse Source

better handling of render program changes

Alexander Rose 6 years ago
parent
commit
f7238c9a32
2 changed files with 6 additions and 8 deletions
  1. 0 2
      src/mol-gl/webgl/context.ts
  2. 6 6
      src/mol-gl/webgl/render-item.ts

+ 0 - 2
src/mol-gl/webgl/context.ts

@@ -137,7 +137,6 @@ export interface WebGLContext {
 
     currentProgramId: number
     currentMaterialId: number
-    currentRenderVariant: string
 
     bufferCount: number
     framebufferCount: number
@@ -266,7 +265,6 @@ export function createContext(gl: GLRenderingContext): WebGLContext {
 
         currentProgramId: -1,
         currentMaterialId: -1,
-        currentRenderVariant: '',
 
         bufferCount: 0,
         framebufferCount: 0,

+ 6 - 6
src/mol-gl/webgl/render-item.ts

@@ -130,6 +130,7 @@ export function createRenderItem(ctx: WebGLContext, drawMode: DrawMode, shaderCo
     const valueChanges = createValueChanges()
 
     let destroyed = false
+    let currentProgramId = -1
 
     return {
         id,
@@ -140,13 +141,12 @@ export function createRenderItem(ctx: WebGLContext, drawMode: DrawMode, shaderCo
             const program = programs[variant].value
             const vertexArray = vertexArrays[variant]
             program.setUniforms(uniformValueEntries)
-            if (ctx.currentRenderVariant !== variant) {
-                ctx.currentMaterialId = -1
-                ctx.currentRenderVariant = variant
-            }
-            if (materialId === -1 || materialId !== ctx.currentMaterialId) {
-                // console.log('materialId changed or -1', materialId)
+            if (program.id !== currentProgramId ||
+                materialId === -1 || materialId !== ctx.currentMaterialId
+            ) {
+                // console.log('program.id changed or materialId changed/-1', materialId)
                 program.setUniforms(materialUniformValueEntries)
+                currentProgramId = program.id
                 ctx.currentMaterialId = materialId
             }
             program.bindTextures(textures)