src/shader.c

changeset 239
3b78ad115ccd
parent 225
c42c7d1a3c34
--- a/src/shader.c	Fri Aug 01 18:19:33 2025 +0200
+++ b/src/shader.c	Sat Aug 02 13:07:28 2025 +0200
@@ -237,40 +237,24 @@
     return asc_error_catch_gl("Activating shader");
 }
 
-const AscShaderProgram *asc_shader_register(unsigned int id, asc_shader_create_func create_func, int create_flags) {
-    AscGLContext *glctx = asc_active_glctx;
-#ifndef NDEBUG
-    {
-        const AscShaderProgram *prog = asc_shader_lookup(id);
-        if (prog != NULL) {
-            asc_error("Shader program %u already exists. This is a bug!", id);
-            // still return it, so that the caller does not die immediately
-            return prog;
+const AscShaderProgram *asc_shader_lookup(unsigned int id, asc_shader_create_func create_func, int create_flags) {
+    AscShaderProgram *prog = NULL;
+    CxIterator iter = cxListIterator(asc_active_glctx->shaders);
+    cx_foreach(AscShaderProgram *, p, iter) {
+        if (p->id == id) {
+            prog = p;
+            break;
         }
     }
-#endif
-    AscShaderProgram *prog = create_func(create_flags);
     if (prog == NULL) {
-        // create an empty program to prevent future loading attempts
-        prog = cxZallocDefault(sizeof(AscShaderProgram));
-    }
-    prog->id = id;
-    cxListAdd(glctx->shaders, prog);
-    return prog;
-}
-
-const AscShaderProgram *asc_shader_lookup(unsigned int id) {
-    CxIterator iter = cxListIterator(asc_active_glctx->shaders);
-    cx_foreach(const AscShaderProgram *, prog, iter) {
-        if (prog->id == id) return prog;
-    }
-    return NULL;
-}
-
-const AscShaderProgram *asc_shader_lookup_or_create(unsigned int id, asc_shader_create_func create_func, int create_flags) {
-    const AscShaderProgram *prog = asc_shader_lookup(id);
-    if (prog == NULL) {
-        return asc_shader_register(id, create_func, create_flags);
+        AscGLContext *glctx = asc_active_glctx;
+        prog = create_func(create_flags);
+        if (prog == NULL) {
+            // create an empty program to prevent future loading attempts
+            prog = cxZallocDefault(sizeof(AscShaderProgram));
+        }
+        prog->id = id;
+        cxListAdd(glctx->shaders, prog);
     }
     return prog;
 }

mercurial