feat: FRAG_FILE_PREFIX

This commit is contained in:
2025-11-07 19:30:48 +01:00
parent 63284d34ef
commit 4927d5cf10
5 changed files with 26 additions and 21 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ make -f Makefile.dev release-arch
- [x] Share openGL state between monitor and screen - [x] Share openGL state between monitor and screen
- [ ] Other - [ ] Other
- [x] `forge_project.cfg` - [x] `forge_project.cfg`
- [ ] Define frag prefix in config - [x] Define frag prefix in config
- [ ] Use custom `#include xxx.glsl` preprocessor - [ ] Use custom `#include xxx.glsl` preprocessor
- [ ] Update readme with usage documentation - [ ] Update readme with usage documentation
- [x] Documentation in default config file - [x] Documentation in default config file
+2
View File
@@ -103,6 +103,8 @@ IN_2_OUT=2
# Fragment shaders will be read from the CLI directory as "fragX.glsl" # Fragment shaders will be read from the CLI directory as "fragX.glsl"
# Special shader "frag0.glsl" will be prepend to each one # Special shader "frag0.glsl" will be prepend to each one
FRAG_FILE_PREFIX=frag
# Total number of fragment shaders (excluding frag0.glsl) # Total number of fragment shaders (excluding frag0.glsl)
FRAG_COUNT=10 FRAG_COUNT=10
+17 -14
View File
@@ -35,7 +35,7 @@ static bool trace_midi;
static void compute_fps(bool trace_fps) { static void compute_fps(bool trace_fps) {
double fps; double fps;
char title[100]; char title[STR_LEN];
if (timer_inc(&timer)) { if (timer_inc(&timer)) {
fps = timer_reset(&timer); fps = timer_reset(&timer);
@@ -102,11 +102,12 @@ static void hot_reload() {
} }
} }
File read_fragment_shader_file(char *frag_path, unsigned int i) { File read_fragment_shader_file(char *frag_path, char *frag_prefix,
unsigned int i) {
File fragment_shader; File fragment_shader;
char file_path[STR_LEN]; char file_path[STR_LEN];
snprintf(file_path, STR_LEN, "%s/frag%d.glsl", frag_path, i); snprintf(file_path, STR_LEN, "%s/%s%d.glsl", frag_path, frag_prefix, i);
fragment_shader = file_read(file_path); fragment_shader = file_read(file_path);
if (fragment_shader.error) { if (fragment_shader.error) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@@ -115,16 +116,18 @@ File read_fragment_shader_file(char *frag_path, unsigned int i) {
return fragment_shader; return fragment_shader;
} }
static void init_files(char *frag_path, unsigned int frag_count) { static void init_files(char *frag_path, char *frag_prefix,
unsigned int frag_count) {
unsigned int i; unsigned int i;
fragment_shaders.length = frag_count; fragment_shaders.length = frag_count;
for (i = 0; i < frag_count + 1; i++) { for (i = 0; i < frag_count + 1; i++) {
if (i == 0) { if (i == 0) {
common_shader_code = read_fragment_shader_file(frag_path, i); common_shader_code = read_fragment_shader_file(frag_path, frag_prefix, i);
} else { } else {
fragment_shaders.values[i - 1] = read_fragment_shader_file(frag_path, i); fragment_shaders.values[i - 1] =
read_fragment_shader_file(frag_path, frag_prefix, i);
file_prepend(&fragment_shaders.values[i - 1], common_shader_code); file_prepend(&fragment_shaders.values[i - 1], common_shader_code);
} }
@@ -233,24 +236,24 @@ static void loop(bool hr, bool trace_fps) {
void forge_run(Parameters params) { void forge_run(Parameters params) {
unsigned int frag_count, in_count; unsigned int frag_count, in_count;
char config_path[STR_LEN]; char config_path[STR_LEN * 2 + 1];
char *frag_prefix;
context = shared_init_context("/" PACKAGE "_context"); context = shared_init_context("/" PACKAGE "_context");
context->stop = false; context->stop = false;
strncpy(config_path, params.project_path, STR_LEN); sprintf(config_path, "%s/%s", params.project_path, params.config_file);
strcat(config_path, "/");
strcat(config_path, params.config_file);
config = config_file_read(config_path); config = config_file_read(config_path);
frag_count = config_file_get_int(config, "FRAG_COUNT", 1);
in_count = config_file_get_int(config, "IN_COUNT", 0);
state_config = state_parse_config(config); state_config = state_parse_config(config);
init_files(params.project_path, frag_count); frag_count = config_file_get_int(config, "FRAG_COUNT", 1);
in_count = config_file_get_int(config, "IN_COUNT", 0);
frag_prefix = config_file_get_str(config, "FRAG_FILE_PREFIX", "frag");
init_files(params.project_path, frag_prefix, frag_count);
init_inputs(params.video_in, params.video_size); init_inputs(params.video_in, params.video_size);
+4 -4
View File
@@ -116,7 +116,7 @@ static void init_input(ShaderProgram *program, ConfigFile config,
VideoCaptureArray inputs) { VideoCaptureArray inputs) {
unsigned int i; unsigned int i;
unsigned tex_i; unsigned tex_i;
char name[256]; char name[STR_LEN];
for (i = 0; i < program->in_count; i++) { for (i = 0; i < program->in_count; i++) {
if (i < inputs.length && !inputs.values[i].error) { if (i < inputs.length && !inputs.values[i].error) {
@@ -132,7 +132,7 @@ static void init_input(ShaderProgram *program, ConfigFile config,
static void init_framebuffers(ShaderProgram *program, ConfigFile config) { static void init_framebuffers(ShaderProgram *program, ConfigFile config) {
unsigned int i; unsigned int i;
unsigned tex_i; unsigned tex_i;
char name[256]; char name[STR_LEN];
glGenFramebuffers(program->frag_count, program->frame_buffers); glGenFramebuffers(program->frag_count, program->frame_buffers);
@@ -190,7 +190,7 @@ static void bind_vertices(ShaderProgram *program, unsigned int index) {
static bool compile_shader(GLuint shader_id, char *name, char *source_code) { static bool compile_shader(GLuint shader_id, char *name, char *source_code) {
GLint status_params; GLint status_params;
char log[1024]; char log[STR_LEN];
log_info("Compiling '%s'...", name); log_info("Compiling '%s'...", name);
@@ -237,7 +237,7 @@ static void init_shaders(ShaderProgram *program, FileArray fragment_shaders) {
static void init_single_program(ShaderProgram *program, unsigned int i, static void init_single_program(ShaderProgram *program, unsigned int i,
ConfigFile config, StateConfig state_config) { ConfigFile config, StateConfig state_config) {
unsigned int j, k, index1, index2; unsigned int j, k, index1, index2;
char name[256]; char name[STR_LEN];
char *prefix; char *prefix;
program->programs[i] = glCreateProgram(); program->programs[i] = glCreateProgram();
+2 -2
View File
@@ -14,7 +14,7 @@
StateConfig state_parse_config(ConfigFile config) { StateConfig state_parse_config(ConfigFile config) {
unsigned int i, j, offset, count; unsigned int i, j, offset, count;
StateConfig state_config; StateConfig state_config;
char name[256]; char name[STR_LEN];
state_config.select_page_codes.length = state_config.select_page_codes.length =
config_file_get_int(config, "SELECT_PAGE_COUNT", 0); config_file_get_int(config, "SELECT_PAGE_COUNT", 0);
@@ -326,7 +326,7 @@ bool state_background_write(SharedContext *context, StateConfig state_config,
static void state_load(SharedContext *context, StateConfig state_config, static void state_load(SharedContext *context, StateConfig state_config,
char *state_file) { char *state_file) {
ConfigFile saved_state; ConfigFile saved_state;
char key[100]; char key[STR_LEN];
unsigned int i; unsigned int i;
saved_state = config_file_read(state_file); saved_state = config_file_read(state_file);