Skip to content

Commit

Permalink
Check return values on glGetUniformBlockIndex and glGetUniformLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
katajakasa committed May 2, 2023
1 parent 1e3c784 commit 7ba8baf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/video/opengl/shaders.c
Expand Up @@ -124,12 +124,20 @@ bool create_program(GLuint *program_id, const char *vertex_shader, const char *f
}

void bind_uniform_4fv(GLuint program_id, const char *name, GLfloat *data) {
GLuint ref = glGetUniformLocation(program_id, name);
GLint ref = glGetUniformLocation(program_id, name);
if(ref == -1) {
PERROR("Unable to find uniform; glGetUniformLocation() returned -1");
return;
}
glUniformMatrix4fv(ref, 1, GL_FALSE, data);
}

void bind_uniform_block(GLuint program_id, const char *name, GLuint binding) {
GLuint ref = glGetUniformBlockIndex(program_id, name);
if(ref == GL_INVALID_INDEX) {
PERROR("Unable to find ubo; glGetUniformBlockIndex() returned GL_INVALID_INDEX");
return;
}
glUniformBlockBinding(program_id, 0, ref);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, binding);
}
Expand Down

0 comments on commit 7ba8baf

Please sign in to comment.