Shader uniform samplers:
uniform sampler2D u_texture;
uniform samplerBuffer u_lights;
Somewhere in shader program code I link the shader program, use it, bind my texture used for rendering textures to texture unit 1, bind my light texture buffer sampler to texture unit 2 and validate the shader:
link();
use();
GL20.glUniform1i(getUniformLocation("u_texture"), 1);
GL20.glUniform1i(getUniformLocation("u_lights"), 2);
validate();
Create texture buffer and buffer object:
textureBuffer = GL11.glGenTextures();
lightBuffer = GL15.glGenBuffers();
Here is where I deal with texture buffer data:
GL15.glBindBuffer(GL31.GL_TEXTURE_BUFFER, lightBuffer);
FloatBuffer lightData=makeLightData();
GL15.glBufferData(GL31.GL_TEXTURE_BUFFER, lightData, GL15.GL_STREAM_DRAW);
GL13.glActiveTexture(GL13.GL_TEXTURE2); // activate texture unit 2, which is sampler 'u_lights'
GL11.glBindTexture(GL31.GL_TEXTURE_BUFFER, textureBuffer);
GL31.glTexBuffer(GL31.GL_TEXTURE_BUFFER, ARBTextureRg.GL_R32F, lightBuffer); // R32F big floats
GL11.glBindTexture(GL31.GL_TEXTURE_BUFFER, 0);
GL15.glBindBuffer(GL31.GL_TEXTURE_BUFFER, 0);
GL13.glActiveTexture(GL13.GL_TEXTURE1); // activate my default texture unit
Here is my FloatBuffer creation method:
private FloatBuffer makeLightData() {
FloatBuffer buffer = BufferUtils.createFloatBuffer(1);
buffer.put(1);
buffer.flip();
return buffer;
}
Here is somewhere in my fragment shader where I render the scene. The problem is that the scene turns out black. Should be white. If I swap texelFetch() with 1.0, the scene turns out white.
lighting.rgb+=texelFetch(u_lights, 0).r;