我试图使用变换反馈从顶点着色器中检索数据以进行调试,因为我的透视矩阵似乎计算错误。我在变换反馈缓冲区中什么也没有。谁能帮我弄清楚我做错了哪一步?
以下是我设置转换反馈的代码片段:
//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 retreived in shader
float dateFromShader[16];//receive the data from shader
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);
我的顶点着色器是这样的:
#version 420
layout(location = 0) in vec4 position;
uniform mat4 perspectiveMatrix;
out mat4 retrieve;
void main()
{
gl_Position = perspectiveMatrix * position;
retrieve = perspectiveMatrix;
}