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.
This commit is contained in:
Ryan C. Gordon 2022-01-24 22:32:58 -05:00
parent 57bc90403e
commit ca22b30e46
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 14 additions and 2 deletions

View File

@ -372,6 +372,8 @@ typedef struct shader_data
int angle_x, angle_y, angle_z; int angle_x, angle_y, angle_z;
GLuint position_buffer;
GLuint color_buffer;
} shader_data; } shader_data;
static void static void
@ -688,8 +690,18 @@ main(int argc, char *argv[])
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color)); GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
/* Populate attributes for position, color and texture coordinates etc. */ /* Populate attributes for position, color and texture coordinates etc. */
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, _vertices));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, _colors)); GL_CHECK(ctx.glGenBuffers(1, &data->position_buffer));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->position_buffer));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices) * 4, _vertices, GL_STATIC_DRAW));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, 0));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
GL_CHECK(ctx.glGenBuffers(1, &data->color_buffer));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->color_buffer));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_colors) * 4, _colors, GL_STATIC_DRAW));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, 0));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
GL_CHECK(ctx.glEnable(GL_CULL_FACE)); GL_CHECK(ctx.glEnable(GL_CULL_FACE));
GL_CHECK(ctx.glEnable(GL_DEPTH_TEST)); GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));