Switching attached texture on Framebuffer objects

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…

I don’t use OpenGl ES but the same principlce should apply.
I’d create a FBO with two attachments (same dimensions). To select which attachment is rendered to I’d use glReadBuffer and glDrawBuffer to select GL_COLOR_ATTACHMENT0 or GL_COLOR_ATTACHMENT1 as appropriate.
I have found this is both the fastest and most convienient way of selecting different attachments within an FBO.

Thank you for your reply. Unfortunately, I don’t think there is more than one GL_COLOR_ATTACHMENT on my openGl es implementation.
GL_MAX_COLOR_ATTACHMENTS_OES is not even defined, and neither is GL_COLOR_ATTACHMENT1_OES… (but GL_COLOR_ATTACHMENT0_OES is)