define macro for predefined shader

Thu, 15 Aug 2024 17:33:42 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Aug 2024 17:33:42 +0200
changeset 72
84472fb3adbd
parent 71
baa73a0be3ce
child 73
cfa1d05754ac

define macro for predefined shader

src/ascension/glcontext.h file | annotate | diff | comparison | revisions
src/ascension/shader.h file | annotate | diff | comparison | revisions
src/glcontext.c file | annotate | diff | comparison | revisions
src/scene.c file | annotate | diff | comparison | revisions
--- a/src/ascension/glcontext.h	Wed Aug 14 21:09:52 2024 +0200
+++ b/src/ascension/glcontext.h	Thu Aug 15 17:33:42 2024 +0200
@@ -49,6 +49,8 @@
     } shader;
 } AscGLContext;
 
+#define ASC_SHADER_SPRITE (&asc_active_window->glctx.shader.sprite)
+
 __attribute__((__nonnull__, __warn_unused_result__))
 bool asc_gl_context_initialize(
         AscGLContext *ctx,
--- a/src/ascension/shader.h	Wed Aug 14 21:09:52 2024 +0200
+++ b/src/ascension/shader.h	Thu Aug 15 17:33:42 2024 +0200
@@ -40,7 +40,7 @@
 } AscShaderProgram;
 
 typedef struct AscShaderSprite {
-    AscShaderProgram base;
+    AscShaderProgram program;
     int depth;
     int tex;
 } AscShaderSprite;
--- a/src/glcontext.c	Wed Aug 14 21:09:52 2024 +0200
+++ b/src/glcontext.c	Thu Aug 15 17:33:42 2024 +0200
@@ -50,13 +50,16 @@
 
 static void asc_shader_initialize_predefined(AscGLContext *ctx) {
     AscShaderSprite *sprite = &ctx->shader.sprite;
-    sprite->base = asc_shader_easy_compile_and_link("shader/sprite_vtx.glsl", "shader/sprite_frag.glsl");
-    sprite->depth = glGetUniformLocation(sprite->base.id, "depth");
-    sprite->tex = glGetUniformLocation(sprite->base.id, "texture");
+    sprite->program = asc_shader_easy_compile_and_link(
+            "shader/sprite_vtx.glsl",
+            "shader/sprite_frag.glsl"
+    );
+    sprite->depth = glGetUniformLocation(sprite->program.id, "depth");
+    sprite->tex = glGetUniformLocation(sprite->program.id, "texture");
 }
 
 static void asc_shader_destroy_predefined(AscGLContext *ctx) {
-    asc_shader_program_destroy(ctx->shader.sprite.base);
+    asc_shader_program_destroy(ctx->shader.sprite.program);
 }
 
 bool asc_gl_context_initialize(
--- a/src/scene.c	Wed Aug 14 21:09:52 2024 +0200
+++ b/src/scene.c	Thu Aug 15 17:33:42 2024 +0200
@@ -60,10 +60,10 @@
 
 static void asc_sprite_draw(AscSprite const *node) {
     // Obtain shader
-    AscShaderSprite *shader = &asc_active_window->glctx.shader.sprite;
+    AscShaderSprite *shader = ASC_SHADER_SPRITE;
 
     // Upload model matrix
-    glUniformMatrix4fv(shader->base.model, 1,
+    glUniformMatrix4fv(shader->program.model, 1,
                        GL_FALSE, node->data.world_transform);
 
     // Bind texture
@@ -158,7 +158,7 @@
     // Sprites
     // -------
     // TODO: implement view matrix for 2D worlds
-    shader = &asc_active_window->glctx.shader.sprite.base;
+    shader = &asc_active_window->glctx.shader.sprite.program;
     glUseProgram(shader->id);
     glUniformMatrix4fv(shader->projection, 1,
                        GL_FALSE, camera->projection);

mercurial