PDA

View Full Version : Switching attached texture on Framebuffer objects



Rafael_Fareal
10-01-2010, 01:30 PM
Hi,

I'm trying to apply multiple filters on an image. I create a texture from my image, and then I work with that texture. As I want to combine filters, I create a frame buffer object, attach a new empty texture to it, draw into that buffer (and texture) and then bind that new texture to my current context, to apply the second filter. I cannot bind the same texture as the one attached to the FBO (said in the specs), so I was trying to attach another new texture to my FBO. But when I do that, the first texture I drew into seems empty!

My alternative is to use two different FBOs and to switch from one to the other, but I read there is a performance cost when binding FBOs and swapping attached texture was much more efficient.

Can someone take a look at my code ? I'm new to opengl I could simply be missing something obvious.



glBindFramebufferOES(GL_FRAMEBUFFER_OES, my_fbo);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, first_texture, 0); // the texture I'll draw into
rt_assert(GL_FRAMEBUFFER_COMPLETE_OES == glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));

glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, input_texture); // my original image


draw_first_filter();

glBindTexture(GL_TEXTURE_2D, first_texture); // this texture should now be filled up with my drawings

// change attached texture to second_texture :
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, second_texture, 0);
rt_assert(GL_FRAMEBUFFER_COMPLETE_OES == glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));

draw_second_filter();

// now go back to the main FBO :
glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, second_texture);

draw_one_last_filter(); // on screen



Curiously, it works almost fine except that my first filter seems to have never been applied ! It's as if I applied directly the second_filter on the input_texture...