mightymandel v16

GPU-based Mandelbrot set explorer

fpxx_unescaped.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 "fpxx_unescaped.h"
6 #include "shader.h"
7 #include "logging.h"
8 
9 extern const char *fpxx_unescaped_vert;
10 extern const char *fpxx_unescaped_geom;
11 const GLchar *fpxx_unescaped_varyings[] = {"cne", "zdz", "err"};
12 
15  s->cne0 = glGetAttribLocation(s->program, "cne0");D;
16  s->zdz0 = glGetAttribLocation(s->program, "zdz0");D;
17  s->err0 = glGetAttribLocation(s->program, "err0");D;
18  glGenVertexArrays(1, &s->vao);D;
19 }
20 
22  glDeleteProgram(s->program);D;
23  s->program = 0;
24  glDeleteVertexArrays(1, &s->vao);D;
25  s->vao = 0;
26 }
27 
28 void fpxx_unescaped_start(struct fpxx_unescaped *s, GLuint vbo) {
29  glBindVertexArray(s->vao);D;
30  glBindBuffer(GL_ARRAY_BUFFER, vbo);D;
31  glVertexAttribLPointer(s->cne0, 4, GL_DOUBLE, (DE ? 9 : 7) * sizeof(GLdouble), 0);D;
32  glVertexAttribLPointer(s->zdz0, DE ? 4 : 2, GL_DOUBLE, (DE ? 9 : 7) * sizeof(GLdouble), ((GLbyte *)0)+(4*sizeof(GLdouble)));D;
33  glVertexAttribLPointer(s->err0, 1, GL_DOUBLE, (DE ? 9 : 7) * sizeof(GLdouble), ((GLbyte *)0)+((DE ? 8 : 6)*sizeof(GLdouble)));D;
34  glEnableVertexAttribArray(s->cne0);D;
35  glEnableVertexAttribArray(s->zdz0);D;
36  glEnableVertexAttribArray(s->err0);D;
37  glBindBuffer(GL_ARRAY_BUFFER, 0);D;
38  glBindVertexArray(0);D;
39  debug_message("VBO unescaped: %d -> ?\n", vbo);
40 }
41 
42 void fpxx_unescaped_do(struct fpxx_unescaped *s, GLuint *unescaped, GLuint active_count, GLuint vbo, GLuint query) {
43  glBindVertexArray(s->vao);D;
44  glUseProgram(s->program);D;
45  glEnable(GL_RASTERIZER_DISCARD);D;
46  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbo);D;
47  glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);D;
48  glBeginTransformFeedback(GL_POINTS);D;
49  glDrawArrays(GL_POINTS, 0, active_count);D;
50  glEndTransformFeedback();D;
51  glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);D;
52  int before = active_count;
53  glGetQueryObjectuiv(query, GL_QUERY_RESULT, unescaped);D;
54  int after = *unescaped;
55  debug_message("unescaped active_count: %d -> %d\n", before, after);
56  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);D;
57  glDisable(GL_RASTERIZER_DISCARD);D;
58  glUseProgram(0);D;
59  glBindVertexArray(0);D;
60  debug_message("VBO unescaped: ? -> %d\n", vbo);
61 }