simplify code

This commit is contained in:
2025-09-18 23:40:25 +02:00
parent 836feedf16
commit 61e70f4913
+19 -7
View File
@@ -152,7 +152,6 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
} else {
glAttachShader(program->programs[i], program->fragment_shaders[i]);
}
glLinkProgram(program->programs[i]);
// create uniforms pointers
@@ -276,10 +275,8 @@ void shaders_update(ShaderProgram program, File *fragment_shaders,
}
}
void shaders_apply(ShaderProgram program, Context context) {
unsigned int i, j;
GLuint subroutines[3];
vec2 resolution;
static void update_viewport(ShaderProgram program, Context context) {
unsigned int i;
// viewport changed
if (context.width != program.last_width ||
@@ -294,15 +291,21 @@ void shaders_apply(ShaderProgram program, Context context) {
GL_RGB, GL_UNSIGNED_BYTE, 0);
}
}
}
static void use_program(ShaderProgram program, int i, bool output,
Context context) {
unsigned int j;
GLuint subroutines[3];
vec2 resolution;
resolution[0] = (float)context.width;
resolution[1] = (float)context.height;
for (i = 0; i < program.frag_count + 1; i++) {
// use specific shader program
glUseProgram(program.programs[i]);
if (i == program.frag_count) {
if (output) {
// use default framebuffer (output)
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -337,4 +340,13 @@ void shaders_apply(ShaderProgram program, Context context) {
// draw output
glDrawArrays(GL_TRIANGLES, 0, 6);
}
void shaders_apply(ShaderProgram program, Context context) {
unsigned int i;
update_viewport(program, context);
for (i = 0; i < program.frag_count + 1; i++) {
use_program(program, i, i == program.frag_count, context);
}
}