mightymandel v16

GPU-based Mandelbrot set explorer

fp32_init.c
Go to the documentation of this file.
1 // mightymandel -- GPU-based Mandelbrot Set explorer
2 // Copyright (C) 2012,2013,2014,2015 Claude Heiland-Allen
3 // License GPL3+ http://www.gnu.org/licenses/gpl.html
4 
5 #include <stdio.h>
6 
7 #include "fp32_init.h"
8 #include "shader.h"
9 #include "logging.h"
10 
11 extern const char *fp32_init_vert;
12 const GLchar *fp32_init_varyings[] = {"cne", "zdz"};
13 
14 void fp32_init_begin(struct fp32_init *s) {
15  s->program = compile_program_tf("fp32_init", fp32_init_vert, 0, 0, 2, fp32_init_varyings);
16  s->radius = glGetUniformLocation(s->program, "radius");D;
17  s->center = glGetUniformLocation(s->program, "center");D;
18  s->c = glGetAttribLocation(s->program, "c");D;
19  glGenVertexArrays(1, &s->vao);D;
20 }
21 
22 void fp32_init_end(struct fp32_init *s) {
23  glDeleteProgram(s->program);D;
24  glDeleteVertexArrays(1, &s->vao);D;
25 }
26 
27 void fp32_init_do(struct fp32_init *s, GLuint *active_count, GLuint *vbo, GLuint query, int width, int height, const mpfr_t centerx, const mpfr_t centery, const mpfr_t radius) {
28  *active_count = width * height;
29  glEnable(GL_RASTERIZER_DISCARD);D;
30  glBindVertexArray(s->vao);D;
31  glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);D;
32  glUseProgram(s->program);D;
33  glUniform1f(s->radius, mpfr_get_d(radius, MPFR_RNDN));D;
34  glUniform2f(s->center, mpfr_get_d(centerx, MPFR_RNDN), mpfr_get_d(centery, MPFR_RNDN));D;
35  glVertexAttribPointer(s->c, 4, GL_FLOAT, GL_FALSE, 0, 0);D;
36  glEnableVertexAttribArray(s->c);D;
37  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbo[0]);D;
38  glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);D;
39  glBeginTransformFeedback(GL_POINTS);D;
40  glDrawArrays(GL_POINTS, 0, *active_count);D;
41  glEndTransformFeedback();D;
42  glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);D;
43  glGetQueryObjectuiv(query, GL_QUERY_RESULT, active_count);D;
44  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);D;
45  glUseProgram(0);D;
46  glBindBuffer(GL_ARRAY_BUFFER, 0);D;
47  glBindVertexArray(0);D;
48  glDisable(GL_RASTERIZER_DISCARD);D;
49  debug_message("VBO init: %d -> %d\n", vbo[1], vbo[0]);
50 }