commit 11376489b5e0103d4d5e3f67a9874ddf0601094a
parent cf736bfde29ff2e71fe35a208bb680f8b1e387bf
Author: anon <anon@example.com>
Date: Sat, 17 Oct 2026 20:51:29 +0000
Avoid synchronous WebGL queries when revealing scenery
Diffstat:
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/src/runtime/gl_renderer.c b/src/runtime/gl_renderer.c
@@ -4,7 +4,6 @@
#include <GLES3/gl3.h>
#include <emscripten.h>
#include <stdatomic.h>
-static double next_presentation_check;
static atomic_int capture_remaining;
EMSCRIPTEN_KEEPALIVE void browser_capture_frames(int count)
@@ -76,9 +75,6 @@ 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"
@@ -315,12 +311,16 @@ static void make_renderable(struct gl_target *target)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, target->color, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
target->depth ? target->depth->buffer : 0);
+ /* RGBA8 attachments have a fixed layout. Browser completeness queries would
+ * synchronize each newly visible mip; explicit readback checks GL errors. */
+#ifndef __EMSCRIPTEN__
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (status != GL_FRAMEBUFFER_COMPLETE) {
fprintf(stderr, "Native framebuffer creation failed: %04x\n", status);
abort();
}
+#endif
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
struct gl_target *gl_target_create(unsigned width, unsigned height, int with_depth)
@@ -473,8 +473,6 @@ void gl_target_present(struct gl_target *target, const int32_t rectangle[4], int
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. */
/* Capture each actual presentation on the GL worker, before the browser
* can discard its default framebuffer. Readback is opt-in and synchronous. */
int remaining = atomic_load(&capture_remaining);
@@ -490,11 +488,6 @@ void gl_target_present(struct gl_target *target, const int32_t rectangle[4], int
/* A stop request from the UI must not be overwritten by this frame. */
atomic_compare_exchange_strong(&capture_remaining, &remaining, remaining - 1);
}
- 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