mightymandel v16

GPU-based Mandelbrot set explorer

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