aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 5f8a5b1d939fc2e34d74aecad9ad8962b4abe259
parent 8805d275cd05c854bdbf128dbe110a97757b7406
Author: anon <anon@example.com>
Date:   Sat, 17 Oct 2026 03:22:36 +0000

Avoid synchronous WebGL error checks on every frame

Diffstat:
Msrc/runtime/gl_renderer.c | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/runtime/gl_renderer.c b/src/runtime/gl_renderer.c @@ -2,6 +2,8 @@ #include "gl_renderer.h" #ifdef __EMSCRIPTEN__ #include <GLES3/gl3.h> +#include <emscripten.h> +static double next_presentation_check; #define SHADER_VERSION "#version 300 es\nprecision highp float;\nprecision highp int;\n" #else #include <SDL2/SDL_opengl.h> @@ -64,6 +66,9 @@ static void check_graphics(const char *operation) int gl_renderer_initialize(void) { if (program) return 1; +#ifdef __EMSCRIPTEN__ + next_presentation_check = 0; +#endif const char *sources[] = { SHADER_VERSION "layout(location=0) in vec4 position;\n" @@ -408,7 +413,17 @@ void gl_target_present(struct gl_target *target, const int32_t rectangle[4], int glBlitFramebuffer(rectangle[0], rectangle[1], rectangle[2], rectangle[3], 0, height, width, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL_FRAMEBUFFER, 0); +#ifdef __EMSCRIPTEN__ + /* WebGL error queries synchronize with the GPU. Check presentation once a + * second; allocation and readback errors are still checked immediately. */ + double now = emscripten_get_now(); + if (now >= next_presentation_check) { + check_graphics("frame rendering and presentation"); + next_presentation_check = now + 1000; + } +#else check_graphics("frame rendering and presentation"); +#endif } void gl_renderer_set_texture(unsigned stage, const struct gl_texture_state *state)