Skip to content
Snippets Groups Projects
Commit 4245eaf1 authored by Alexander Rose's avatar Alexander Rose
Browse files

improve use of gl_VertexID when possible

parent c41bd702
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ Note that since we don't clearly distinguish between a public and private interf ...@@ -7,6 +7,7 @@ Note that since we don't clearly distinguish between a public and private interf
## [Unreleased] ## [Unreleased]
- Fix superfluous shader varying - Fix superfluous shader varying
- Improve use of gl_VertexID when possible
## [v3.10.1] - 2022-06-26 ## [v3.10.1] - 2022-06-26
......
...@@ -309,6 +309,9 @@ function getGlsl300VertPrefix(extensions: WebGLExtensions, shaderExtensions: Sha ...@@ -309,6 +309,9 @@ function getGlsl300VertPrefix(extensions: WebGLExtensions, shaderExtensions: Sha
prefix.push('#define requiredDrawBuffers'); prefix.push('#define requiredDrawBuffers');
} }
} }
if (extensions.noNonInstancedActiveAttribs) {
prefix.push('#define noNonInstancedActiveAttribs');
}
prefix.push(glsl300VertPrefixCommon); prefix.push(glsl300VertPrefixCommon);
return prefix.join('\n') + '\n'; return prefix.join('\n') + '\n';
} }
......
...@@ -43,16 +43,10 @@ uniform int uPickType; ...@@ -43,16 +43,10 @@ uniform int uPickType;
varying vec3 vModelPosition; varying vec3 vModelPosition;
varying vec3 vViewPosition; varying vec3 vViewPosition;
#if __VERSION__ == 100 #if defined(noNonInstancedActiveAttribs)
attribute float aVertex; #define VertexID gl_VertexID
#define VertexID int(aVertex)
#else #else
// 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; attribute float aVertex;
#define VertexID int(aVertex) #define VertexID int(aVertex)
// #define VertexID gl_VertexID
#endif #endif
`; `;
\ No newline at end of file
...@@ -401,6 +401,20 @@ export function getDisjointTimerQuery(gl: GLRenderingContext): COMPAT_disjoint_t ...@@ -401,6 +401,20 @@ export function getDisjointTimerQuery(gl: GLRenderingContext): COMPAT_disjoint_t
} }
} }
export function getNoNonInstancedActiveAttribs(gl: GLRenderingContext): boolean {
if (!isWebGL2(gl)) return false;
if (typeof navigator !== 'undefined') {
const ffMatch = window.navigator.userAgent.match(/Firefox\/([0-9]+)\./);
if (!ffMatch) return true;
const ffVersion = parseInt(ffMatch[1]);
// supported since FF 85 (https://bugzilla.mozilla.org/show_bug.cgi?id=1679693)
return ffVersion >= 85;
}
return false;
}
// //
const TextureTestVertShader = ` const TextureTestVertShader = `
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers, getShaderTextureLod, COMPAT_shader_texture_lod, getDepthTexture, COMPAT_depth_texture, COMPAT_sRGB, getSRGB, getTextureHalfFloat, getTextureHalfFloatLinear, COMPAT_texture_half_float, COMPAT_texture_half_float_linear, COMPAT_color_buffer_half_float, getColorBufferHalfFloat, getVertexArrayObject, getDisjointTimerQuery, COMPAT_disjoint_timer_query } from './compat'; import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers, getShaderTextureLod, COMPAT_shader_texture_lod, getDepthTexture, COMPAT_depth_texture, COMPAT_sRGB, getSRGB, getTextureHalfFloat, getTextureHalfFloatLinear, COMPAT_texture_half_float, COMPAT_texture_half_float_linear, COMPAT_color_buffer_half_float, getColorBufferHalfFloat, getVertexArrayObject, getDisjointTimerQuery, COMPAT_disjoint_timer_query, getNoNonInstancedActiveAttribs } from './compat';
import { isDebugMode } from '../../mol-util/debug'; import { isDebugMode } from '../../mol-util/debug';
export type WebGLExtensions = { export type WebGLExtensions = {
...@@ -26,6 +26,8 @@ export type WebGLExtensions = { ...@@ -26,6 +26,8 @@ export type WebGLExtensions = {
shaderTextureLod: COMPAT_shader_texture_lod | null shaderTextureLod: COMPAT_shader_texture_lod | null
sRGB: COMPAT_sRGB | null sRGB: COMPAT_sRGB | null
disjointTimerQuery: COMPAT_disjoint_timer_query | null disjointTimerQuery: COMPAT_disjoint_timer_query | null
noNonInstancedActiveAttribs: boolean
} }
export function createExtensions(gl: GLRenderingContext): WebGLExtensions { export function createExtensions(gl: GLRenderingContext): WebGLExtensions {
...@@ -105,6 +107,8 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions { ...@@ -105,6 +107,8 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions {
console.log('Could not find support for "disjoint_timer_query"'); console.log('Could not find support for "disjoint_timer_query"');
} }
const noNonInstancedActiveAttribs = getNoNonInstancedActiveAttribs(gl);
return { return {
instancedArrays, instancedArrays,
standardDerivatives, standardDerivatives,
...@@ -124,5 +128,7 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions { ...@@ -124,5 +128,7 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions {
shaderTextureLod, shaderTextureLod,
sRGB, sRGB,
disjointTimerQuery, disjointTimerQuery,
noNonInstancedActiveAttribs,
}; };
} }
\ No newline at end of file
...@@ -112,12 +112,7 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode: ...@@ -112,12 +112,7 @@ export function createRenderItem<T extends string>(ctx: WebGLContext, drawMode:
const { instancedArrays, vertexArrayObject } = ctx.extensions; const { instancedArrays, vertexArrayObject } = ctx.extensions;
// emulate gl_VertexID when needed // emulate gl_VertexID when needed
// if (!ctx.isWebGL2 && values.uVertexCount) { if (values.uVertexCount && !ctx.extensions.noNonInstancedActiveAttribs) {
// 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; const vertexCount = values.uVertexCount.ref.value;
(values as any).aVertex = ValueCell.create(fillSerial(new Float32Array(vertexCount))); (values as any).aVertex = ValueCell.create(fillSerial(new Float32Array(vertexCount)));
(schema as any).aVertex = AttributeSpec('float32', 1, 0); (schema as any).aVertex = AttributeSpec('float32', 1, 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment