mightymandel v16

GPU-based Mandelbrot set explorer

fp32_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 "fp32_unescaped.h"
6 #include "shader.h"
7 #include "logging.h"
8 
9 extern const char *fp32_unescaped_vert;
10 extern const char *fp32_unescaped_geom;
11 const GLchar *fp32_unescaped_varyings[] = {"cne", "zdz"};
12 
15  s->cne0 = glGetAttribLocation(s->program, "cne0");D;
16  s->zdz0 = glGetAttribLocation(s->program, "zdz0");D;
17  glGenVertexArrays(1, &s->vao);D;
18 }
19 
21  glDeleteProgram(s->program);D;
22  glDeleteVertexArrays(1, &s->vao);D;
23 }
24 
25 void fp32_unescaped_start(struct fp32_unescaped *s, GLuint vbo) {
26  glBindVertexArray(s->vao);D;
27  glBindBuffer(GL_ARRAY_BUFFER, vbo);D;
28  glEnableVertexAttribArray(s->cne0);D;
29  glEnableVertexAttribArray(s->zdz0);D;
30  glVertexAttribPointer(s->cne0, 4, GL_FLOAT, GL_FALSE, (DE ? 8 : 6) * sizeof(GLfloat), 0);D;
31  glVertexAttribPointer(s->zdz0, DE ? 4 : 2, GL_FLOAT, GL_FALSE, (DE ? 8 : 6) * sizeof(GLfloat), ((GLbyte *)0)+(4*sizeof(GLfloat)));D;
32  glBindBuffer(GL_ARRAY_BUFFER, 0);D;
33  glBindVertexArray(0);D;
34  debug_message("VBO unescaped: %d -> ?\n", vbo);
35 }
36 
37 void fp32_unescaped_do(struct fp32_unescaped *s, GLuint *unescaped, GLuint active_count, GLuint vbo, GLuint query) {
38  glBindVertexArray(s->vao);D;
39  glUseProgram(s->program);D;
40  glEnable(GL_RASTERIZER_DISCARD);D;
41  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbo);D;
42  glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);D;
43  glBeginTransformFeedback(GL_POINTS);D;
44  glDrawArrays(GL_POINTS, 0, active_count);D;
45  glEndTransformFeedback();D;
46  glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);D;
47  glGetQueryObjectuiv(query, GL_QUERY_RESULT, unescaped);D;
48  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);D;
49  glDisable(GL_RASTERIZER_DISCARD);D;
50  glUseProgram(0);D;
51  glBindVertexArray(0);D;
52  debug_message("VBO unescaped: ? -> %d\n", vbo);
53 }