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 { } else {
glAttachShader(program->programs[i], program->fragment_shaders[i]); glAttachShader(program->programs[i], program->fragment_shaders[i]);
} }
glLinkProgram(program->programs[i]); glLinkProgram(program->programs[i]);
// create uniforms pointers // create uniforms pointers
@@ -276,10 +275,8 @@ void shaders_update(ShaderProgram program, File *fragment_shaders,
} }
} }
void shaders_apply(ShaderProgram program, Context context) { static void update_viewport(ShaderProgram program, Context context) {
unsigned int i, j; unsigned int i;
GLuint subroutines[3];
vec2 resolution;
// viewport changed // viewport changed
if (context.width != program.last_width || if (context.width != program.last_width ||
@@ -294,15 +291,21 @@ void shaders_apply(ShaderProgram program, Context context) {
GL_RGB, GL_UNSIGNED_BYTE, 0); 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[0] = (float)context.width;
resolution[1] = (float)context.height; resolution[1] = (float)context.height;
for (i = 0; i < program.frag_count + 1; i++) {
// use specific shader program // use specific shader program
glUseProgram(program.programs[i]); glUseProgram(program.programs[i]);
if (i == program.frag_count) { if (output) {
// use default framebuffer (output) // use default framebuffer (output)
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -336,5 +339,14 @@ void shaders_apply(ShaderProgram program, Context context) {
// draw output // draw output
glDrawArrays(GL_TRIANGLES, 0, 6); 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);
} }
} }