Skip to content

Commit ca22b30

Browse files
committed
testgles2: Use vertex buffer objects instead of client-side arrays.
GLES2 always has them, and they work without hacks on Emscripten, unlike client-side arrays. I cleaned it up slightly, but this patch was mostly written by @bing2008. Fixes #5258.
1 parent 57bc904 commit ca22b30

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/testgles2.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ typedef struct shader_data
372372

373373
int angle_x, angle_y, angle_z;
374374

375+
GLuint position_buffer;
376+
GLuint color_buffer;
375377
} shader_data;
376378

377379
static void
@@ -688,8 +690,18 @@ main(int argc, char *argv[])
688690
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
689691

690692
/* Populate attributes for position, color and texture coordinates etc. */
691-
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, _vertices));
692-
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, _colors));
693+
694+
GL_CHECK(ctx.glGenBuffers(1, &data->position_buffer));
695+
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->position_buffer));
696+
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices) * 4, _vertices, GL_STATIC_DRAW));
697+
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, 0));
698+
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
699+
700+
GL_CHECK(ctx.glGenBuffers(1, &data->color_buffer));
701+
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->color_buffer));
702+
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_colors) * 4, _colors, GL_STATIC_DRAW));
703+
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, 0));
704+
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
693705

694706
GL_CHECK(ctx.glEnable(GL_CULL_FACE));
695707
GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));

0 commit comments

Comments
 (0)