improve OpenGL error handling

Thu, 17 Jul 2025 19:44:22 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 17 Jul 2025 19:44:22 +0200
changeset 208
658bccb1bf73
parent 207
4d184a8706b1
child 209
90fc22696e94

improve OpenGL error handling

src/error.c file | annotate | diff | comparison | revisions
src/glcontext.c file | annotate | diff | comparison | revisions
src/mesh.c file | annotate | diff | comparison | revisions
src/text.c file | annotate | diff | comparison | revisions
--- a/src/error.c	Wed Jul 16 23:27:34 2025 +0200
+++ b/src/error.c	Thu Jul 17 19:44:22 2025 +0200
@@ -107,7 +107,7 @@
         default:
             glerr = "unknown GL error";
     }
-    asc_error("%s\nGL Error: %s", message, glerr);
+    asc_error("%s - GL Error: %s", message, glerr);
 }
 
 int asc_error_catch_all_gl(void) {
--- a/src/glcontext.c	Wed Jul 16 23:27:34 2025 +0200
+++ b/src/glcontext.c	Thu Jul 17 19:44:22 2025 +0200
@@ -41,7 +41,7 @@
         const void *userParam
 ) {
     if (type == GL_DEBUG_TYPE_ERROR) {
-        asc_error("OpenGL source = %d, id = %u, type = %d, severity= %d, message = %.*s",
+        asc_wprintf("OpenGL source = %d, id = %u, type = %d, severity= %d, message = %.*s",
             source, id, type, severity, length, message);
     } else {
         asc_dprintf("OpenGL source = %d, id = %u, type = %d, severity= %d, message = %.*s",
--- a/src/mesh.c	Wed Jul 16 23:27:34 2025 +0200
+++ b/src/mesh.c	Thu Jul 17 19:44:22 2025 +0200
@@ -66,6 +66,7 @@
 void asc_mesh_draw_triangle_strip(const AscMesh *mesh) {
     glBindVertexArray(mesh->vao);
     glDrawArrays(GL_TRIANGLE_STRIP, 0, mesh->vtx_count);
+    asc_error_catch_all_gl();
 #ifndef NDEBUG
     // only unbind in debug mode to detect accidental re-use of the wrong VAO
     glBindVertexArray(0);
@@ -128,4 +129,6 @@
     glEnableVertexAttribArray(0);
     glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(asc_vertex2d), (void*)offsetof(asc_vertex2d, uv));
     glEnableVertexAttribArray(1);
+
+    asc_error_catch_all_gl();
 }
--- a/src/text.c	Wed Jul 16 23:27:34 2025 +0200
+++ b/src/text.c	Thu Jul 17 19:44:22 2025 +0200
@@ -97,9 +97,9 @@
     asc_texture_from_surface(text->texture, surface);
 
     // If dimensions changed, update the mesh
-    if (text->dimension.x != (unsigned)surface->w || text->dimension.y != (unsigned)surface->h) {
-        text->dimension.x = surface->w;
-        text->dimension.y = surface->h;
+    if (text->dimension.width != (unsigned)surface->w || text->dimension.height != (unsigned)surface->h) {
+        text->dimension.width = surface->w;
+        text->dimension.height = surface->h;
         const asc_vec2f uv_scale = asc_texture_calculate_uv_scale(text->texture, text->dimension, ASC_VEC2F_1);
         asc_mesh_plane_2d(&text->mesh,
             .size = ASC_VEC2F(surface->w, surface->h),
@@ -117,6 +117,9 @@
 static void asc_text_draw(const AscCamera *camera, const AscSceneNode *node) {
     asc_cptr_cast(AscText, text, node);
 
+    // early exit when the text has no width
+    if (text->dimension.width == 0) return;
+
     // Activate shader
     // TODO: scene should know which shader we are going to activate s.t. it can pre-sort nodes
     const AscShaderProgram *shader = asc_shader_lookup_or_create(
@@ -174,7 +177,7 @@
     text->texture = cxMallocDefault(sizeof(AscTexture));
     asc_texture_init_rectangle(text->texture, 1);
     // TODO: check why we can't just wait for the first normal update to happen
-    asc_text_update(node);
+    //asc_text_update(node);
 
     return node;
 }

mercurial