1
votes

Note: the general question has been asked before, but this sort of error seems to really depend on specifics. Apologies if this is indeed a duplicate

I am getting the "out of range" error for the attribute a_Morph_0, despite checking numerous things:

  1. The attribute exists in the shader
  2. I am using VAO's, and tried releasing it (setting to null)
  3. The pipeline works fine with other data
  4. I encountered this error previously and fixed by just chopping stuff off the fragment shader, but that didn't help this time
  5. Switching the order of a_Position and a_Morph_0 changes the error accordingly, i.e. it still references a_Morph_0.

The vertex shader code:

attribute vec4 a_Position;
attribute vec4 a_Morph_0;
attribute vec4 a_Morph_1;
uniform float u_MorphWeights[2];

uniform mat4 u_MVPMatrix;
uniform mat4 u_ModelMatrix;    

void main() {
    vec4 m_Position = a_Position;

    m_Position += (u_MorphWeights[0] * a_Morph_0);
    m_Position += (u_MorphWeights[1] * a_Morph_1);

    gl_Position = u_MVPMatrix * m_Position;
}

Some relevant data:

  • data for elements: Uint16Array(3) [0, 1, 2]
  • data for attribute a_Position: Float32Array(9) [0, 0, 0, 1, 0, 0, 0.5, 0.5, 0]
  • data for attribute a_Morph_0: Float32Array(9) [0, 0, 0, 0, 0, 0, -1, 1, 0]
  • data for attribute a_Morph_1: Float32Array(9) [0, 0, 0, 0, 0, 0, 1, 1, 0]

The draw call is with count of 3. Specifically:

gl.drawElements(4, 3, 5123, 0);

Screenshot from Spector:

enter image description here

Anything else I should be checking?

1
"data for elements: Uint16Array(3) [0, 1, 2]"davidkomer

1 Answers

0
votes

I found my bug - if we look at the Spector output, the morphs attributes have a non-zero offsetPointer, i.e. 36 and 72

This isn't correct in my current implementation since the data is sliced to the correct segment before uploading it to the GPU buffer. Therefore the offset should always be 0.