I've implemented some postprocessing effects (DOF, HDR, Bloom) into my engine. I've tested it on AMD card which supports OpenGL 4.2. Yesterday I've made a test on NVidia card which supports only OpenGL 3.3. I tried to write my code to works also in OpenGL 3.3 but I was suprised when I saw something like on the screen:
It seems that textures are filled with random values and never change during app life (only when I'm changing dimensions of textures so basically recreate them). It happens mostly when I want downscale texture to some size (I use 2 textures to do that and a shader). Here is some examples of my code which implements Bloom effect:
Creating framebuffer:
if (!_p_buffer)glGenFramebuffers(1, &_p_buffer); // generate postprocess buffer
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _p_buffer);
for (int i = 0; i < 2; i++){
_lens[i].create(x / D.lensDownsample(), y / D.lensDownsample(), 0, IMAGE_16F_3, IMAGE_2D, true, FILTER_LINEAR); // create Lens Flare texture (with half resolution)
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2 + i, GL_TEXTURE_2D, _lens[i].get(), 0);
}
Render-to-texture:
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _p_buffer);
// first downsample image
glDrawBuffer(GL_COLOR_ATTACHMENT2);
glClear(GL_COLOR_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
_aux[_aux_number].lock();
Shaders["ScaleBias"].set(true);
Shaders["ScaleBias"].set("scale", Vector4(1.2f));
Shaders["ScaleBias"].set("bias", Vector4(-0.4));
Shaders["ScaleBias"].set("texelSize", Vector2(1 / (float)D.x() * D.lensDownsample(), 1 / (float)D.y() * (float)D.lensDownsample()));
glViewport(0, 0, D.x() / D.lensDownsample(), D.y() / D.lensDownsample());
Quad();
ScaleBias shader:
void main() {
FragColor = max(vec4(0.0), texture(col, gl_FragCoord.xy*texelSize) + bias) * scale;
}
What "create" method actually does here:
if(!_image)glGenTextures(1, &_image);
glBindTexture(GL_TEXTURE_2D, _image);
glTexParameteri(_gl_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(_gl_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(_gl_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(_gl_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(_gl_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, x, y, 0, GL_RGB,GL_FLOAT, NULL);
I used debug extension to check if there is any invalid parameters but debuging shows nothing interesting. I tried make G-Buffer textures as GL_FLOAT but they works ok. I tried make shader as simple as possible (return color texture) but error still was valid. I've observed similar problem on newer NVidia cards but the only difference was that textures are clear (black). But they still didn't update. Framebuffer doesn't output any errors.
Could you point me out the cause of this bug or give some clue?