src/shader.c

changeset 169
6e6717d9c776
parent 168
f70569c49c24
--- a/src/shader.c	Wed Jun 25 21:58:44 2025 +0200
+++ b/src/shader.c	Thu Jun 26 21:43:22 2025 +0200
@@ -158,7 +158,7 @@
     return program == NULL || program->gl_id == 0;
 }
 
-void *asc_shader_create(AscShaderCodes codes, size_t mem_size) {
+AscShaderProgram *asc_shader_create(AscShaderCodes codes, size_t mem_size) {
     AscShaderProgram *prog = cxZallocDefault(mem_size);
     unsigned shader[2];
     unsigned n = 0;
@@ -173,17 +173,19 @@
     return prog;
 }
 
-void asc_shader_use(const AscShaderProgram *shader, const AscCamera *camera) {
+int asc_shader_use(const AscShaderProgram *shader, const AscCamera *camera) {
     if (shader == NULL) {
         asc_active_glctx->active_program = 0;
         glUseProgram(0);
-        return;
+        return 0;
     }
-    if (asc_active_glctx->active_program == shader->gl_id) return;
+    if (asc_active_glctx->active_program == shader->gl_id) return 0;
+    if (asc_shader_invalid(shader)) return -1;
     asc_active_glctx->active_program = shader->gl_id;
     glUseProgram(shader->gl_id);
     glUniformMatrix4fv(shader->projection, 1, GL_FALSE, camera->projection);
     glUniformMatrix4fv(shader->view, 1, GL_FALSE, camera->view);
+    return asc_error_catch_all_gl();
 }
 
 static int asc_shader_load_code_file(const char *filename, char **code) {
@@ -223,7 +225,7 @@
     cxFreeDefault(codes.frag);
 }
 
-const void *asc_shader_register(unsigned int id, asc_shader_create_func create_func, int create_flags) {
+const AscShaderProgram *asc_shader_register(unsigned int id, asc_shader_create_func create_func, int create_flags) {
     AscGLContext *glctx = asc_active_glctx;
 #ifndef NDEBUG
     {
@@ -242,7 +244,7 @@
     return prog;
 }
 
-const void *asc_shader_lookup(unsigned int id) {
+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;
@@ -250,7 +252,7 @@
     return NULL;
 }
 
-const void *asc_shader_lookup_or_create(unsigned int id, asc_shader_create_func create_func, int create_flags) {
+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);

mercurial