PDA

View Full Version : Transform feedback crashes



Rakehell
06-22-2016, 01:55 PM
const GLchar* vertexShaderSrc = "in float inValue; out float outValue; void main() { outValue = sqrt(inValue); } );";

GLuint shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader, 1, &vertexShaderSrc, 0);
glCompileShader(shader);

GLuint program = glCreateProgram();
glAttachShader(program, shader);

const GLchar* feedbackVaryings[] = { "outValue" };
glTransformFeedbackVaryings(program, 1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);

glLinkProgram(program);
glUseProgram(program);

GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

GLfloat data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };

GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);

GLint inputAttrib = glGetAttribLocation(program, "inValue");
glEnableVertexAttribArray(inputAttrib);
glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);

GLuint tbo;
glGenBuffers(1, &tbo);
glBindBuffer(GL_ARRAY_BUFFER, tbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), 0, GL_STATIC_READ);

glEnable(GL_RASTERIZER_DISCARD);

glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo);

glBeginTransformFeedback(GL_POINTS);

glDrawArrays(GL_POINTS, 0, 5);

glEndTransformFeedback();

glFlush();

GLfloat *feedback;


feedback = glMapBufferRange(GL_ARRAY_BUFFER, 0, sizeof(feedback), GL_MAP_READ_BIT);

NSLog(@"%f %f %f %f %f\n", feedback[0], feedback[1], feedback[2], feedback[3], feedback[4]);




The problem is that glMapBufferRange returns a null pointer. How can I successfully compute using transform feedback?

arekkusu
06-24-2016, 10:34 AM
There is an extra ); at the end of your shader which will fail compilation, and link, and draw. Checking for errors or compiler logs would catch this.

Otherwise, your code works as expected here on OSX 10.9.5 in a GL4.1 context: "1.000000 1.414214 1.732051 2.000000 2.236068"