src/glcontext.c

changeset 80
9f7bfc0a1dc3
parent 78
9bc544f4ce8f
child 81
84a546e282b7
--- a/src/glcontext.c	Thu Mar 20 20:36:09 2025 +0100
+++ b/src/glcontext.c	Fri Apr 18 19:34:31 2025 +0200
@@ -48,25 +48,14 @@
     cx_strfree(&buf);
 }
 
-static void asc_shader_initialize_predefined(AscGLContext *ctx) {
-    // TODO: deal with different working dirs
-    AscShaderSprite *sprite = &ctx->shader.sprite;
-    AscShaderCodes codes;
-    if (asc_shader_load_code_files((AscShaderCodeFiles){
-        .vtx = "./shader/sprite_vtx.glsl",
-        .frag = "./shader/sprite_frag.glsl"
-    }, &codes)) {
-        asc_error("Loading sprite shader failed.");
-        return;
-    }
-    sprite->program = asc_shader_program_create(codes);
-    sprite->depth = glGetUniformLocation(sprite->program.id, "depth");
-    sprite->tex = glGetUniformLocation(sprite->program.id, "texture");
-    asc_shader_free_codes(codes);
+static int asc_shader_initialize_predefined(AscGLContext *ctx) {
+    int ret = 0;
+    ret |= asc_shader_sprite_init(&ctx->shader.sprite);
+    return ret;
 }
 
 static void asc_shader_destroy_predefined(AscGLContext *ctx) {
-    asc_shader_program_destroy(ctx->shader.sprite.program);
+    asc_shader_program_destroy(&ctx->shader.sprite.program);
 }
 
 bool asc_gl_context_initialize(
@@ -98,7 +87,10 @@
             return false;
         }
 
-        asc_shader_initialize_predefined(ctx);
+        if (asc_shader_initialize_predefined(ctx)) {
+            SDL_GL_DeleteContext(ctx->glctx);
+            return false;
+        }
 
         return true;
     } else {

mercurial