diff --git a/src/platform/graphics/webgl/webgl-graphics-device.js b/src/platform/graphics/webgl/webgl-graphics-device.js index 9124d088b20..6a0dcfa75b7 100644 --- a/src/platform/graphics/webgl/webgl-graphics-device.js +++ b/src/platform/graphics/webgl/webgl-graphics-device.js @@ -372,6 +372,7 @@ class WebglGraphicsDevice extends GraphicsDevice { } } + /** @type {WebGL2RenderingContext} */ let gl = null; // we always allocate the default framebuffer without antialiasing, so remove that option @@ -427,6 +428,26 @@ class WebglGraphicsDevice extends GraphicsDevice { // only enable ImageBitmap on chrome this.supportsImageBitmap = !isSafari && typeof ImageBitmap !== 'undefined'; + // supported sampler types + this._samplerTypes = new Set([ + ...[ + gl.SAMPLER_2D, + gl.SAMPLER_CUBE + ], + ...(this.isWebGL2 ? [ + gl.UNSIGNED_INT_SAMPLER_2D, + gl.INT_SAMPLER_2D, + gl.SAMPLER_2D_SHADOW, + gl.SAMPLER_CUBE_SHADOW, + gl.SAMPLER_3D, + gl.INT_SAMPLER_3D, + gl.UNSIGNED_INT_SAMPLER_3D, + gl.SAMPLER_2D_ARRAY, + gl.INT_SAMPLER_2D_ARRAY, + gl.UNSIGNED_INT_SAMPLER_2D_ARRAY + ] : []) + ]); + this.glAddress = [ gl.REPEAT, gl.CLAMP_TO_EDGE, diff --git a/src/platform/graphics/webgl/webgl-shader.js b/src/platform/graphics/webgl/webgl-shader.js index 1713fee3775..b47e35334fd 100644 --- a/src/platform/graphics/webgl/webgl-shader.js +++ b/src/platform/graphics/webgl/webgl-shader.js @@ -9,13 +9,13 @@ import { DebugGraphics } from '../debug-graphics.js'; let _totalCompileTime = 0; -const _vertexShaderBuiltins = [ +const _vertexShaderBuiltins = new Set([ 'gl_VertexID', 'gl_InstanceID', 'gl_DrawID', 'gl_BaseVertex', 'gl_BaseInstance' -]; +]); // class used to hold compiled WebGL vertex or fragment shaders in the device cache class CompiledShaderCache { @@ -304,14 +304,13 @@ class WebglShader { } // Query the program for each vertex buffer input (GLSL 'attribute') - let i = 0; const numAttributes = gl.getProgramParameter(glProgram, gl.ACTIVE_ATTRIBUTES); - while (i < numAttributes) { - const info = gl.getActiveAttrib(glProgram, i++); + for (let i = 0; i < numAttributes; i++) { + const info = gl.getActiveAttrib(glProgram, i); const location = gl.getAttribLocation(glProgram, info.name); // a built-in attributes for which we do not need to provide any data - if (_vertexShaderBuiltins.indexOf(info.name) !== -1) + if (_vertexShaderBuiltins.has(info.name)) continue; // Check attributes are correctly linked up @@ -325,32 +324,15 @@ class WebglShader { } // Query the program for each shader state (GLSL 'uniform') - i = 0; + const samplerTypes = device._samplerTypes; const numUniforms = gl.getProgramParameter(glProgram, gl.ACTIVE_UNIFORMS); - while (i < numUniforms) { - const info = gl.getActiveUniform(glProgram, i++); + for (let i = 0; i < numUniforms; i++) { + const info = gl.getActiveUniform(glProgram, i); const location = gl.getUniformLocation(glProgram, info.name); const shaderInput = new WebglShaderInput(device, info.name, device.pcUniformType[info.type], location); - if ( - info.type === gl.SAMPLER_2D || - info.type === gl.SAMPLER_CUBE || - ( - device.isWebGL2 && ( - info.type === gl.UNSIGNED_INT_SAMPLER_2D || - info.type === gl.INT_SAMPLER_2D || - info.type === gl.SAMPLER_2D_SHADOW || - info.type === gl.SAMPLER_CUBE_SHADOW || - info.type === gl.SAMPLER_3D || - info.type === gl.INT_SAMPLER_3D || - info.type === gl.UNSIGNED_INT_SAMPLER_3D || - info.type === gl.SAMPLER_2D_ARRAY || - info.type === gl.INT_SAMPLER_2D_ARRAY || - info.type === gl.UNSIGNED_INT_SAMPLER_2D_ARRAY - ) - ) - ) { + if (samplerTypes.has(info.type)) { this.samplers.push(shaderInput); } else { this.uniforms.push(shaderInput);