EDIT: I simply forgot to bind the shader. Now it's working.
I am currently trying to get transform feedback to run but it doesn't. I am using OpenGL 3.3 and followed the steps from this tutorial converting it to Java and LWJGL.
Shader code:
#version 330 core
in float inValue;
out float outValue;
void main(){
outValue = sqrt(inValue);
}
Shader class code:
... 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
}
Other:
...
//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);
The values I get from the feedback buffer are those from the test buffer. Hence writing and reading the buffers seems to work. When leaving out the test buffer and loading an empty one to the TBO
the results are all 0.
I tried replacing the GL_ARRAY_BUFFER
with GL_TRANSFORM_FEEDBACK_BUFFER
when using the TBO
as I read here but it didn't work either.
I don't get any OpenGL Errors btw.