From 77d013b77580a126d282aed7484dbd0f209caf02 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Sat, 13 Feb 2021 11:30:13 -0800
Subject: [PATCH] webgl, ensure active attribute with divisor 0

- workaround for FF <85
- needed for `texture-mesh` geometry
---
 src/mol-gl/compute/marching-cubes/isosurface.ts     | 6 +++---
 src/mol-gl/shader/chunks/common-vert-params.glsl.ts | 8 +++++++-
 src/mol-gl/webgl/render-item.ts                     | 7 ++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/mol-gl/compute/marching-cubes/isosurface.ts b/src/mol-gl/compute/marching-cubes/isosurface.ts
index 994c55bfd..9b49abeff 100644
--- a/src/mol-gl/compute/marching-cubes/isosurface.ts
+++ b/src/mol-gl/compute/marching-cubes/isosurface.ts
@@ -195,17 +195,17 @@ export function createIsosurfaceBuffers(ctx: WebGLContext, activeVoxelsBase: Tex
 export function extractIsosurface(ctx: WebGLContext, volumeData: Texture, gridDim: Vec3, gridTexDim: Vec3, gridTexScale: Vec2, transform: Mat4, isoValue: number, packedGroup: boolean, vertexTexture?: Texture, groupTexture?: Texture, normalTexture?: Texture) {
     // console.time('calcActiveVoxels');
     const activeVoxelsTex = calcActiveVoxels(ctx, volumeData, gridDim, gridTexDim, isoValue, gridTexScale);
-    // ctx.webgl.waitForGpuCommandsCompleteSync();
+    // ctx.waitForGpuCommandsCompleteSync();
     // console.timeEnd('calcActiveVoxels');
 
     // console.time('createHistogramPyramid');
     const compacted = createHistogramPyramid(ctx, activeVoxelsTex, gridTexScale, gridTexDim);
-    // ctx.webgl.waitForGpuCommandsCompleteSync();
+    // ctx.waitForGpuCommandsCompleteSync();
     // console.timeEnd('createHistogramPyramid');
 
     // console.time('createIsosurfaceBuffers');
     const gv = createIsosurfaceBuffers(ctx, activeVoxelsTex, volumeData, compacted, gridDim, gridTexDim, transform, isoValue, packedGroup, vertexTexture, groupTexture, normalTexture);
-    // ctx.webgl.waitForGpuCommandsCompleteSync();
+    // ctx.waitForGpuCommandsCompleteSync();
     // console.timeEnd('createIsosurfaceBuffers');
 
     return gv;
diff --git a/src/mol-gl/shader/chunks/common-vert-params.glsl.ts b/src/mol-gl/shader/chunks/common-vert-params.glsl.ts
index 9ee8e3d95..635fbd434 100644
--- a/src/mol-gl/shader/chunks/common-vert-params.glsl.ts
+++ b/src/mol-gl/shader/chunks/common-vert-params.glsl.ts
@@ -41,6 +41,12 @@ varying vec3 vViewPosition;
     attribute float aVertex;
     #define VertexID int(aVertex)
 #else
-    #define VertexID gl_VertexID
+    // not using gl_VertexID but aVertex to ensure there is an active attribute with divisor 0
+    // since FF 85 this is not needed anymore but lets keep it for backwards compatibility
+    // https://bugzilla.mozilla.org/show_bug.cgi?id=1679693
+    // see also note in src/mol-gl/webgl/render-item.ts
+    attribute float aVertex;
+    #define VertexID int(aVertex)
+    // #define VertexID gl_VertexID
 #endif
 `;
\ No newline at end of file
diff --git a/src/mol-gl/webgl/render-item.ts b/src/mol-gl/webgl/render-item.ts
index 21b04ed4e..96498091e 100644
--- a/src/mol-gl/webgl/render-item.ts
+++ b/src/mol-gl/webgl/render-item.ts
@@ -112,7 +112,12 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode:
     const { instancedArrays, vertexArrayObject } = ctx.extensions;
 
     // emulate gl_VertexID when needed
-    if (!ctx.isWebGL2 && values.uVertexCount) {
+    // if (!ctx.isWebGL2 && values.uVertexCount) {
+    // not using gl_VertexID in WebGL2 but aVertex to ensure there is an active attribute with divisor 0
+    // since FF 85 this is not needed anymore but lets keep it for backwards compatibility
+    // https://bugzilla.mozilla.org/show_bug.cgi?id=1679693
+    // see also note in src/mol-gl/shader/chunks/common-vert-params.glsl.ts
+    if (values.uVertexCount) {
         const vertexCount = values.uVertexCount.ref.value;
         (values as any).aVertex = ValueCell.create(fillSerial(new Float32Array(vertexCount)));
         (schema as any).aVertex = AttributeSpec('float32', 1, 0);
-- 
GitLab