Skip to content

Commit f9ce3a1

Browse files
authored
[test] Fix WebGL errors in full_es2_sdlproc.c (#27834)
`draw_gear` in `full_es2_sdlproc.c` was calling `glDrawElements` with `GL_FLOAT` (an invalid index type in OpenGL ES 2.0 / WebGL) and passing an integer vertex offset (`gear->strips[n].first`) as the client-side `indices` pointer without a bound `GL_ELEMENT_ARRAY_BUFFER`. Construct a valid `GLushort` index array for each strip and pass `GL_UNSIGNED_SHORT` to `glDrawElements`, call `gears_reshape(300, 300)` before `gears_draw()`, and assert `glGetError() == GL_NO_ERROR`. Also remove the `-Wno-int-conversion` workaround from `test_fulles2_sdlproc`.
1 parent c0edf5b commit f9ce3a1

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎test/full_es2_sdlproc.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,14 @@ draw_gear(struct gear *gear, GLfloat *transform,
497497
glEnableVertexAttribArray(1);
498498

499499
/* Draw the triangle strips that comprise the gear */
500-
int n;
501-
for (n = 0; n < gear->nstrips; n++)
502-
glDrawElements(GL_TRIANGLE_STRIP, gear->strips[n].count, GL_FLOAT, gear->strips[n].first);
500+
for (int n = 0; n < gear->nstrips; n++) {
501+
GLushort indices[7];
502+
assert(gear->strips[n].count <= 7);
503+
for (int i = 0; i < gear->strips[n].count; i++) {
504+
indices[i] = gear->strips[n].first + i;
505+
}
506+
glDrawElements(GL_TRIANGLE_STRIP, gear->strips[n].count, GL_UNSIGNED_SHORT, indices);
507+
}
503508

504509
/* Disable the attributes */
505510
glDisableVertexAttribArray(1);
@@ -725,7 +730,9 @@ main(int argc, char *argv[])
725730

726731
gears_idle();
727732
gears_init();
733+
gears_reshape(300, 300);
728734
gears_draw();
735+
assert(glGetError() == GL_NO_ERROR);
729736

730737
return 0;
731738
}

‎test/test_browser.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ def test_glgears_animation(self, filename):
16681668

16691669
@requires_graphics_hardware
16701670
def test_fulles2_sdlproc(self):
1671-
self.btest_exit('full_es2_sdlproc.c', cflags=['-sGL_TESTING', '-sFULL_ES2', '-lGL', '-lSDL', '-lglut', '-sGL_ENABLE_GET_PROC_ADDRESS', '-Wno-int-conversion'])
1671+
self.btest_exit('full_es2_sdlproc.c', cflags=['-sGL_TESTING', '-sFULL_ES2', '-lGL', '-lSDL', '-lglut', '-sGL_ENABLE_GET_PROC_ADDRESS'])
16721672

16731673
@requires_graphics_hardware
16741674
@flaky('https://github.com/emscripten-core/emscripten/issues/25329')

0 commit comments

Comments
 (0)