state outside shaders
This commit is contained in:
@@ -66,6 +66,7 @@ static void loop(Window *window, ShaderProgram program, bool hr,
|
||||
File *common_shader_code, File *fragment_shaders,
|
||||
Timer *timer) {
|
||||
Context context;
|
||||
int size;
|
||||
|
||||
if (hr) {
|
||||
hot_reload(program, common_shader_code, fragment_shaders);
|
||||
@@ -76,9 +77,17 @@ static void loop(Window *window, ShaderProgram program, bool hr,
|
||||
context.fps = compute_fps(window, timer);
|
||||
context.tempo = 120.0f; // TODO need tempo here
|
||||
|
||||
// TODO temporary state
|
||||
size = program.frag_count * program.sub_type_count * sizeof(unsigned int);
|
||||
context.sub_state = malloc(size);
|
||||
memset(context.sub_state, 0, size);
|
||||
context.sub_state[0] = 1;
|
||||
|
||||
shaders_apply(program, context);
|
||||
|
||||
window_refresh(window);
|
||||
|
||||
free(context.sub_state);
|
||||
}
|
||||
|
||||
File read_fragment_shader_file(char *frag_path, unsigned int i) {
|
||||
|
||||
+5
-9
@@ -4,7 +4,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "config_file.h"
|
||||
#include "constants.h"
|
||||
#include "logs.h"
|
||||
@@ -223,9 +222,9 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
||||
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.frag_output_index =
|
||||
config_file_get_int(shader_config, "FRAG_OUT", 0) - 1;
|
||||
config_file_get_int(shader_config, "FRAG_OUTPUT", 1) - 1;
|
||||
program.frag_monitor_index =
|
||||
config_file_get_int(shader_config, "FRAG_MONITOR", 0) - 1;
|
||||
config_file_get_int(shader_config, "FRAG_MONITOR", 1) - 1;
|
||||
program.sub_type_count =
|
||||
config_file_get_int(shader_config, "SUB_TYPE_COUNT", 0);
|
||||
program.sub_variant_count =
|
||||
@@ -310,12 +309,9 @@ static void use_program(ShaderProgram program, int i, bool output,
|
||||
glUniform1i(program.ifps_locations[i], (const GLint)context.fps);
|
||||
glUniform2fv(program.ires_locations[i], 1, (const GLfloat *)&resolution);
|
||||
|
||||
// set subroutines for fragment
|
||||
for (j = 0; j < program.sub_type_count; j++) {
|
||||
k = 0;
|
||||
if (j == 0 &&
|
||||
i == 1) { // TODO pass context here to select correct sub with mapping
|
||||
k = 1;
|
||||
}
|
||||
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];
|
||||
@@ -338,7 +334,7 @@ void shaders_apply(ShaderProgram program, Context context) {
|
||||
|
||||
update_viewport(program, context);
|
||||
|
||||
for (i = 0; i < program.frag_count + 1; i++) {
|
||||
for (i = 0; i < program.frag_count; i++) {
|
||||
if (i != program.frag_output_index && i != program.frag_monitor_index) {
|
||||
use_program(program, i, false, context);
|
||||
}
|
||||
|
||||
+1
-2
@@ -6,8 +6,6 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
@@ -74,6 +72,7 @@ typedef struct Context {
|
||||
double time;
|
||||
unsigned int fps;
|
||||
float tempo;
|
||||
unsigned int *sub_state;
|
||||
} Context;
|
||||
|
||||
typedef struct Timer {
|
||||
|
||||
Reference in New Issue
Block a user