Closed satoshinm closed 7 years ago
Check if the two other forks I've found which use emscripten did anything about this:
The first error message at least is in rendering the sky:
void draw_triangles_3d(Attrib *attrib, GLuint buffer, int count) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glEnableVertexAttribArray(attrib->position);
glEnableVertexAttribArray(attrib->normal);
_glBindBuffer(34962,($1|0));
$3 = ((($0)) + 4|0);
$4 = HEAP32[$3>>2]|0;
_glEnableVertexAttribArray(($4|0)); // $4 = 0
$5 = ((($0)) + 8|0);
$6 = HEAP32[$5>>2]|0;
_glEnableVertexAttribArray(($6|0)); // $6 = -1
trying to pass -1 for the attribute index. Check return values of glGetAttribLocation()?
program = load_program(
"shaders/sky_vertex.glsl", "shaders/sky_fragment.glsl");
sky_attrib.program = program;
sky_attrib.position = glGetAttribLocation(program, "position");
sky_attrib.normal = glGetAttribLocation(program, "normal");
sky_attrib.uv = glGetAttribLocation(program, "uv");
printf("sky_attrib position=%d, normal=%d, uv=%d\n", sky_attrib.position, sky_attrib.normal, sky_attrib.uv);
0, -1 (error?), 1. Nonetheless, don't see anything wrong with the sky...
And on native, sky_attrib.normal is -1, as well. There is just no error printed. But shaders/sky_vertex.glsl does have a normal attribute:
#ifdef GL_ES
precision mediump float;
#endif
uniform mat4 matrix;
attribute vec4 position;
attribute vec3 normal;
attribute vec2 uv;
varying vec2 fragment_uv;
void main() {
gl_Position = matrix * position;
fragment_uv = uv;
}
--except, it is not used. Compiled out? Nothing uses sky_attrib.normal. It may be retained here for future expansion/consistency (draw_triangles_*
and Attrib
all have position, normal, uv). Is there any way to add a no-op in glsl so the attribute is referenced and available obviating these errors, or should they just be removed from the codebase? This task may be a matter of cleaning up and linting the GL code.
Added some if (attrib != -1)
checks to guard against enabling/pointing/disabling non-existent attributes in https://github.com/satoshinm/NetCraft/pull/53 this does resolve all of:
craft.js:7409 WebGL: INVALID_VALUE: enableVertexAttribArray: index out of range
craft.js:6940 WebGL: INVALID_VALUE: vertexAttribPointer: index out of range
craft.js:7548 WebGL: INVALID_VALUE: disableVertexAttribArray: index out of range
but not the other errors, there's a long way to go and adding all these checks may be overkill.
Merged https://github.com/satoshinm/NetCraft/pull/53, there is now only one set of WebGL errors remaining:
craft.js:8299 WebGL: INVALID_OPERATION: drawArrays: no buffer is bound to enabled attribute _glDrawArrays @ craft.js:8299 _draw_chunk @ craft.js:13381 _render_chunks @ craft.js:18208 craft.js:7875 WebGL: INVALID_OPERATION: vertexAttribPointer: no ARRAY_BUFFER is bound and offset is non-zero _glVertexAttribPointer @ craft.js:7875 _draw_chunk @ craft.js:13380 _render_chunks @ craft.js:18208 craft.js:8299 WebGL: INVALID_OPERATION: drawArrays: no buffer is bound to enabled attribute
see notes in https://github.com/satoshinm/NetCraft/pull/53#issuecomment-293142142
Hints at http://www.mjbshaw.com/2013/03/webgl-fixing-invalidoperation.html "It turns out the problem was being caused by me using two different shader programs, with each program having a different number of attributes"
https://www.khronos.org/registry/webgl/specs/1.0/#6.5
If a vertex attribute is enabled as an array via enableVertexAttribArray but no buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls to drawArrays or drawElements will generate an INVALID_OPERATION error.
The console log shows tons of WebGL errors, track down where these come from and why: