mightymandel v16

GPU-based Mandelbrot set explorer

fp32_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 "fp32_escaped.h"
9 #include "shader.h"
10 #include "logging.h"
11 
12 extern const char *fp32_escaped_vert;
13 extern const char *fp32_escaped_geom;
14 extern const char *fp32_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  glGenVertexArrays(1, &s->vao);D;
26 }
27 
28 void fp32_escaped_end(struct fp32_escaped *s) {
29  glDeleteProgram(s->program);D;
30  glDeleteVertexArrays(1, &s->vao);D;
31 }
32 
33 void fp32_escaped_start(struct fp32_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  double centerx = mpfr_get_d(centerx0, MPFR_RNDN);
35  double centery = mpfr_get_d(centery0, MPFR_RNDN);
36  double radius = mpfr_get_d(radius0, MPFR_RNDN);
37  double aspect = width / (double) height;
38  glBindFramebuffer(GL_FRAMEBUFFER, fbo);D;
39  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);D;
40  GLenum buffers[1] = { GL_COLOR_ATTACHMENT0 };
41  glDrawBuffers(1, buffers);D;
42  glBindVertexArray(s->vao);D;
43  glBindBuffer(GL_ARRAY_BUFFER, vbo);D;
44  glUseProgram(s->program);D;
45  glUniform1f(s->loger2, log(escaperadius2));D;
46  glUniform2f(s->center, centerx, centery);D;
47  glUniform1f(s->radius, radius);D;
48  glUniform1f(s->aspect, 1 / aspect);D;
49  glUniform1f(s->pxs, height / (2.0 * radius));D;
50  glEnableVertexAttribArray(s->cne0);D;
51  glEnableVertexAttribArray(s->zdz0);D;
52  glVertexAttribPointer(s->cne0, 4, GL_FLOAT, GL_FALSE, (DE ? 8 : 6) * sizeof(GLfloat), 0);D;
53  glVertexAttribPointer(s->zdz0, DE ? 4 : 2, GL_FLOAT, GL_FALSE, (DE ? 8 : 6) * sizeof(GLfloat), ((GLbyte *)0)+(4*sizeof(GLfloat)));D;
54  glBindVertexArray(0);D;
55  glBindBuffer(GL_ARRAY_BUFFER, 0);D;
56  glBindFramebuffer(GL_FRAMEBUFFER, 0);D;
57  debug_message("VBO escaped: %d -> ?\n", vbo);
58 }
59 
60 void fp32_escaped_do(struct fp32_escaped *s, GLuint active_count) {
61  glUseProgram(s->program);D;
62  glBindVertexArray(s->vao);D;
63  glDrawArrays(GL_POINTS, 0, active_count);D;
64  glBindVertexArray(0);D;
65  glUseProgram(0);D;
66  debug_message("VBO escaped: ? -> frag\n");
67 }