bind any number of textures (i'm unstoppable)
This commit is contained in:
@@ -22,6 +22,7 @@ uniform sampler2D tex4;
|
|||||||
uniform sampler2D tex5;
|
uniform sampler2D tex5;
|
||||||
uniform sampler2D tex6;
|
uniform sampler2D tex6;
|
||||||
uniform sampler2D tex7;
|
uniform sampler2D tex7;
|
||||||
|
uniform sampler2D tex8;
|
||||||
|
|
||||||
// 3. definitions
|
// 3. definitions
|
||||||
// --------------
|
// --------------
|
||||||
|
|||||||
+1
-1
@@ -8,5 +8,5 @@ in vec2 vUV;
|
|||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = fx_stage(vUV, tex7, tex0);
|
fragColor = fx_stage(vUV, tex8, tex0);
|
||||||
}
|
}
|
||||||
+3
-2
@@ -18,6 +18,7 @@ void main() {
|
|||||||
fragColor += s(uv,0,1) * texture(tex4, uv);
|
fragColor += s(uv,0,1) * texture(tex4, uv);
|
||||||
fragColor += s(uv,1,1) * texture(tex5, uv);
|
fragColor += s(uv,1,1) * texture(tex5, uv);
|
||||||
fragColor += s(uv,2,1) * texture(tex6, uv);
|
fragColor += s(uv,2,1) * texture(tex6, uv);
|
||||||
fragColor += s(uv,0.5,0) * texture(tex7, uv-vec2(0.5,0));
|
fragColor += s(uv,0,0) * texture(tex7, uv);
|
||||||
fragColor += s(uv,1.5,0) * texture(tex0, uv-vec2(0.5,0));
|
fragColor += s(uv,1,0) * texture(tex8, uv);
|
||||||
|
fragColor += s(uv,2,0) * texture(tex0, uv);
|
||||||
}
|
}
|
||||||
+4
-1
@@ -2,6 +2,9 @@ UNIFORM_TIME=iTime
|
|||||||
UNIFORM_TEMPO=iTempo
|
UNIFORM_TEMPO=iTempo
|
||||||
UNIFORM_FPS=iFPS
|
UNIFORM_FPS=iFPS
|
||||||
UNIFORM_RESOLUTION=iResolution
|
UNIFORM_RESOLUTION=iResolution
|
||||||
|
UNIFORM_TEX_PREFIX=tex
|
||||||
|
|
||||||
|
TEX_COUNT=9
|
||||||
|
|
||||||
FRAG_COUNT=8
|
FRAG_COUNT=8
|
||||||
FRAG_OUTPUT=7
|
FRAG_OUTPUT=7
|
||||||
@@ -10,7 +13,7 @@ FRAG_1_OUT=2
|
|||||||
FRAG_2_OUT=5
|
FRAG_2_OUT=5
|
||||||
FRAG_3_OUT=3
|
FRAG_3_OUT=3
|
||||||
FRAG_4_OUT=6
|
FRAG_4_OUT=6
|
||||||
FRAG_5_OUT=7
|
FRAG_5_OUT=8
|
||||||
FRAG_6_OUT=0
|
FRAG_6_OUT=0
|
||||||
|
|
||||||
SUB_TYPE_COUNT=3
|
SUB_TYPE_COUNT=3
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
#define VERSION "(dev)"
|
#define VERSION "(dev)"
|
||||||
#endif /* VERSION */
|
#endif /* VERSION */
|
||||||
|
|
||||||
#ifndef TEX_COUNT
|
|
||||||
#define TEX_COUNT 8
|
|
||||||
#endif /* TEXT_COUNT */
|
|
||||||
|
|
||||||
#ifndef SUB_COUNT
|
#ifndef SUB_COUNT
|
||||||
#define SUB_COUNT 16
|
#define SUB_COUNT 16
|
||||||
#endif /* SUB_COUNT */
|
#endif /* SUB_COUNT */
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ void forge_run(Parameters params) {
|
|||||||
|
|
||||||
timer = timer_init(30);
|
timer = timer_init(30);
|
||||||
|
|
||||||
|
log_success("Initialized");
|
||||||
|
|
||||||
while (!window_should_close(window)) {
|
while (!window_should_close(window)) {
|
||||||
loop(window, program, params.hot_reload, &common_shader_code,
|
loop(window, program, params.hot_reload, &common_shader_code,
|
||||||
fragment_shaders, &timer);
|
fragment_shaders, &timer);
|
||||||
|
|||||||
+16
-15
@@ -39,9 +39,11 @@ static bool compile_shader(GLuint shader_id, char *name, char *source_code) {
|
|||||||
static void init_textures(ShaderProgram *program, Context context) {
|
static void init_textures(ShaderProgram *program, Context context) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
glGenTextures(TEX_COUNT, program->textures);
|
program->textures = malloc(program->tex_count * sizeof(GLuint));
|
||||||
|
|
||||||
for (i = 0; i < TEX_COUNT; i++) {
|
glGenTextures(program->tex_count, program->textures);
|
||||||
|
|
||||||
|
for (i = 0; i < program->tex_count; i++) {
|
||||||
// selects which texture unit subsequent texture state calls will affect
|
// selects which texture unit subsequent texture state calls will affect
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ static void init_textures(ShaderProgram *program, Context context) {
|
|||||||
|
|
||||||
static void init_framebuffers(ShaderProgram *program,
|
static void init_framebuffers(ShaderProgram *program,
|
||||||
ConfigFile shader_config) {
|
ConfigFile shader_config) {
|
||||||
unsigned int i, j;
|
unsigned int i;
|
||||||
unsigned tex_i;
|
unsigned tex_i;
|
||||||
char name[32];
|
char name[32];
|
||||||
|
|
||||||
@@ -135,6 +137,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
|||||||
ConfigFile shader_config) {
|
ConfigFile shader_config) {
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
char name[32];
|
char name[32];
|
||||||
|
char *tex_prefix;
|
||||||
|
|
||||||
program->programs[i] = glCreateProgram();
|
program->programs[i] = glCreateProgram();
|
||||||
|
|
||||||
@@ -172,9 +175,10 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create texX uniforms pointer
|
// create texX uniforms pointer
|
||||||
for (j = 0; j < TEX_COUNT; j++) {
|
tex_prefix = config_file_get_str(shader_config, "UNIFORM_TEX_PREFIX", "tex");
|
||||||
sprintf(name, "tex%d", j);
|
for (j = 0; j < program->tex_count; j++) {
|
||||||
program->textures_locations[j][i] =
|
sprintf(name, "%s%d", tex_prefix, j);
|
||||||
|
program->textures_locations[i * program->frag_count + j] =
|
||||||
glGetUniformLocation(program->programs[i], name);
|
glGetUniformLocation(program->programs[i], name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,11 +204,8 @@ static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
|
|||||||
program->ifps_locations = malloc(program->frag_count * sizeof(GLuint));
|
program->ifps_locations = malloc(program->frag_count * sizeof(GLuint));
|
||||||
program->ires_locations = malloc(program->frag_count * sizeof(GLuint));
|
program->ires_locations = malloc(program->frag_count * sizeof(GLuint));
|
||||||
program->vpos_locations = malloc(program->frag_count * sizeof(GLuint));
|
program->vpos_locations = malloc(program->frag_count * sizeof(GLuint));
|
||||||
|
program->textures_locations =
|
||||||
for (i = 0; i < TEX_COUNT; i++) {
|
malloc(program->frag_count * program->tex_count * sizeof(GLuint));
|
||||||
program->textures_locations[i] =
|
|
||||||
malloc(program->frag_count * sizeof(GLuint));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < program->frag_count; i++) {
|
for (i = 0; i < program->frag_count; i++) {
|
||||||
init_single_program(program, i, shader_config);
|
init_single_program(program, i, shader_config);
|
||||||
@@ -218,8 +219,8 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
|||||||
program.error = false;
|
program.error = false;
|
||||||
program.last_width = context.width;
|
program.last_width = context.width;
|
||||||
program.last_height = context.height;
|
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.frag_count = config_file_get_int(shader_config, "FRAG_COUNT", 6);
|
||||||
program.framebuffer_count = program.frag_count - 2;
|
|
||||||
program.frag_output_index =
|
program.frag_output_index =
|
||||||
config_file_get_int(shader_config, "FRAG_OUT", 0) - 1;
|
config_file_get_int(shader_config, "FRAG_OUT", 0) - 1;
|
||||||
program.frag_monitor_index =
|
program.frag_monitor_index =
|
||||||
@@ -266,7 +267,7 @@ static void update_viewport(ShaderProgram program, Context context) {
|
|||||||
glViewport(0, 0, context.width, context.height);
|
glViewport(0, 0, context.width, context.height);
|
||||||
|
|
||||||
// clean and resize all textures
|
// clean and resize all textures
|
||||||
for (i = 0; i < TEX_COUNT; i++) {
|
for (i = 0; i < program.tex_count; i++) {
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context.width, context.height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context.width, context.height, 0,
|
||||||
GL_RGB, GL_UNSIGNED_BYTE, 0);
|
GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||||
@@ -312,8 +313,8 @@ static void use_program(ShaderProgram program, int i, bool output,
|
|||||||
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 3, subroutines);
|
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 3, subroutines);
|
||||||
|
|
||||||
// set GL_TEXTURE(X) to uniform sampler2D texX
|
// set GL_TEXTURE(X) to uniform sampler2D texX
|
||||||
for (j = 0; j < TEX_COUNT; j++) {
|
for (j = 0; j < program.tex_count; j++) {
|
||||||
glUniform1i(program.textures_locations[j][i], j);
|
glUniform1i(program.textures_locations[i * program.frag_count + j], j);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw output
|
// draw output
|
||||||
|
|||||||
+3
-5
@@ -39,7 +39,7 @@ typedef struct ShaderProgram {
|
|||||||
unsigned int frag_output_index;
|
unsigned int frag_output_index;
|
||||||
unsigned int frag_monitor_index;
|
unsigned int frag_monitor_index;
|
||||||
|
|
||||||
unsigned int framebuffer_count;
|
unsigned int tex_count;
|
||||||
|
|
||||||
GLuint *programs;
|
GLuint *programs;
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ typedef struct ShaderProgram {
|
|||||||
GLuint *ifps_locations;
|
GLuint *ifps_locations;
|
||||||
GLuint *ires_locations;
|
GLuint *ires_locations;
|
||||||
|
|
||||||
GLuint *textures_locations[TEX_COUNT];
|
GLuint *textures_locations;
|
||||||
|
|
||||||
GLuint sub_src_indexes[8][SUB_COUNT]; // TODO change
|
GLuint sub_src_indexes[8][SUB_COUNT]; // TODO change
|
||||||
GLuint sub_fx_indexes[8][SUB_COUNT];
|
GLuint sub_fx_indexes[8][SUB_COUNT];
|
||||||
@@ -64,9 +64,7 @@ typedef struct ShaderProgram {
|
|||||||
GLuint vertex_array;
|
GLuint vertex_array;
|
||||||
|
|
||||||
GLuint *frame_buffers;
|
GLuint *frame_buffers;
|
||||||
GLuint textures[TEX_COUNT];
|
GLuint *textures;
|
||||||
|
|
||||||
GLenum draw_buffers[TEX_COUNT];
|
|
||||||
} ShaderProgram;
|
} ShaderProgram;
|
||||||
|
|
||||||
typedef GLFWwindow Window;
|
typedef GLFWwindow Window;
|
||||||
|
|||||||
Reference in New Issue
Block a user