commit e13b7b128a55bc998bb1cc9075bd127d8f49b954
parent 1150c34eec22d26dfb8758e9bbb0df3e3b1f6242
Author: anon <anon@example.com>
Date: Fri, 16 Oct 2026 21:05:31 +0000
Retain renderer bindings to reduce per-draw driver work
Keep the single-context program, VAO and streamed buffers bound, and avoid resetting the framebuffer after each draw.
Lush control/candidate/control measurements reduce render-thread CPU from 41.2/40.4 ms to 35.3 ms per frame. Bronto runs at 60 FPS and 8.8 ms CPU per frame. Native tests and exact pixel comparison pass; rebuilt WASM scene verifies rendering, movement, inventory, map, audio and server connection.
Diffstat:
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/src/runtime/gl_renderer.c b/src/runtime/gl_renderer.c
@@ -151,7 +151,8 @@ int gl_renderer_initialize(void)
glUniform1i(glGetUniformLocation(program, "image1"), 1);
glGenSamplers(2, samplers);
- /* One streamed vertex/index pair is shared by this single rendering context. */
+ /* This context owns one program, vertex array and streamed buffer pair.
+ * Keep them bound for all draws and uniform updates. */
glGenVertexArrays(1, &vertex_array);
glGenBuffers(1, &vertex_buffer);
glGenBuffers(1, &index_buffer);
@@ -170,7 +171,6 @@ int gl_renderer_initialize(void)
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
- glBindVertexArray(0);
check_graphics("renderer initialization");
return 1;
}
@@ -349,16 +349,11 @@ void gl_target_draw(struct gl_target *target, unsigned primitive, const struct g
glPolygonOffset(-(float)depth_bias * .25f, -(float)depth_bias * .5f);
} else glDisable(GL_POLYGON_OFFSET_FILL);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glUseProgram(program);
- glBindVertexArray(vertex_array);
- glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, vertex_count * sizeof(*vertices), vertices, GL_STREAM_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_count * sizeof(*indices), indices, GL_STREAM_DRAW);
glDrawElements(primitive == 2 ? GL_LINES : GL_TRIANGLES, index_count, GL_UNSIGNED_SHORT, NULL);
glDisable(GL_SCISSOR_TEST);
- glBindVertexArray(0);
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ /* Leave the draw target bound; other framebuffer operations bind their own. */
/* Check errors at presentation/readback without synchronizing every draw. */
}
@@ -412,7 +407,6 @@ void gl_target_present(struct gl_target *target, const int32_t rectangle[4], int
void gl_renderer_set_texture(unsigned stage, const struct gl_texture_state *state)
{
assert(stage < 2);
- glUseProgram(program);
glUniform1i(texture_enabled[stage], state != NULL);
glActiveTexture(GL_TEXTURE0 + stage);
glBindSampler(stage, samplers[stage]);
@@ -481,7 +475,6 @@ static GLenum blend_factor(uint32_t factor)
void gl_renderer_set_fog(int enabled, uint32_t color)
{
- glUseProgram(program);
glUniform1i(fog_enabled, enabled);
glUniform3f(fog_color, ((color >> 16) & 255) / 255.0f,
((color >> 8) & 255) / 255.0f, (color & 255) / 255.0f);
@@ -497,7 +490,6 @@ void gl_renderer_set_blend(int enabled, uint32_t source, uint32_t destination)
void gl_renderer_set_alpha_test(int enabled, uint32_t function, uint32_t reference)
{
- glUseProgram(program);
glUniform1i(alpha_function, enabled ? function : 8);
glUniform1f(alpha_reference, reference);
}