diff --git a/Makefile.dev b/Makefile.dev index 59d5fe4..8c4b953 100644 --- a/Makefile.dev +++ b/Makefile.dev @@ -1,6 +1,6 @@ TARGET ?= forge INSTALL_DIR ?= $(HOME)/.local/bin -TEST_ARGS ?= --hot-reload --frag=./shaders --frag-config=./config/shaders.cfg --demo +TEST_ARGS ?= --hot-reload --frag=./shaders --frag-config=./config/shaders.cfg --demo -is=480 SHELL := /bin/bash .PHONY: build diff --git a/README.md b/README.md index ea4262f..d2da8b1 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,8 @@ make -f Makefile.dev release-arch - [x] demo mode - [x] random seed injected into shaders - [ ] internal texture size for speed + - [ ] pass state as uniform + - [ ] debug shader (and in monitor) - [ ] Clean code and fix things - [ ] Midi - [ ] Read Midi events diff --git a/src/args.c b/src/args.c index 29b9499..207bada 100644 --- a/src/args.c +++ b/src/args.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -24,14 +25,15 @@ static void print_help(int status_code) { "\n\n" "Fusion Of Real-time Generative Effects.\n\n" "options:\n" - " -h, --help show this help message and exit\n" - " -v, --version print version\n" - " -hr, --hot-reload hot reload of shaders scripts\n" - " -s, --screen output screen number (default: primary)\n" - " -f, --frag fragment shaders directory (default: TODO)\n" - " -fc, --frag-config fragment shaders config file (default: TODO)\n" - " -t, --tempo base tempo (default: 60)\n" - " --demo demonstration mode\n"); + " -h, --help show this help message and exit\n" + " -v, --version print version\n" + " -hr, --hot-reload hot reload of shaders scripts\n" + " -s, --screen output screen number (default: primary)\n" + " -f, --frag fragment shaders directory (default: TODO)\n" + " -fc, --frag-config fragment shaders config file (default: TODO)\n" + " -is, --internal-size internal texture height (default: 720)\n" + " -t, --tempo base tempo (default: 60)\n" + " --demo demonstration mode\n"); exit(status_code); } @@ -52,26 +54,15 @@ static char *split_arg_value(char *arg) { return strtok(NULL, "="); } -static unsigned char parse_uchar(char *arg, char *value) { +static unsigned int parse_uint(char *arg, char *value) { if (!string_is_number(value)) { invalid_value(arg, value); } unsigned long long tmp_value = (unsigned long long)atoll(value); - if (tmp_value >= 256) { + if (tmp_value >= UINT_MAX) { invalid_value(arg, value); } - return (unsigned char)tmp_value; -} - -static unsigned short parse_ushort(char *arg, char *value) { - if (!string_is_number(value)) { - invalid_value(arg, value); - } - unsigned long long tmp_value = (unsigned long long)atoll(value); - if (tmp_value >= 65536) { - invalid_value(arg, value); - } - return (unsigned short)tmp_value; + return (unsigned int)tmp_value; } Parameters args_parse(int argc, char **argv) { @@ -80,10 +71,11 @@ Parameters args_parse(int argc, char **argv) { char *arg; char *value; + params.hot_reload = false; params.screen = 0; params.frag_path = 0; params.frag_config_path = 0; - params.hot_reload = false; + params.internal_size = 720; params.base_tempo = 60.0f; params.demo = false; @@ -98,13 +90,15 @@ Parameters args_parse(int argc, char **argv) { } else if (is_arg(arg, "-hr") || is_arg(arg, "--hot-reload")) { params.hot_reload = true; } else if (is_arg(arg, "-s") || is_arg(arg, "--screen")) { - params.screen = parse_uchar(arg, value); + params.screen = parse_uint(arg, value); } else if (is_arg(arg, "-f") || is_arg(arg, "--frag")) { params.frag_path = value; } else if (is_arg(arg, "-fc") || is_arg(arg, "--frag-config")) { params.frag_config_path = value; } else if (is_arg(arg, "-t") || is_arg(arg, "--tempo")) { - params.base_tempo = (float)parse_ushort(arg, value); + params.base_tempo = (float)parse_uint(arg, value); + } else if (is_arg(arg, "-is") || is_arg(arg, "--internal-size")) { + params.internal_size = (float)parse_uint(arg, value); } else if (is_arg(arg, "--demo")) { params.demo = true; } else { diff --git a/src/forge.c b/src/forge.c index b3b2ba8..be94d02 100644 --- a/src/forge.c +++ b/src/forge.c @@ -175,6 +175,8 @@ void forge_run(Parameters params) { window_get_context(window, &context); + context.internal_size = params.internal_size; + program = shaders_init(fragment_shaders, shader_config, context); init_context(program, &context, params); diff --git a/src/shaders.c b/src/shaders.c index c4e41f7..67295cd 100644 --- a/src/shaders.c +++ b/src/shaders.c @@ -49,8 +49,10 @@ static void init_textures(ShaderProgram *program, Context context) { glBindTexture(GL_TEXTURE_2D, program->textures[i]); // define texture image as empty - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context.width, context.height, 0, - GL_RGB, GL_UNSIGNED_BYTE, 0); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGB, + (int)(context.internal_size * (float)context.width / context.height), + context.internal_size, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); // setup mipmap context glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -288,8 +290,10 @@ static void update_viewport(ShaderProgram program, Context context) { // clean and resize all textures for (i = 0; i < program.tex_count; i++) { glActiveTexture(GL_TEXTURE0 + i); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context.width, context.height, 0, - GL_RGB, GL_UNSIGNED_BYTE, 0); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGB, + (int)(context.internal_size * (float)context.width / context.height), + context.internal_size, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); } } } @@ -362,5 +366,5 @@ void shaders_apply(ShaderProgram program, Context context) { } } - use_program(program, program.frag_output_index, true, context); + use_program(program, program.frag_monitor_index, true, context); } diff --git a/src/types.h b/src/types.h index adc377f..d7a3d27 100644 --- a/src/types.h +++ b/src/types.h @@ -16,6 +16,7 @@ typedef struct Parameters { bool hot_reload; float base_tempo; bool demo; + unsigned int internal_size; } Parameters; typedef struct Vertex { @@ -73,6 +74,7 @@ typedef GLFWwindow Window; typedef struct Context { int width; int height; + unsigned int internal_size; double time; unsigned int fps; float tempo;