src/glcontext.c

changeset 139
5d655459db85
parent 137
f8e6e0ae61a8
--- a/src/glcontext.c	Sun Jun 08 14:57:54 2025 +0200
+++ b/src/glcontext.c	Sun Jun 08 14:58:19 2025 +0200
@@ -47,20 +47,6 @@
     }
 }
 
-static int asc_shader_initialize_predefined(AscGLContext *ctx) {
-    // TODO: check if we can replace that by lazy loading shaders just like fonts
-    int ret = 0;
-    ret |= asc_shader_sprite_init(&ctx->shader.sprite_uv, false);
-    ret |= asc_shader_sprite_init(&ctx->shader.sprite_rect, true);
-    ret |= asc_error_catch_all_gl();
-    return ret;
-}
-
-static void asc_shader_destroy_predefined(AscGLContext *ctx) {
-    asc_shader_program_destroy(&ctx->shader.sprite_uv.program);
-    asc_shader_program_destroy(&ctx->shader.sprite_rect.program);
-}
-
 struct asc_gl_context_cleanup_data {
     int type;
     union {
@@ -109,15 +95,14 @@
         glEnable(GL_DEBUG_OUTPUT);
         glDebugMessageCallback(asc_gl_debug_callback, NULL);
 
-        if (asc_shader_initialize_predefined(ctx)) {
-            asc_error("Initializing predefined shaders failed");
-            SDL_GL_DeleteContext(ctx->glctx);
-            return false;
-        }
-
+        // Create the cleanup functions array
         ctx->cleanup_funcs = cxArrayListCreateSimple(sizeof(struct asc_gl_context_cleanup_data), 8);
         cxDefineDestructor(ctx->cleanup_funcs, asc_gl_context_cleanup);
 
+        // Create the shaders array
+        ctx->shaders = cxArrayListCreateSimple(CX_STORE_POINTERS, 32);
+        cxDefineDestructor(ctx->shaders, asc_shader_free);
+
         return true;
     } else {
         asc_error("glewInit failed: %s", glewGetErrorString(err));
@@ -130,8 +115,8 @@
     if (ctx->glctx == NULL) return;
     SDL_GL_MakeCurrent(ctx->window, ctx->glctx);
 
+    cxListFree(ctx->shaders);
     cxListFree(ctx->cleanup_funcs);
-    asc_shader_destroy_predefined(ctx);
 
     // destroy the GL context and the window
     SDL_GL_DeleteContext(ctx->glctx);

mercurial