我目前正试图让变换反馈运行,但事实并非如此。我正在使用OpenGL 3.3并按照this教程中的步骤将其转换为Java和LWJGL。
着色器代码:
#version 330 core
in float inValue;
out float outValue;
void main(){
outValue = sqrt(inValue);
}
着色器类代码:
... loading shaders, uniforms, attribute locations etc. ...
public void setTransformFeedbackVaryings(String[] varyings, boolean interleaved){
int bufferMode = interleaved ? GL_INTERLEAVED_ATTRIBS : GL_SEPERATE_ATTRIBS;
glTransformFeedbackVaryings(programID, varyings, bufferMode);
}
public void compile(){
glLinkProgram(programID);
glValidateProgram(programID);
... //error catching
}
其他:
...
//sets the list of feedback varyings names with GL_INTERLEAVED_ATTRIBS
shader.setTransformFeedbackVaryings(new String[]{"outValue"}, true);
//linking and validating shader
shader.compile();
attribLocation = shader.getAttribLocation("inValue");
//create VAO
VAO = glGenVertexArrays();
glBindVertexArrayObject(VAO);
//create data buffer
FloatBuffer buffer = ... //contains the values to be send to the shader
//create VBO
VBO = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
glEnableVertexAttribArray(attribLocation);
glVertexAttribPointer(attribLocation, 1, GL_FLOAT, false, 0, 0);
//create test buffer
FloatBuffer test = ... //some values
//create transform feedback buffer
TBO = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, TBO);
glBufferData(GL_ARRAY_BUFFER, test, GL_STATIC_READ);
//perform feedback
glEnable(GL_RASTERIZER_DISCARD);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, TBO);
glBeginTransformFeedBack(GL_POINTS);
glDrawArrays(GL_POINTS, 0, NUM_VALUES);
glEndTransformFeedback();
glDisable(GL_RASTERIZER_DISCARD);
glFlush();
//read data
FloatBuffer feedback = ... //empty buffer
glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, feedback);
我从反馈缓冲区获得的值是来自测试缓冲区的值。因此,编写和读取缓冲区似乎有效。当省略测试缓冲区并将空的加载到TBO
时,结果都是0.我在使用{{1}时尝试用GL_ARRAY_BUFFER
替换GL_TRANSFORM_FEEDBACK_BUFFER
当我阅读here但它也没有用。
我没有得到任何OpenGL错误。