223 |
223 |
224 int asc_shader_use(const AscShaderProgram *shader, const AscCamera *camera) { |
224 int asc_shader_use(const AscShaderProgram *shader, const AscCamera *camera) { |
225 if (asc_shader_invalid(shader)) { |
225 if (asc_shader_invalid(shader)) { |
226 asc_active_glctx->active_program = 0; |
226 asc_active_glctx->active_program = 0; |
227 glUseProgram(0); |
227 glUseProgram(0); |
|
228 return -1; |
|
229 } |
|
230 if (asc_active_glctx->active_program == shader->gl_id) { |
|
231 // already using this shader - continue |
228 return 0; |
232 return 0; |
229 } |
233 } |
230 if (asc_active_glctx->active_program == shader->gl_id) return 0; |
|
231 if (asc_shader_invalid(shader)) return -1; |
|
232 asc_active_glctx->active_program = shader->gl_id; |
234 asc_active_glctx->active_program = shader->gl_id; |
233 glUseProgram(shader->gl_id); |
235 glUseProgram(shader->gl_id); |
234 glUniformMatrix4fv(shader->projection, 1, GL_FALSE, camera->projection); |
236 glUniformMatrix4fv(shader->projection, 1, GL_FALSE, camera->projection); |
235 glUniformMatrix4fv(shader->view, 1, GL_FALSE, camera->view); |
237 glUniformMatrix4fv(shader->view, 1, GL_FALSE, camera->view); |
236 return asc_error_catch_gl("Activating shader"); |
238 return asc_error_catch_gl("Activating shader"); |