pass internal dimensions to shaders
This commit is contained in:
@@ -3,6 +3,8 @@ UNIFORM_TEMPO=iTempo
|
|||||||
UNIFORM_FPS=iFPS
|
UNIFORM_FPS=iFPS
|
||||||
UNIFORM_DEMO=iDemo
|
UNIFORM_DEMO=iDemo
|
||||||
UNIFORM_RESOLUTION=iResolution
|
UNIFORM_RESOLUTION=iResolution
|
||||||
|
UNIFORM_TEX_RESOLUTION=iTexResolution
|
||||||
|
UNIFORM_IN_RESOLUTION_PREFIX=iInputResolution
|
||||||
UNIFORM_SEED_PREFIX=seed
|
UNIFORM_SEED_PREFIX=seed
|
||||||
UNIFORM_STATE_PREFIX=state
|
UNIFORM_STATE_PREFIX=state
|
||||||
UNIFORM_TEX_PREFIX=tex
|
UNIFORM_TEX_PREFIX=tex
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ uniform float iTime;
|
|||||||
uniform float iTempo;
|
uniform float iTempo;
|
||||||
uniform int iFPS;
|
uniform int iFPS;
|
||||||
uniform vec2 iResolution;
|
uniform vec2 iResolution;
|
||||||
|
uniform vec2 iTexResolution;
|
||||||
uniform int iDemo;
|
uniform int iDemo;
|
||||||
|
|
||||||
uniform int seed1;
|
uniform int seed1;
|
||||||
|
|||||||
+1
-1
@@ -241,7 +241,7 @@ void forge_run(Parameters params) {
|
|||||||
|
|
||||||
window_startup(error_callback);
|
window_startup(error_callback);
|
||||||
|
|
||||||
context.internal_size = params.internal_size;
|
context.internal_height = params.internal_size;
|
||||||
|
|
||||||
init_devices(params.video_in, params.video_count, params.internal_size);
|
init_devices(params.video_in, params.video_count, params.internal_size);
|
||||||
|
|
||||||
|
|||||||
+39
-27
@@ -50,10 +50,8 @@ static void init_textures(ShaderProgram *program, Context context) {
|
|||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
// define texture image as empty
|
// define texture image as empty
|
||||||
glTexImage2D(
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context.internal_width,
|
||||||
GL_TEXTURE_2D, 0, GL_RGB,
|
context.internal_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||||
(int)(context.internal_size * (float)context.width / (context.height)),
|
|
||||||
context.internal_size, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
|
||||||
|
|
||||||
// setup mipmap context
|
// setup mipmap context
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
@@ -244,10 +242,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
|||||||
ConfigFile shader_config) {
|
ConfigFile shader_config) {
|
||||||
unsigned int j, k;
|
unsigned int j, k;
|
||||||
char name[32];
|
char name[32];
|
||||||
char *tex_prefix;
|
char *prefix;
|
||||||
char *sub_prefix;
|
|
||||||
char *seed_prefix;
|
|
||||||
char *state_prefix;
|
|
||||||
program->programs[i] = glCreateProgram();
|
program->programs[i] = glCreateProgram();
|
||||||
|
|
||||||
glAttachShader(program->programs[i], program->vertex_shader);
|
glAttachShader(program->programs[i], program->vertex_shader);
|
||||||
@@ -267,23 +262,34 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
|||||||
program->ires_locations[i] = glGetUniformLocation(
|
program->ires_locations[i] = glGetUniformLocation(
|
||||||
program->programs[i],
|
program->programs[i],
|
||||||
config_file_get_str(shader_config, "UNIFORM_RESOLUTION", "iResolution"));
|
config_file_get_str(shader_config, "UNIFORM_RESOLUTION", "iResolution"));
|
||||||
|
program->itexres_locations[i] = glGetUniformLocation(
|
||||||
|
program->programs[i],
|
||||||
|
config_file_get_str(shader_config, "UNIFORM_TEX_RESOLUTION",
|
||||||
|
"iTexResolution"));
|
||||||
program->idemo_locations[i] = glGetUniformLocation(
|
program->idemo_locations[i] = glGetUniformLocation(
|
||||||
program->programs[i],
|
program->programs[i],
|
||||||
config_file_get_str(shader_config, "UNIFORM_DEMO", "iDemo"));
|
config_file_get_str(shader_config, "UNIFORM_DEMO", "iDemo"));
|
||||||
|
|
||||||
seed_prefix =
|
prefix = config_file_get_str(shader_config, "UNIFORM_IN_RESOLUTION_PREFIX",
|
||||||
config_file_get_str(shader_config, "UNIFORM_SEED_PREFIX", "seed");
|
"iInputResolution");
|
||||||
|
|
||||||
|
for (j = 0; j < program->in_count; j++) {
|
||||||
|
sprintf(name, "%s%d", prefix, j + 1);
|
||||||
|
program->iinres_locations[i * program->in_count + j] =
|
||||||
|
glGetUniformLocation(program->programs[i], name);
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix = config_file_get_str(shader_config, "UNIFORM_SEED_PREFIX", "seed");
|
||||||
for (j = 0; j < program->frag_count; j++) {
|
for (j = 0; j < program->frag_count; j++) {
|
||||||
sprintf(name, "%s%d", seed_prefix, j + 1);
|
sprintf(name, "%s%d", prefix, j + 1);
|
||||||
program->iseed_locations[i * program->frag_count + j] =
|
program->iseed_locations[i * program->frag_count + j] =
|
||||||
glGetUniformLocation(program->programs[i], name);
|
glGetUniformLocation(program->programs[i], name);
|
||||||
}
|
}
|
||||||
|
|
||||||
state_prefix =
|
prefix = config_file_get_str(shader_config, "UNIFORM_STATE_PREFIX", "state");
|
||||||
config_file_get_str(shader_config, "UNIFORM_STATE_PREFIX", "state");
|
|
||||||
for (j = 0; j < program->frag_count; j++) {
|
for (j = 0; j < program->frag_count; j++) {
|
||||||
for (k = 0; k < program->sub_type_count; k++) {
|
for (k = 0; k < program->sub_type_count; k++) {
|
||||||
sprintf(name, "%s%d_%d", state_prefix, j + 1, k + 1);
|
sprintf(name, "%s%d_%d", prefix, j + 1, k + 1);
|
||||||
program
|
program
|
||||||
->istate_locations[i * program->frag_count * program->sub_type_count +
|
->istate_locations[i * program->frag_count * program->sub_type_count +
|
||||||
j * program->sub_type_count + k] =
|
j * program->sub_type_count + k] =
|
||||||
@@ -293,9 +299,9 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
|||||||
|
|
||||||
for (j = 0; j < program->sub_type_count; j++) {
|
for (j = 0; j < program->sub_type_count; j++) {
|
||||||
sprintf(name, "SUB_%d_PREFIX", j + 1);
|
sprintf(name, "SUB_%d_PREFIX", j + 1);
|
||||||
sub_prefix = config_file_get_str(shader_config, name, 0);
|
prefix = config_file_get_str(shader_config, name, 0);
|
||||||
for (k = 0; k < program->sub_variant_count; k++) {
|
for (k = 0; k < program->sub_variant_count; k++) {
|
||||||
sprintf(name, "%s%d", sub_prefix, k + 1);
|
sprintf(name, "%s%d", prefix, k + 1);
|
||||||
program->sub_locations[i * program->sub_variant_count *
|
program->sub_locations[i * program->sub_variant_count *
|
||||||
program->sub_type_count +
|
program->sub_type_count +
|
||||||
j * program->sub_variant_count + k] =
|
j * program->sub_variant_count + k] =
|
||||||
@@ -304,9 +310,9 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create texX uniforms pointer
|
// create texX uniforms pointer
|
||||||
tex_prefix = config_file_get_str(shader_config, "UNIFORM_TEX_PREFIX", "tex");
|
prefix = config_file_get_str(shader_config, "UNIFORM_TEX_PREFIX", "tex");
|
||||||
for (j = 0; j < program->tex_count; j++) {
|
for (j = 0; j < program->tex_count; j++) {
|
||||||
sprintf(name, "%s%d", tex_prefix, j);
|
sprintf(name, "%s%d", prefix, j);
|
||||||
program->textures_locations[i * program->tex_count + j] =
|
program->textures_locations[i * program->tex_count + j] =
|
||||||
glGetUniformLocation(program->programs[i], name);
|
glGetUniformLocation(program->programs[i], name);
|
||||||
}
|
}
|
||||||
@@ -326,6 +332,9 @@ static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
|
|||||||
program->itempo_locations = malloc(program->frag_count * sizeof(GLuint));
|
program->itempo_locations = malloc(program->frag_count * sizeof(GLuint));
|
||||||
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->itexres_locations = malloc(program->frag_count * sizeof(GLuint));
|
||||||
|
program->iinres_locations =
|
||||||
|
malloc(program->frag_count * program->in_count * sizeof(GLuint));
|
||||||
program->idemo_locations = malloc(program->frag_count * sizeof(GLuint));
|
program->idemo_locations = malloc(program->frag_count * sizeof(GLuint));
|
||||||
program->iseed_locations =
|
program->iseed_locations =
|
||||||
malloc(program->frag_count * program->frag_count * sizeof(GLuint));
|
malloc(program->frag_count * program->frag_count * sizeof(GLuint));
|
||||||
@@ -416,10 +425,8 @@ static void update_viewport(ShaderProgram program, Context context) {
|
|||||||
// clean and resize all textures
|
// clean and resize all textures
|
||||||
for (i = 0; i < program.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,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context.internal_width,
|
||||||
(int)(context.internal_size * (float)context.width /
|
context.internal_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||||
(context.height)),
|
|
||||||
context.internal_size, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,10 +435,12 @@ static void use_program(ShaderProgram program, int i, bool output,
|
|||||||
Context context) {
|
Context context) {
|
||||||
unsigned int j, k;
|
unsigned int j, k;
|
||||||
GLuint *subroutines;
|
GLuint *subroutines;
|
||||||
vec2 resolution;
|
vec2 resolution, tex_resolution;
|
||||||
|
|
||||||
resolution[0] = (float)context.width;
|
resolution[0] = (float)context.width;
|
||||||
resolution[1] = (float)context.height;
|
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));
|
subroutines = malloc(program.sub_type_count * sizeof(GLuint));
|
||||||
|
|
||||||
// use specific shader program
|
// use specific shader program
|
||||||
@@ -446,10 +455,7 @@ static void use_program(ShaderProgram program, int i, bool output,
|
|||||||
// clear buffer
|
// clear buffer
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
} else {
|
} else {
|
||||||
glViewport(
|
glViewport(0, 0, context.internal_width, context.internal_height);
|
||||||
0, 0,
|
|
||||||
(int)(context.internal_size * (float)context.width / (context.height)),
|
|
||||||
context.internal_size);
|
|
||||||
|
|
||||||
// use memory framebuffer
|
// use memory framebuffer
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, program.frame_buffers[i]);
|
glBindFramebuffer(GL_FRAMEBUFFER, program.frame_buffers[i]);
|
||||||
@@ -461,6 +467,10 @@ static void use_program(ShaderProgram program, int i, bool output,
|
|||||||
glUniform1i(program.ifps_locations[i], (const GLint)context.fps);
|
glUniform1i(program.ifps_locations[i], (const GLint)context.fps);
|
||||||
glUniform1i(program.idemo_locations[i], (const GLint)(context.demo ? 1 : 0));
|
glUniform1i(program.idemo_locations[i], (const GLint)(context.demo ? 1 : 0));
|
||||||
glUniform2fv(program.ires_locations[i], 1, (const GLfloat *)&resolution);
|
glUniform2fv(program.ires_locations[i], 1, (const GLfloat *)&resolution);
|
||||||
|
glUniform2fv(program.itexres_locations[i], 1,
|
||||||
|
(const GLfloat *)&tex_resolution);
|
||||||
|
|
||||||
|
// TODO video resolution
|
||||||
|
|
||||||
// set seeds uniforms
|
// set seeds uniforms
|
||||||
for (j = 0; j < program.frag_count; j++) {
|
for (j = 0; j < program.frag_count; j++) {
|
||||||
@@ -493,6 +503,8 @@ static void use_program(ShaderProgram program, int i, bool output,
|
|||||||
|
|
||||||
// draw output
|
// draw output
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
free(subroutines);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaders_compute(ShaderProgram program, Context context, bool monitor,
|
void shaders_compute(ShaderProgram program, Context context, bool monitor,
|
||||||
|
|||||||
+4
-1
@@ -67,6 +67,8 @@ typedef struct ShaderProgram {
|
|||||||
GLuint *itempo_locations;
|
GLuint *itempo_locations;
|
||||||
GLuint *ifps_locations;
|
GLuint *ifps_locations;
|
||||||
GLuint *ires_locations;
|
GLuint *ires_locations;
|
||||||
|
GLuint *itexres_locations;
|
||||||
|
GLuint *iinres_locations;
|
||||||
GLuint *idemo_locations;
|
GLuint *idemo_locations;
|
||||||
GLuint *iseed_locations;
|
GLuint *iseed_locations;
|
||||||
GLuint *istate_locations;
|
GLuint *istate_locations;
|
||||||
@@ -102,7 +104,8 @@ typedef GLFWwindow Window;
|
|||||||
typedef struct Context {
|
typedef struct Context {
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
unsigned int internal_size;
|
unsigned int internal_width;
|
||||||
|
unsigned int internal_height;
|
||||||
double time;
|
double time;
|
||||||
unsigned int fps;
|
unsigned int fps;
|
||||||
float tempo;
|
float tempo;
|
||||||
|
|||||||
@@ -122,6 +122,8 @@ double window_get_time() { return glfwGetTime(); }
|
|||||||
void window_use(Window *window, Context *context) {
|
void window_use(Window *window, Context *context) {
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glfwGetFramebufferSize(window, &context->width, &context->height);
|
glfwGetFramebufferSize(window, &context->width, &context->height);
|
||||||
|
context->internal_width = (int)(context->internal_height *
|
||||||
|
(float)context->width / (context->height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_close(Window *window) {
|
void window_close(Window *window) {
|
||||||
|
|||||||
Reference in New Issue
Block a user