pex-context icon indicating copy to clipboard operation
pex-context copied to clipboard

Simplify instancing, instancedArrays and vertexArray polyfilling code

Open dmnsgn opened this issue 3 years ago • 3 comments

According to MDN WebGL_best_practices, ANGLE_instanced_arrays, OES_standard_derivatives, OES_element_index_uint and OES_vertex_array_object are universally supported in WebGL 1.

So we could remove the checks for their existence and just polyfill directly.

Related #114.

dmnsgn avatar May 19 '22 10:05 dmnsgn

From this:

  if (!gl.drawElementsInstanced) {
    const ext = gl.getExtension("ANGLE_instanced_arrays");
    if (!ext) {
      // TODO: this._caps[CAPS_INSTANCED_ARRAYS] = false;
      gl.drawElementsInstanced = () => {
        throw new Error(
          "gl.drawElementsInstanced not available. ANGLE_instanced_arrays not supported"
        );
      };
      gl.drawArraysInstanced = () => {
        throw new Error(
          "gl.drawArraysInstanced not available. ANGLE_instanced_arrays not supported"
        );
      };
      gl.vertexAttribDivisor = () => {
        throw new Error(
          "gl.vertexAttribDivisor not available. ANGLE_instanced_arrays not supported"
        );
      };
    } else {
      // TODO: this._caps[CAPS_INSTANCED_ARRAYS] = true;
      gl.drawElementsInstanced = ext.drawElementsInstancedANGLE.bind(ext);
      gl.drawArraysInstanced = ext.drawArraysInstancedANGLE.bind(ext);
      gl.vertexAttribDivisor = ext.vertexAttribDivisorANGLE.bind(ext);
      capabilities.instancedArrays = true;
      capabilities.instancing = true; // TODO: deprecate
    }
  } else {
    capabilities.instancedArrays = true;
    capabilities.instancing = true; // TODO: deprecate
  }

to this:

if (!gl.drawElementsInstanced) {
    const ext = gl.getExtension("ANGLE_instanced_arrays");
    gl.drawElementsInstanced = ext.drawElementsInstancedANGLE.bind(ext);
    gl.drawArraysInstanced = ext.drawArraysInstancedANGLE.bind(ext);
    gl.vertexAttribDivisor = ext.vertexAttribDivisorANGLE.bind(ext);
  }

and removing capabilities.instancing/instancedArrays/vertexArrayObject.

dmnsgn avatar May 19 '22 10:05 dmnsgn

Looks good

vorg avatar May 19 '22 11:05 vorg

OES_element_index_uint and OES_standard_derivatives still need a call to get activated.

dmnsgn avatar Jun 08 '22 10:06 dmnsgn