Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 sobeit   Members   -  Reputation: 440

Like
0Likes
Like

Posted 29 November 2012 - 06:47 AM

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:
//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);
and my vertex shader is like this:
#version 420

layout(location = 0) in vec4 position;


uniform mat4 perspectiveMatrix;
out mat4 retrieve;

void main()
{
gl_Position = perspectiveMatrix * position;

retrieve = perspectiveMatrix;
}

Edited by sobeit, 29 November 2012 - 09:12 AM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS