aboutsummaryrefslogtreecommitdiff
path: root/src/shader.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-19 22:45:04 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-19 22:45:04 +0200
commit70bf7ac330545f14ab9babddfdf0cb5df9e9ee69 (patch)
treef8d6d124e6ac82e4aadf80ff21310caa7746e84d /src/shader.c
parent3b2e7cc2347d88dbd8d7697a7cbd8354e7728fc0 (diff)
downloadmandelbrot-70bf7ac330545f14ab9babddfdf0cb5df9e9ee69.tar.gz
mandelbrot-70bf7ac330545f14ab9babddfdf0cb5df9e9ee69.tar.bz2
mandelbrot-70bf7ac330545f14ab9babddfdf0cb5df9e9ee69.zip
Simple (but insanly fast compared to CPU) fragment shader to draw mandelbrot set
Diffstat (limited to 'src/shader.c')
-rw-r--r--src/shader.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/shader.c b/src/shader.c
index 478c93b..0b4091d 100644
--- a/src/shader.c
+++ b/src/shader.c
@@ -24,9 +24,33 @@ bool shader_init(Shader *shader)
GL_CALL(glValidateProgram(shader->id));
GL_CALL(glDeleteShader(shader_vert));
GL_CALL(glDeleteShader(shader_frag));
+
+ GL_CALL(shader->location.width = glGetUniformLocation(shader->id, "u_width"));
+ GL_CALL(shader->location.height = glGetUniformLocation(shader->id, "u_height"));
+
+ GL_CALL(shader->location.real_start = glGetUniformLocation(shader->id, "u_real_start"));
+ GL_CALL(shader->location.real_end = glGetUniformLocation(shader->id, "u_real_end"));
+ GL_CALL(shader->location.imag_start = glGetUniformLocation(shader->id, "u_imag_start"));
+ GL_CALL(shader->location.imag_end = glGetUniformLocation(shader->id, "u_imag_end"));
+
+ GL_CALL(shader->location.iterations = glGetUniformLocation(shader->id, "u_iterations"));
+
return (true);
}
+void shader_set_uniforms(Shader *shader, State *state)
+{
+ GL_CALL(glUniform1i(shader->location.width, state->width));
+ GL_CALL(glUniform1i(shader->location.height, state->height));
+
+ GL_CALL(glUniform1f(shader->location.real_start, state->real_start));
+ GL_CALL(glUniform1f(shader->location.real_end, state->real_end));
+ GL_CALL(glUniform1f(shader->location.imag_start, state->imag_start));
+ GL_CALL(glUniform1f(shader->location.imag_end, state->imag_end));
+
+ GL_CALL(glUniform1i(shader->location.iterations, state->iterations));
+}
+
static unsigned int st_compile(char *filepath, unsigned int type)
{
unsigned int id;