mat3 attribute in WebGL

时光毁灭记忆、已成空白 提交于 2019-12-08 02:09:22

问题


I'm attempting to use the ANGLE_instanced_arrays extension in WebGL to render multiple instances of an object with different mat3 transformation matrices. This is the code related to the buffer for my matrices:

//setup
this.shaderProgram.transformAttribute = gl.getAttribLocation(this.shaderProgram, "transform");
ext.vertexAttribDivisorANGLE(this.shaderProgram.transformAttribute, 1);
this.transformBuffer = gl.createBuffer();

//each render
gl.enableVertexAttribArray(this.shaderProgram.transformAttribute);
gl.bindBuffer(gl.ARRAY_BUFFER, this.transformBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([/*9 floats per instance*/]), gl.STREAM_DRAW);
gl.vertexAttribPointer(this.shaderProgram.transformAttribute, 9, gl.FLOAT, false, 0, 0);

And in my vertex shader, I just have 'attribute mat3 transform;' instead of 'uniform mat3 transform'.

When I execute the code above, I get an error on vertexAttribPointer: "vertexAttribPointer: bad size or stride".

This error persists if I set the stride to 36 (9 * 4-byte float) or 0 (auto?).

(As an aside, why do you have to specify the count, the type, and also the stride? Under what circumstances will the stride not be just the product of the count and the size of the type?)

来源:https://stackoverflow.com/questions/27326904/mat3-attribute-in-webgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!