mightymandel v16

GPU-based Mandelbrot set explorer

fpxx_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 "fpxx_init.h"
8 #include "shader.h"
9 #include "logging.h"
10 #include "mightymandel.h"
11 
12 extern const char *fpxx_init_vert;
13 extern const char *fpxx_init_geom;
14 extern const char *fpxx_init_frag;
15 const GLchar *fpxx_init_varyings[] = {"cne", "zdz", "err"};
16 
17 void fpxx_init_begin(struct fpxx_init *s) {
19  s->radius = glGetUniformLocation(s->program, "radius");
20  s->center = glGetUniformLocation(s->program, "center");
21  s->aspect = glGetUniformLocation(s->program, "aspect");
22  s->pass = glGetUniformLocation(s->program, "pass");
23  s->c = glGetAttribLocation(s->program, "c");
24  glGenVertexArrays(1, &s->vao);
25 }
26 
27 void fpxx_init_end(struct fpxx_init *s) {
28  glDeleteVertexArrays(1, &s->vao);
29  glDeleteProgram(s->program);
30 }
31 
32 void fpxx_init_do(struct fpxx_init *s, GLuint *active_count, GLuint *vbo, GLuint query, int pass, int width, int height, const mpfr_t centerx, const mpfr_t centery, const mpfr_t radius, const mpfr_t refx, const mpfr_t refy) {
33  mpfr_t dx, dy;
34  mpfr_inits2(mpfr_get_prec(refx), dx, dy, (mpfr_ptr) 0);
35  mpfr_sub(dx, centerx, refx, MPFR_RNDN);
36  mpfr_sub(dy, centery, refy, MPFR_RNDN);
37  debug_message("init dx: %Re\n", dx);
38  debug_message("init dy: %Re\n", dy);
39  *active_count = width * height;
40  glBindVertexArray(s->vao);D;
41  glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);D;
42  glUseProgram(s->program);D;
43  glUniform1i(s->pass, pass);D;
44  glUniform1d(s->radius, mpfr_get_d(radius, MPFR_RNDN));D;
45  glUniform2d(s->center, mpfr_get_d(dx, MPFR_RNDN), mpfr_get_d(dy, MPFR_RNDN));D;
46  glUniform1d(s->aspect, height / (double) width);D;
47  glVertexAttribPointer(s->c, 4, GL_FLOAT, GL_FALSE, 0, 0);D;
48  glEnableVertexAttribArray(s->c);D;
49  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbo[1]);D;
50  glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);D;
51  glBeginTransformFeedback(GL_POINTS);D;
52  glDrawArrays(GL_POINTS, 0, *active_count);D;
53  glEndTransformFeedback();D;
54  glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);D;
55  int before = *active_count;
56  glGetQueryObjectuiv(query, GL_QUERY_RESULT, active_count);D;
57  int after = *active_count;
58  debug_message("init active_count: %d -> %d\n", before, after);
59  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);D;
60  glUseProgram(0);D;
61  glBindBuffer(GL_ARRAY_BUFFER, 0);D;
62  glBindVertexArray(0);
63  mpfr_clears(dx, dy, (mpfr_ptr) 0);
64  debug_message("VBO init: %d -> %d\n", vbo[0], vbo[1]);
65 }