• Advertisement
Sign in to follow this  

how to use opengl transform feedback, I always get 0 in the buffers

This topic is 1877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm a beginner in OpenGL, I was trying to use transform feedback to retrieve data from vertex shader for debugging as my perspective matrix seemed to be miscalculated. But after all efforts I did, I still got nothing in the transform feedback buffer. Can anyone help me figure out which step I did wrong? Thanks in advance!
Following is snippet of my code of setting up transform feedback:
[CODE]
//vertex to be passed into shader
const float vertexPos[] =
{
0.75f, 0.75f, 0.0f, 1.0f,
0.75f, -0.75f, 0.0f, 1.0f,
-0.75f, -0.75f, 0.0f, 1.0f
};

//set up transform feedback
const char *variableName = "retrieve";//the variable to be retrieved in vertex shader
float dateFromShader[16];//for receive the retrieved data
GLuint tf_bo;// transform feedback buffer id

glTransformFeedbackVaryings(shaderProgram, 1, &variableName, GL_INTERLEAVED_ATTRIBS);
glLinkProgram(shaderProgram);

glGenBuffers(1, &tf_bo);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tf_bo);// Is this necessary to call glBindBuffer before glBindBufferBase?
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tf_bo);
glBufferDate(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(float) * 16, NULL, GL_DYNAMIC_COPY);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);

//retrieve data from vertex shader
glEnable(GL_RASTERIZER_DICARD);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tf_bo);
glBeginTransformFeedback(GL_TRIANGLES);
glDrawArrays(GL_TRIANGLES, 0, 3);//
glEndTransformFeedback();

glBindBuffer(GL_ARRAY_BUFFER, tf_bo);
glGetBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * 16, dataFromShader);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisable(GL_RASTERIZER_DISCARD);
[/CODE]
and my vertex shader is like this:
[CODE]
#version 420

layout(location = 0) in vec4 position;


uniform mat4 perspectiveMatrix;
out mat4 retrieve;

void main()
{
gl_Position = perspectiveMatrix * position;

retrieve = perspectiveMatrix;
}
[/CODE] Edited by sobeit

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement