shared context and rename config filer
This commit is contained in:
+5
-5
@@ -22,7 +22,7 @@ static void print_help(int status_code) {
|
||||
"[-m=SCREEN] "
|
||||
"[-mo] "
|
||||
"[-f=DIR_PATH] "
|
||||
"[-fc=CFG_PATH] "
|
||||
"[-c=CFG_PATH] "
|
||||
"[-is=SIZE] "
|
||||
"[-v=FILE] "
|
||||
"[-vs=SIZE] "
|
||||
@@ -39,7 +39,7 @@ static void print_help(int status_code) {
|
||||
" -m, --monitor monitor screen number (default: none)\n"
|
||||
" -mo, --monitor-only no output screen\n"
|
||||
" -f, --frag fragment shaders directory (default: TODO)\n"
|
||||
" -fc, --frag-config fragment shaders config file (default: "
|
||||
" -c, --config fragment shaders config file (default: "
|
||||
"TODO)\n"
|
||||
" -is, --internal-size internal texture height (default: 720)\n"
|
||||
" -v, --video-in path to video capture device (multiple "
|
||||
@@ -92,7 +92,7 @@ Parameters args_parse(int argc, char **argv) {
|
||||
params.monitor = false;
|
||||
params.monitor_screen = 0;
|
||||
params.frag_path = 0;
|
||||
params.frag_config_path = 0;
|
||||
params.config_path = 0;
|
||||
params.internal_size = 720;
|
||||
params.video_size = 0;
|
||||
params.base_tempo = 60.0f;
|
||||
@@ -114,8 +114,8 @@ Parameters args_parse(int argc, char **argv) {
|
||||
params.output_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, "-c") || is_arg(arg, "--config")) {
|
||||
params.config_path = value;
|
||||
} else if (is_arg(arg, "-is") || is_arg(arg, "--internal-size")) {
|
||||
params.internal_size = parse_uint(arg, value);
|
||||
if (params.internal_size == 0) {
|
||||
|
||||
+39
-57
@@ -16,7 +16,7 @@
|
||||
#include "video.h"
|
||||
#include "window.h"
|
||||
|
||||
static Context context;
|
||||
static SharedContext *context;
|
||||
static ShaderProgram program;
|
||||
static Window *window_output;
|
||||
static Window *window_monitor;
|
||||
@@ -24,12 +24,9 @@ static VideoCapture *inputs;
|
||||
static File *fragment_shaders;
|
||||
static File common_shader_code;
|
||||
static Timer timer;
|
||||
static ConfigFile shader_config;
|
||||
static SharedBool *stop;
|
||||
static ConfigFile config;
|
||||
|
||||
static void compute_fps() {
|
||||
unsigned int i;
|
||||
|
||||
double fps;
|
||||
char title[100];
|
||||
|
||||
@@ -48,13 +45,7 @@ static void compute_fps() {
|
||||
window_update_title(window_monitor, title);
|
||||
}
|
||||
|
||||
context.fps = (unsigned int)round(fps);
|
||||
}
|
||||
|
||||
for (i = 0; i < program.in_count; i++) {
|
||||
if (!inputs[i].error) {
|
||||
context.input_fps[i] = inputs[i].fps->value;
|
||||
}
|
||||
context->fps = (unsigned int)round(fps);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,54 +53,43 @@ static void randomize_context_state() {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < program.frag_count * program.sub_type_count; i++) {
|
||||
context.sub_state[i] = rand_uint(program.sub_variant_count);
|
||||
context->sub_state[i] = rand_uint(program.sub_variant_count);
|
||||
}
|
||||
}
|
||||
static void init_context(Parameters params) {
|
||||
unsigned int i;
|
||||
|
||||
context.tempo = params.base_tempo;
|
||||
context.demo = params.demo;
|
||||
context.monitor = params.monitor;
|
||||
context->tempo = params.base_tempo;
|
||||
context->demo = params.demo;
|
||||
context->monitor = params.monitor;
|
||||
|
||||
context.sub_state = (unsigned int *)calloc(
|
||||
program.frag_count * program.sub_type_count, sizeof(unsigned int));
|
||||
memset(context->sub_state, 0, sizeof(context->sub_state));
|
||||
|
||||
if (params.demo) {
|
||||
randomize_context_state();
|
||||
}
|
||||
|
||||
context.seeds = malloc(program.frag_count * sizeof(unsigned int));
|
||||
memset(context->seeds, 0, sizeof(context->seeds));
|
||||
|
||||
for (i = 0; i < program.frag_count; i++) {
|
||||
context.seeds[i] = rand_uint(1000);
|
||||
context->seeds[i] = rand_uint(1000);
|
||||
}
|
||||
|
||||
context.input_widths =
|
||||
(unsigned int *)calloc(program.in_count, sizeof(unsigned int));
|
||||
context.input_heights =
|
||||
(unsigned int *)calloc(program.in_count, sizeof(unsigned int));
|
||||
context.input_formats =
|
||||
(unsigned int *)calloc(program.in_count, sizeof(unsigned int));
|
||||
context.input_fps =
|
||||
(unsigned int *)calloc(program.in_count, sizeof(unsigned int));
|
||||
memset(context->input_widths, 0, sizeof(context->input_widths));
|
||||
memset(context->input_heights, 0, sizeof(context->input_heights));
|
||||
memset(context->input_formats, 0, sizeof(context->input_formats));
|
||||
memset(context->input_fps, 0, sizeof(context->input_fps));
|
||||
|
||||
for (i = 0; i < program.in_count; i++) {
|
||||
if (!inputs[i].error) {
|
||||
context.input_widths[i] = inputs[i].width;
|
||||
context.input_heights[i] = inputs[i].height;
|
||||
context.input_formats[i] = inputs[i].pixelformat;
|
||||
context->input_widths[i] = inputs[i].width;
|
||||
context->input_heights[i] = inputs[i].height;
|
||||
context->input_formats[i] = inputs[i].pixelformat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void free_context() {
|
||||
free(context.sub_state);
|
||||
free(context.seeds);
|
||||
free(context.input_widths);
|
||||
free(context.input_heights);
|
||||
free(context.input_formats);
|
||||
free(context.input_fps);
|
||||
}
|
||||
static void free_context() { shared_close_context(context); }
|
||||
|
||||
static void hot_reload() {
|
||||
unsigned int i;
|
||||
@@ -189,7 +169,7 @@ static void start_video_captures(unsigned int video_count) {
|
||||
|
||||
for (i = 0; i < video_count; i++) {
|
||||
if (!inputs[i].error) {
|
||||
video_background_read(&inputs[i], stop);
|
||||
video_background_read(&inputs[i], context, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,7 +189,7 @@ static void free_video_captures(unsigned int video_count) {
|
||||
static void error_callback(int error, const char *description) {
|
||||
log_error("[GLFW] %d: %s", error, description);
|
||||
window_terminate();
|
||||
stop->value = true;
|
||||
context->stop = true;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -224,7 +204,7 @@ static void key_callback(Window *window, int key,
|
||||
randomize_context_state();
|
||||
} else if (window_char_key(key, action, 68)) {
|
||||
// D: demo on/off
|
||||
context.demo = !context.demo;
|
||||
context->demo = !context->demo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,10 +215,10 @@ static void loop(bool hr) {
|
||||
|
||||
compute_fps();
|
||||
|
||||
context.time = window_get_time();
|
||||
context->time = window_get_time();
|
||||
|
||||
if (window_output != NULL) {
|
||||
window_use(window_output, &context);
|
||||
window_use(window_output, context);
|
||||
|
||||
shaders_compute(program, context, false, false);
|
||||
|
||||
@@ -246,7 +226,7 @@ static void loop(bool hr) {
|
||||
}
|
||||
|
||||
if (window_monitor != NULL) {
|
||||
window_use(window_monitor, &context);
|
||||
window_use(window_monitor, context);
|
||||
|
||||
shaders_compute(program, context, true, window_output != NULL);
|
||||
|
||||
@@ -259,11 +239,13 @@ static void loop(bool hr) {
|
||||
void forge_run(Parameters params) {
|
||||
unsigned int frag_count;
|
||||
|
||||
stop = shared_init_bool("/" PACKAGE "_stop", false);
|
||||
context = shared_init_context("/" PACKAGE "_context");
|
||||
|
||||
shader_config = config_file_read(params.frag_config_path, false);
|
||||
context->stop = false;
|
||||
|
||||
frag_count = config_file_get_int(shader_config, "FRAG_COUNT", 6);
|
||||
config = config_file_read(params.config_path, false);
|
||||
|
||||
frag_count = config_file_get_int(config, "FRAG_COUNT", 6);
|
||||
|
||||
init_files(params.frag_path, frag_count);
|
||||
|
||||
@@ -271,15 +253,15 @@ void forge_run(Parameters params) {
|
||||
|
||||
window_startup(error_callback);
|
||||
|
||||
context.internal_height = params.internal_size;
|
||||
context->internal_height = params.internal_size;
|
||||
|
||||
if (params.output) {
|
||||
window_output = window_init(PACKAGE " " VERSION, params.output_screen,
|
||||
params.windowed, NULL, key_callback);
|
||||
|
||||
window_use(window_output, &context);
|
||||
window_use(window_output, context);
|
||||
|
||||
program = shaders_init(fragment_shaders, shader_config, context, inputs,
|
||||
program = shaders_init(fragment_shaders, config, context, inputs,
|
||||
params.video_in_count, NULL);
|
||||
} else {
|
||||
window_output = NULL;
|
||||
@@ -290,9 +272,9 @@ void forge_run(Parameters params) {
|
||||
window_init(PACKAGE " " VERSION " (monitor)", params.monitor_screen,
|
||||
params.windowed, window_output, key_callback);
|
||||
|
||||
window_use(window_monitor, &context);
|
||||
window_use(window_monitor, context);
|
||||
|
||||
program = shaders_init(fragment_shaders, shader_config, context, inputs,
|
||||
program = shaders_init(fragment_shaders, config, context, inputs,
|
||||
params.video_in_count,
|
||||
window_output != NULL ? &program : NULL);
|
||||
} else {
|
||||
@@ -317,20 +299,20 @@ void forge_run(Parameters params) {
|
||||
loop(params.hot_reload);
|
||||
}
|
||||
|
||||
stop->value = true;
|
||||
context->stop = true;
|
||||
|
||||
wait(NULL);
|
||||
|
||||
shaders_free(program);
|
||||
|
||||
if (window_output != NULL) {
|
||||
window_use(window_output, &context);
|
||||
window_use(window_output, context);
|
||||
|
||||
shaders_free_window(program, false);
|
||||
}
|
||||
|
||||
if (window_monitor != NULL) {
|
||||
window_use(window_monitor, &context);
|
||||
window_use(window_monitor, context);
|
||||
|
||||
shaders_free_window(program, params.output);
|
||||
}
|
||||
@@ -341,7 +323,7 @@ void forge_run(Parameters params) {
|
||||
|
||||
free_files(frag_count);
|
||||
|
||||
config_file_free(shader_config);
|
||||
config_file_free(config);
|
||||
|
||||
window_terminate();
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "forge.h"
|
||||
#include "main.h"
|
||||
#include "rand.h"
|
||||
#include "types.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Parameters params;
|
||||
|
||||
+63
-68
@@ -31,7 +31,7 @@ static void init_gl(ShaderProgram *program) {
|
||||
gladLoadEGL(program->egl_display, glfwGetProcAddress);
|
||||
}
|
||||
|
||||
static void init_textures(ShaderProgram *program, Context context) {
|
||||
static void init_textures(ShaderProgram *program, SharedContext *context) {
|
||||
unsigned int i;
|
||||
|
||||
program->textures = malloc(program->tex_count * sizeof(GLuint));
|
||||
@@ -50,8 +50,8 @@ static void init_textures(ShaderProgram *program, Context context) {
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
// define texture image as empty
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context.internal_width,
|
||||
context.internal_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context->internal_width,
|
||||
context->internal_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
// setup mipmap context
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
@@ -111,7 +111,7 @@ static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
log_info("Texture %d linked to %s", texture_index, input->name);
|
||||
}
|
||||
|
||||
static void init_input(ShaderProgram *program, ConfigFile shader_config,
|
||||
static void init_input(ShaderProgram *program, ConfigFile config,
|
||||
VideoCapture *inputs, unsigned int input_count) {
|
||||
unsigned int i;
|
||||
unsigned tex_i;
|
||||
@@ -120,7 +120,7 @@ static void init_input(ShaderProgram *program, ConfigFile shader_config,
|
||||
for (i = 0; i < program->in_count; i++) {
|
||||
if (i < input_count && !inputs[i].error) {
|
||||
sprintf(name, "IN_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(shader_config, name, 0);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
link_input_to_texture(program, &inputs[i], tex_i);
|
||||
} else {
|
||||
log_warn("Cannot link input %d", i + 1);
|
||||
@@ -128,8 +128,7 @@ static void init_input(ShaderProgram *program, ConfigFile shader_config,
|
||||
}
|
||||
}
|
||||
|
||||
static void init_framebuffers(ShaderProgram *program,
|
||||
ConfigFile shader_config) {
|
||||
static void init_framebuffers(ShaderProgram *program, ConfigFile config) {
|
||||
unsigned int i;
|
||||
unsigned tex_i;
|
||||
char name[32];
|
||||
@@ -146,7 +145,7 @@ static void init_framebuffers(ShaderProgram *program,
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, program->frame_buffers[i]);
|
||||
|
||||
sprintf(name, "FRAG_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(shader_config, name, 0);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
program->textures[tex_i], 0);
|
||||
|
||||
@@ -239,7 +238,7 @@ static void init_shaders(ShaderProgram *program, File *fragment_shaders) {
|
||||
}
|
||||
|
||||
static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
ConfigFile shader_config) {
|
||||
ConfigFile config) {
|
||||
unsigned int j, k;
|
||||
char name[32];
|
||||
char *prefix;
|
||||
@@ -252,25 +251,23 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
// create uniforms pointers
|
||||
program->itime_locations[i] = glGetUniformLocation(
|
||||
program->programs[i],
|
||||
config_file_get_str(shader_config, "UNIFORM_TIME", "iTime"));
|
||||
config_file_get_str(config, "UNIFORM_TIME", "iTime"));
|
||||
program->itempo_locations[i] = glGetUniformLocation(
|
||||
program->programs[i],
|
||||
config_file_get_str(shader_config, "UNIFORM_TEMPO", "iTempo"));
|
||||
config_file_get_str(config, "UNIFORM_TEMPO", "iTempo"));
|
||||
program->ifps_locations[i] = glGetUniformLocation(
|
||||
program->programs[i],
|
||||
config_file_get_str(shader_config, "UNIFORM_FPS", "iFPS"));
|
||||
program->programs[i], config_file_get_str(config, "UNIFORM_FPS", "iFPS"));
|
||||
program->ires_locations[i] = glGetUniformLocation(
|
||||
program->programs[i],
|
||||
config_file_get_str(shader_config, "UNIFORM_RESOLUTION", "iResolution"));
|
||||
config_file_get_str(config, "UNIFORM_RESOLUTION", "iResolution"));
|
||||
program->itexres_locations[i] = glGetUniformLocation(
|
||||
program->programs[i],
|
||||
config_file_get_str(shader_config, "UNIFORM_TEX_RESOLUTION",
|
||||
"iTexResolution"));
|
||||
config_file_get_str(config, "UNIFORM_TEX_RESOLUTION", "iTexResolution"));
|
||||
program->idemo_locations[i] = glGetUniformLocation(
|
||||
program->programs[i],
|
||||
config_file_get_str(shader_config, "UNIFORM_DEMO", "iDemo"));
|
||||
config_file_get_str(config, "UNIFORM_DEMO", "iDemo"));
|
||||
|
||||
prefix = config_file_get_str(shader_config, "UNIFORM_IN_RESOLUTION_PREFIX",
|
||||
prefix = config_file_get_str(config, "UNIFORM_IN_RESOLUTION_PREFIX",
|
||||
"iInputResolution");
|
||||
for (j = 0; j < program->in_count; j++) {
|
||||
sprintf(name, "%s%d", prefix, j + 1);
|
||||
@@ -278,30 +275,29 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(shader_config, "UNIFORM_IN_FORMAT_PREFIX",
|
||||
"iInputFormat");
|
||||
prefix =
|
||||
config_file_get_str(config, "UNIFORM_IN_FORMAT_PREFIX", "iInputFormat");
|
||||
for (j = 0; j < program->in_count; j++) {
|
||||
sprintf(name, "%s%d", prefix, j + 1);
|
||||
program->iinfmt_locations[i * program->in_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix =
|
||||
config_file_get_str(shader_config, "UNIFORM_IN_FPS_PREFIX", "iInputFPS");
|
||||
prefix = config_file_get_str(config, "UNIFORM_IN_FPS_PREFIX", "iInputFPS");
|
||||
for (j = 0; j < program->in_count; j++) {
|
||||
sprintf(name, "%s%d", prefix, j + 1);
|
||||
program->iinfps_locations[i * program->in_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(shader_config, "UNIFORM_SEED_PREFIX", "seed");
|
||||
prefix = config_file_get_str(config, "UNIFORM_SEED_PREFIX", "seed");
|
||||
for (j = 0; j < program->frag_count; j++) {
|
||||
sprintf(name, "%s%d", prefix, j + 1);
|
||||
program->iseed_locations[i * program->frag_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(shader_config, "UNIFORM_STATE_PREFIX", "state");
|
||||
prefix = config_file_get_str(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", prefix, j + 1, k + 1);
|
||||
@@ -314,7 +310,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
|
||||
for (j = 0; j < program->sub_type_count; j++) {
|
||||
sprintf(name, "SUB_%d_PREFIX", j + 1);
|
||||
prefix = config_file_get_str(shader_config, name, 0);
|
||||
prefix = config_file_get_str(config, name, 0);
|
||||
for (k = 0; k < program->sub_variant_count; k++) {
|
||||
sprintf(name, "%s%d", prefix, k + 1);
|
||||
program->sub_locations[i * program->sub_variant_count *
|
||||
@@ -325,7 +321,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
}
|
||||
|
||||
// create texX uniforms pointer
|
||||
prefix = config_file_get_str(shader_config, "UNIFORM_TEX_PREFIX", "tex");
|
||||
prefix = config_file_get_str(config, "UNIFORM_TEX_PREFIX", "tex");
|
||||
for (j = 0; j < program->tex_count; j++) {
|
||||
sprintf(name, "%s%d", prefix, j);
|
||||
program->textures_locations[i * program->tex_count + j] =
|
||||
@@ -339,7 +335,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
log_info("Program %d initialized", i + 1);
|
||||
}
|
||||
|
||||
static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
|
||||
static void init_programs(ShaderProgram *program, ConfigFile config) {
|
||||
unsigned int i;
|
||||
|
||||
program->programs = malloc(program->frag_count * sizeof(GLuint));
|
||||
@@ -367,30 +363,29 @@ static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
|
||||
program->sub_variant_count * sizeof(GLuint));
|
||||
|
||||
for (i = 0; i < program->frag_count; i++) {
|
||||
init_single_program(program, i, shader_config);
|
||||
init_single_program(program, i, config);
|
||||
}
|
||||
}
|
||||
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
||||
Context context, VideoCapture *inputs,
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
|
||||
SharedContext *context, VideoCapture *inputs,
|
||||
unsigned int input_count, ShaderProgram *previous) {
|
||||
ShaderProgram program;
|
||||
|
||||
if (previous == NULL) {
|
||||
program.error = false;
|
||||
program.last_width = context.width;
|
||||
program.last_height = context.height;
|
||||
program.tex_count = config_file_get_int(shader_config, "TEX_COUNT", 9);
|
||||
program.frag_count = config_file_get_int(shader_config, "FRAG_COUNT", 6);
|
||||
program.last_width = context->width;
|
||||
program.last_height = context->height;
|
||||
program.tex_count = config_file_get_int(config, "TEX_COUNT", 9);
|
||||
program.frag_count = config_file_get_int(config, "FRAG_COUNT", 6);
|
||||
program.frag_output_index =
|
||||
config_file_get_int(shader_config, "FRAG_OUTPUT", 1) - 1;
|
||||
config_file_get_int(config, "FRAG_OUTPUT", 1) - 1;
|
||||
program.frag_monitor_index =
|
||||
config_file_get_int(shader_config, "FRAG_MONITOR", 1) - 1;
|
||||
program.sub_type_count =
|
||||
config_file_get_int(shader_config, "SUB_TYPE_COUNT", 0);
|
||||
config_file_get_int(config, "FRAG_MONITOR", 1) - 1;
|
||||
program.sub_type_count = config_file_get_int(config, "SUB_TYPE_COUNT", 0);
|
||||
program.sub_variant_count =
|
||||
config_file_get_int(shader_config, "SUB_VARIANT_COUNT", 0);
|
||||
program.in_count = config_file_get_int(shader_config, "IN_COUNT", 0);
|
||||
config_file_get_int(config, "SUB_VARIANT_COUNT", 0);
|
||||
program.in_count = config_file_get_int(config, "IN_COUNT", 0);
|
||||
|
||||
init_gl(&program);
|
||||
|
||||
@@ -402,11 +397,11 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
||||
|
||||
init_textures(&program, context);
|
||||
|
||||
init_input(&program, shader_config, inputs, input_count);
|
||||
init_input(&program, config, inputs, input_count);
|
||||
|
||||
init_framebuffers(&program, shader_config);
|
||||
init_framebuffers(&program, config);
|
||||
|
||||
init_programs(&program, shader_config);
|
||||
init_programs(&program, config);
|
||||
|
||||
init_vertices(&program);
|
||||
|
||||
@@ -435,38 +430,38 @@ void shaders_update(ShaderProgram program, File *fragment_shaders,
|
||||
}
|
||||
}
|
||||
|
||||
static void update_viewport(ShaderProgram program, Context context) {
|
||||
static void update_viewport(ShaderProgram program, SharedContext *context) {
|
||||
unsigned int i;
|
||||
|
||||
// viewport changed
|
||||
if (context.width != program.last_width ||
|
||||
context.height != program.last_height) {
|
||||
if (context->width != program.last_width ||
|
||||
context->height != program.last_height) {
|
||||
// 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.internal_width,
|
||||
context.internal_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context->internal_width,
|
||||
context->internal_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void use_program(ShaderProgram program, int i, bool output,
|
||||
Context context) {
|
||||
SharedContext *context) {
|
||||
unsigned int j, k;
|
||||
GLuint *subroutines;
|
||||
vec2 resolution, tex_resolution, in_resolution;
|
||||
|
||||
resolution[0] = (float)context.width;
|
||||
resolution[1] = (float)context.height;
|
||||
tex_resolution[0] = (float)context.internal_width;
|
||||
tex_resolution[1] = (float)context.internal_height;
|
||||
resolution[0] = (float)context->width;
|
||||
resolution[1] = (float)context->height;
|
||||
tex_resolution[0] = (float)context->internal_width;
|
||||
tex_resolution[1] = (float)context->internal_height;
|
||||
subroutines = malloc(program.sub_type_count * sizeof(GLuint));
|
||||
|
||||
// use specific shader program
|
||||
glUseProgram(program.programs[i]);
|
||||
|
||||
if (output) {
|
||||
glViewport(0, 0, context.width, context.height);
|
||||
glViewport(0, 0, context->width, context->height);
|
||||
|
||||
// use default framebuffer (output)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
@@ -474,42 +469,42 @@ static void use_program(ShaderProgram program, int i, bool output,
|
||||
// clear buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
} else {
|
||||
glViewport(0, 0, context.internal_width, context.internal_height);
|
||||
glViewport(0, 0, context->internal_width, context->internal_height);
|
||||
|
||||
// use memory framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, program.frame_buffers[i]);
|
||||
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
||||
}
|
||||
// set fragment uniforms
|
||||
glUniform1f(program.itime_locations[i], (const GLfloat)context.time);
|
||||
glUniform1f(program.itempo_locations[i], (const GLfloat)context.tempo);
|
||||
glUniform1i(program.ifps_locations[i], (const GLint)context.fps);
|
||||
glUniform1i(program.idemo_locations[i], (const GLint)(context.demo ? 1 : 0));
|
||||
glUniform1f(program.itime_locations[i], (const GLfloat)context->time);
|
||||
glUniform1f(program.itempo_locations[i], (const GLfloat)context->tempo);
|
||||
glUniform1i(program.ifps_locations[i], (const GLint)context->fps);
|
||||
glUniform1i(program.idemo_locations[i], (const GLint)(context->demo ? 1 : 0));
|
||||
glUniform2fv(program.ires_locations[i], 1, (const GLfloat *)&resolution);
|
||||
glUniform2fv(program.itexres_locations[i], 1,
|
||||
(const GLfloat *)&tex_resolution);
|
||||
|
||||
for (j = 0; j < program.in_count; j++) {
|
||||
in_resolution[0] = context.input_widths[j];
|
||||
in_resolution[1] = context.input_heights[j];
|
||||
in_resolution[0] = context->input_widths[j];
|
||||
in_resolution[1] = context->input_heights[j];
|
||||
|
||||
glUniform2fv(program.iinres_locations[i * program.in_count + j], 1,
|
||||
(const GLfloat *)&in_resolution);
|
||||
glUniform1i(program.iinfmt_locations[i * program.in_count + j],
|
||||
(const GLint)context.input_formats[j]);
|
||||
(const GLint)context->input_formats[j]);
|
||||
glUniform1i(program.iinfps_locations[i * program.in_count + j],
|
||||
(const GLint)context.input_fps[j]);
|
||||
(const GLint)context->input_fps[j]);
|
||||
}
|
||||
|
||||
// set seeds uniforms
|
||||
for (j = 0; j < program.frag_count; j++) {
|
||||
glUniform1i(program.iseed_locations[i * program.frag_count + j],
|
||||
(const GLint)context.seeds[j]);
|
||||
(const GLint)context->seeds[j]);
|
||||
}
|
||||
|
||||
// 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];
|
||||
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];
|
||||
@@ -518,7 +513,7 @@ static void use_program(ShaderProgram program, int i, bool output,
|
||||
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]);
|
||||
(const GLint)context->sub_state[k * program.sub_type_count + j]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,8 +531,8 @@ static void use_program(ShaderProgram program, int i, bool output,
|
||||
free(subroutines);
|
||||
}
|
||||
|
||||
void shaders_compute(ShaderProgram program, Context context, bool monitor,
|
||||
bool output_only) {
|
||||
void shaders_compute(ShaderProgram program, SharedContext *context,
|
||||
bool monitor, bool output_only) {
|
||||
unsigned int i;
|
||||
|
||||
if (!output_only) {
|
||||
|
||||
+4
-4
@@ -3,15 +3,15 @@
|
||||
#ifndef SHADERS_H
|
||||
#define SHADERS_H
|
||||
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
||||
Context context, VideoCapture *inputs,
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
|
||||
SharedContext *context, VideoCapture *inputs,
|
||||
unsigned int input_count, ShaderProgram *previous);
|
||||
|
||||
void shaders_update(ShaderProgram program, File *fragment_shaders,
|
||||
unsigned int i);
|
||||
|
||||
void shaders_compute(ShaderProgram program, Context context, bool monitor,
|
||||
bool output_only);
|
||||
void shaders_compute(ShaderProgram program, SharedContext *context,
|
||||
bool monitor, bool output_only);
|
||||
|
||||
void shaders_free(ShaderProgram program);
|
||||
|
||||
|
||||
+6
-23
@@ -18,34 +18,17 @@ static void close_shared(void *shared, size_t size, int fd) {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
SharedUint *shared_init_uint(const char *key, unsigned int initial_value) {
|
||||
SharedContext *shared_init_context(const char *key) {
|
||||
int shared_fd;
|
||||
SharedUint *shared;
|
||||
SharedContext *shared;
|
||||
|
||||
shared = open_shared(key, sizeof(SharedUint), &shared_fd);
|
||||
shared = open_shared(key, sizeof(SharedContext), &shared_fd);
|
||||
|
||||
shared->fd = shared_fd;
|
||||
shared->value = initial_value;
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
void shared_close_uint(SharedUint *shared) {
|
||||
close_shared(shared, sizeof(SharedUint), shared->fd);
|
||||
}
|
||||
|
||||
SharedBool *shared_init_bool(const char *key, bool initial_value) {
|
||||
int shared_fd;
|
||||
SharedBool *shared;
|
||||
|
||||
shared = open_shared(key, sizeof(SharedBool), &shared_fd);
|
||||
|
||||
shared->fd = shared_fd;
|
||||
shared->value = initial_value;
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
void shared_close_bool(SharedBool *shared) {
|
||||
close_shared(shared, sizeof(SharedBool), shared->fd);
|
||||
}
|
||||
void shared_close_context(SharedContext *shared) {
|
||||
close_shared(shared, sizeof(SharedContext), shared->fd);
|
||||
}
|
||||
+2
-5
@@ -3,10 +3,7 @@
|
||||
#ifndef SHARED_H
|
||||
#define SHARED_H
|
||||
|
||||
SharedUint *shared_init_uint(const char *key, unsigned int initial_value);
|
||||
void shared_close_uint(SharedUint *shared);
|
||||
|
||||
SharedBool *shared_init_bool(const char *key, bool initial_value);
|
||||
void shared_close_bool(SharedBool *shared);
|
||||
SharedContext *shared_init_context(const char *key);
|
||||
void shared_close_context(SharedContext *shared);
|
||||
|
||||
#endif /* SHARED_H */
|
||||
+12
-10
@@ -31,7 +31,7 @@ typedef struct Parameters {
|
||||
bool monitor;
|
||||
unsigned int monitor_screen;
|
||||
char *frag_path;
|
||||
char *frag_config_path;
|
||||
char *config_path;
|
||||
unsigned int internal_size;
|
||||
unsigned int video_size;
|
||||
float base_tempo;
|
||||
@@ -108,7 +108,6 @@ typedef struct VideoCapture {
|
||||
unsigned int height;
|
||||
unsigned int pixelformat;
|
||||
unsigned int bytesperline;
|
||||
SharedUint *fps;
|
||||
bool output;
|
||||
struct v4l2_buffer buf;
|
||||
EGLImageKHR dma_image;
|
||||
@@ -116,7 +115,9 @@ typedef struct VideoCapture {
|
||||
|
||||
typedef GLFWwindow Window;
|
||||
|
||||
typedef struct Context {
|
||||
typedef struct SharedContext {
|
||||
int fd;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
unsigned int internal_width;
|
||||
@@ -124,15 +125,16 @@ typedef struct Context {
|
||||
double time;
|
||||
unsigned int fps;
|
||||
float tempo;
|
||||
unsigned int *sub_state;
|
||||
unsigned int sub_state[256]; // TODO
|
||||
bool demo;
|
||||
unsigned int *seeds;
|
||||
unsigned int seeds[256];
|
||||
bool monitor;
|
||||
unsigned int *input_widths;
|
||||
unsigned int *input_heights;
|
||||
unsigned int *input_formats;
|
||||
unsigned int *input_fps;
|
||||
} Context;
|
||||
unsigned int input_widths[256];
|
||||
unsigned int input_heights[256];
|
||||
unsigned int input_formats[256];
|
||||
unsigned int input_fps[256];
|
||||
bool stop;
|
||||
} SharedContext;
|
||||
|
||||
typedef struct Timer {
|
||||
struct timeval start;
|
||||
|
||||
+6
-19
@@ -3,13 +3,10 @@
|
||||
#include <linux/videodev2.h>
|
||||
#include <log.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "rand.h"
|
||||
#include "shared.h"
|
||||
#include "timer.h"
|
||||
#include "types.h"
|
||||
@@ -270,14 +267,6 @@ static void create_image_buffer(VideoCapture *video_capture) {
|
||||
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf);
|
||||
}
|
||||
|
||||
static void create_shared_data(VideoCapture *video_capture) {
|
||||
char name[256];
|
||||
|
||||
sprintf(name, "/" PACKAGE "_fps_%d", rand_uint(1000000));
|
||||
|
||||
video_capture->fps = shared_init_uint(name, 0);
|
||||
}
|
||||
|
||||
static void close_stream(VideoCapture video_capture) {
|
||||
ioctl(video_capture.fd, VIDIOC_STREAMOFF, &buf_type);
|
||||
}
|
||||
@@ -317,8 +306,6 @@ VideoCapture video_init(char *name, unsigned int preferred_height) {
|
||||
|
||||
create_image_buffer(&video_capture);
|
||||
|
||||
create_shared_data(&video_capture);
|
||||
|
||||
return video_capture;
|
||||
}
|
||||
|
||||
@@ -340,7 +327,8 @@ static bool read_video(VideoCapture *video_capture) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void video_background_read(VideoCapture *video_capture, SharedBool *stop) {
|
||||
void video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
int input_index) {
|
||||
pid_t pid;
|
||||
Timer timer;
|
||||
double fps;
|
||||
@@ -357,16 +345,16 @@ void video_background_read(VideoCapture *video_capture, SharedBool *stop) {
|
||||
pid);
|
||||
timer = timer_init(30);
|
||||
|
||||
while (!stop->value && read_video(video_capture)) {
|
||||
while (!context->stop && read_video(video_capture)) {
|
||||
// repeat infinitely
|
||||
if (timer_inc(&timer)) {
|
||||
fps = timer_reset(&timer);
|
||||
|
||||
video_capture->fps->value = (unsigned int)round(fps);
|
||||
context->input_fps[input_index] = (unsigned int)round(fps);
|
||||
log_trace("(%s) %.2ffps", video_capture->name, fps);
|
||||
}
|
||||
}
|
||||
if (stop->value) {
|
||||
if (context->stop) {
|
||||
log_info("%s background acquisition stopped by main thread (pid: %d)",
|
||||
video_capture->name, pid);
|
||||
} else {
|
||||
@@ -374,13 +362,12 @@ void video_background_read(VideoCapture *video_capture, SharedBool *stop) {
|
||||
video_capture->name, pid);
|
||||
}
|
||||
window_terminate();
|
||||
exit(stop->value ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void video_free(VideoCapture video_capture) {
|
||||
if (!video_capture.error) {
|
||||
close_stream(video_capture);
|
||||
shared_close_uint(video_capture.fps);
|
||||
}
|
||||
if (video_capture.exp_fd != -1) {
|
||||
close(video_capture.exp_fd);
|
||||
|
||||
+2
-1
@@ -5,7 +5,8 @@
|
||||
|
||||
VideoCapture video_init(char *name, unsigned int preferred_height);
|
||||
|
||||
void video_background_read(VideoCapture *video_capture, SharedBool *stop);
|
||||
void video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
int input_index);
|
||||
|
||||
void video_free(VideoCapture video_capture);
|
||||
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ void window_events() { glfwPollEvents(); }
|
||||
|
||||
double window_get_time() { return glfwGetTime(); }
|
||||
|
||||
void window_use(Window *window, Context *context) {
|
||||
void window_use(Window *window, SharedContext *context) {
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwGetFramebufferSize(window, &context->width, &context->height);
|
||||
context->internal_width = (int)(context->internal_height *
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ void window_update_title(Window *window, char *title);
|
||||
|
||||
double window_get_time();
|
||||
|
||||
void window_use(Window *window, Context *context);
|
||||
void window_use(Window *window, SharedContext *context);
|
||||
|
||||
void window_refresh(Window *window);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user