mightymandel v16

GPU-based Mandelbrot set explorer

fpxx_escaped.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 <math.h>
6 #include <stdio.h>
7 
8 #include "fpxx_escaped.h"
9 #include "shader.h"
10 #include "logging.h"
11 
12 extern const char *fpxx_escaped_vert;
13 extern const char *fpxx_escaped_geom;
14 extern const char *fpxx_escaped_frag;
15 
18  s->center = glGetUniformLocation(s->program, "center");D;
19  s->radius = glGetUniformLocation(s->program, "radius");D;
20  s->aspect = glGetUniformLocation(s->program, "aspect");D;
21  s->loger2 = glGetUniformLocation(s->program, "loger2");D;
22  s->pxs = glGetUniformLocation(s->program, "pxs");D;
23  s->cne0 = glGetAttribLocation(s->program, "cne0");D;
24  s->zdz0 = glGetAttribLocation(s->program, "zdz0");D;
25  s->err0 = glGetAttribLocation(s->program, "err0");D;
26  glGenVertexArrays(1, &s->vao);D;
27 }
28 
29 void fpxx_escaped_end(struct fpxx_escaped *s) {
30  glDeleteProgram(s->program);D;
31  glDeleteVertexArrays(1, &s->vao);D;
32 }
33 
34 void fpxx_escaped_start(struct fpxx_escaped *s, GLuint tex, GLuint fbo, GLuint vbo, double escaperadius2, int width, int height, const mpfr_t centerx0, const mpfr_t centery0, const mpfr_t radius0, const mpfr_t refx, const mpfr_t refy) {
35  // set up target framebuffer
36  glBindFramebuffer(GL_FRAMEBUFFER, fbo);D;
37  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);
38  GLenum buffers[1] = { GL_COLOR_ATTACHMENT0 };
39  glDrawBuffers(1, buffers);D;
40  glBindFramebuffer(GL_FRAMEBUFFER, 0);D;
41  // set up shader uniforms
42  glUseProgram(s->program);D;
43  mpfr_t dx, dy;
44  mpfr_inits2(mpfr_get_prec(refx), dx, dy, (mpfr_ptr) 0);
45  mpfr_sub(dx, centerx0, refx, MPFR_RNDN);
46  mpfr_sub(dy, centery0, refy, MPFR_RNDN);
47  debug_message("escaped dx: %Re\n", dx);
48  debug_message("escaped dy: %Re\n", dy);
49  double centerx = mpfr_get_d(dx, MPFR_RNDN);
50  double centery = mpfr_get_d(dy, MPFR_RNDN);
51  double radius = mpfr_get_d(radius0, MPFR_RNDN);
52  double pxs = height / (2.0 * radius);
53  mpfr_clears(dx, dy, (mpfr_ptr) 0);
54  glUniform2d(s->center, centerx, centery);D;
55  glUniform1d(s->radius, radius);D;
56  glUniform1d(s->aspect, height / (double) width);D;
57  glUniform1d(s->loger2, log(escaperadius2));D;
58  glUniform1d(s->pxs, pxs);D;
59  glUseProgram(0);D;
60  // set up vertex pointers
61  glBindVertexArray(s->vao);D;
62  glBindBuffer(GL_ARRAY_BUFFER, vbo);D;
63  glVertexAttribLPointer(s->cne0, 4, GL_DOUBLE, (DE ? 9 : 7) * sizeof(GLdouble), 0);D;
64  glVertexAttribLPointer(s->zdz0, DE ? 4 : 2, GL_DOUBLE, (DE ? 9 : 7) * sizeof(GLdouble), ((GLbyte *)0)+(4*sizeof(GLdouble)));D;
65  glVertexAttribLPointer(s->err0, 1, GL_DOUBLE, (DE ? 9 : 7) * sizeof(GLdouble), ((GLbyte *)0)+((DE ? 8 : 6)*sizeof(GLdouble)));D;
66  glEnableVertexAttribArray(s->cne0);D;
67  glEnableVertexAttribArray(s->zdz0);D;
68  glEnableVertexAttribArray(s->err0);D;
69  glBindBuffer(GL_ARRAY_BUFFER, 0);D;
70  glBindVertexArray(0);D;
71  debug_message("VBO escaped: %d -> ?\n", vbo);
72 }
73 
74 void fpxx_escaped_do(struct fpxx_escaped *s, GLuint active_count) {
75  glUseProgram(s->program);D;
76  glBindVertexArray(s->vao);D;
77  glDrawArrays(GL_POINTS, 0, active_count);D;
78  debug_message("escaped active_count: %d\n", active_count);
79  glBindVertexArray(0);D;
80  glUseProgram(0);D;
81  debug_message("VBO escaped: ? -> frag\n");
82 }