mightymandel v16

GPU-based Mandelbrot set explorer

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