debug shader

This commit is contained in:
2025-09-20 20:02:29 +02:00
parent ce1d0dba60
commit 3d5a6fc6ac
7 changed files with 135 additions and 28 deletions
+23 -1
View File
@@ -141,6 +141,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
char *tex_prefix;
char *sub_prefix;
char *seed_prefix;
char *state_prefix;
program->programs[i] = glCreateProgram();
@@ -173,6 +174,18 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
glGetUniformLocation(program->programs[i], name);
}
state_prefix =
config_file_get_str(shader_config, "UNIFORM_STATE_PREFIX", "state");
for (j = 0; j < program->frag_count; j++) {
for (k = 0; k < program->sub_type_count; k++) {
sprintf(name, "%s%d_%d", state_prefix, j + 1, k + 1);
program
->istate_locations[i * program->frag_count * program->sub_type_count +
j * program->sub_type_count + k] =
glGetUniformLocation(program->programs[i], name);
}
}
for (j = 0; j < program->sub_type_count; j++) {
sprintf(name, "SUB_%d_PREFIX", j + 1);
sub_prefix = config_file_get_str(shader_config, name, 0);
@@ -217,6 +230,8 @@ static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
program->idemo_locations = malloc(program->frag_count * sizeof(GLuint));
program->iseed_locations =
malloc(program->frag_count * program->frag_count * sizeof(GLuint));
program->istate_locations = malloc(program->frag_count * program->frag_count *
program->sub_type_count * sizeof(GLuint));
program->vpos_locations = malloc(program->frag_count * sizeof(GLuint));
program->textures_locations =
malloc(program->frag_count * program->tex_count * sizeof(GLuint));
@@ -335,12 +350,19 @@ static void use_program(ShaderProgram program, int i, bool output,
(const GLint)context.seeds[j]);
}
// set subroutines for fragment
// set subroutines for fragment and update state uniforms
for (j = 0; j < program.sub_type_count; j++) {
k = context.sub_state[i * program.sub_type_count + j];
subroutines[j] = program.sub_locations[i * program.sub_type_count *
program.sub_variant_count +
j * program.sub_variant_count + k];
for (k = 0; k < program.frag_count; k++) {
glUniform1i(
program.istate_locations[i * program.frag_count *
program.sub_type_count +
k * program.sub_type_count + j],
(const GLint)context.sub_state[k * program.sub_type_count + j]);
}
}
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, program.sub_type_count,
+1
View File
@@ -60,6 +60,7 @@ typedef struct ShaderProgram {
GLuint *ires_locations;
GLuint *idemo_locations;
GLuint *iseed_locations;
GLuint *istate_locations;
GLuint *vpos_locations;