Big problem!. share textures between FBOs

Hi,

I’m programming an APP using two FBOs
the first one cover some equal sized textures fbo1_tex[3], and the another one has a only one texture fbo2_tex
The issue is, I need update the fbo2_tex every frame using the current fbo1_tex[curr], and using it I need generate the next texture fbo1_tex[next]. Notice that, the textures in the fbo1 are swapped every frame.
tmp = curr;
curr = next;
next = tmp;

The problem is, I can’t read the fbo2_tex texture when I try to generate the fbo1_tex[next] (I’m doing it using a fs), but when i use glReadPixels binding the fbo2, the values come valid.

do somebody have any example or demo using two fbo and sharing their attached textures ?

Thanks in advance.

1 - A small piece of code shows what exactly you are doing when you bind your texture and fbo would be helpful i think.

2 - Did you try using only one fbo? I remember it is faster on most of the GL implementations if not all.

Hi,

What do you want to do when reading the fbo2_tex texture?

If you need to draw several textures in a fbo texture you can use multitexturing, but it depends on what operations you want to do…otherwise you can do this with shaders.

I guess the problem is because I’m using the fbo2 with depth and stencil buffer, and as said, the texture attached to fbo2
is well generated, I get their data using glReadBuffer(…) and the data becomes valid, but when I try to use this texture to update the texture fbo1_tex[next](attached into fbo1) this seems to have zero values.

See the code below
I’m using this code to update the next fbo1 textures


 // bind the fbo1
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1);      
      
      // Save the view port and set it to the size of the texture      
      glPushAttrib(GL_CURRENT_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT );
      
      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      glLoadIdentity();
      gluOrtho2D(0, fbo1_tex_w, 0, fbo1_tex_w);

      glMatrixMode(GL_MODELVIEW);
      glPushMatrix();
      glLoadIdentity();
      glViewport(0, 0, fbo1_tex_w, 0, fbo1_tex_w);	            

      glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
      
      glEnable(GL_TEXTURE_2D);
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, fbo1_tex[curr_id]);
      glActiveTexture(GL_TEXTURE1);
      glBindTexture(TEX_TARGET, grid_tex);           

      fbo1_shader.use(true);  

      // activate the textures to be used
      drawQuad(0.0, 0.0, fbo1_tex_w, 0, fbo1_tex_w);

and this code to generate the fbo2_tex (which uses depth buffer and stencil buffer)


// bind the fbo2
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2);

// Save the view port and set it to the size of the texture
glPushAttrib( GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);
     
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, fbo2_tex_w, 0, fbo2_tex_w, 200, -200);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glViewport(0, 0, fbo2_tex_w, fbo2_tex_w);

// draw into the associated texture
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

/*glEnable(TEX_TARGET);
glActiveTexture(GL_TEXTURE0);*/
glBindTexture(TEX_TARGET, fbo1_tex[curr_id]);

fbo2_shader.use(true);

glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

glColorMask(true, false, false, false);
glDepthFunc(GL_LESS);
drawVertices();

glEnable(GL_STENCIL_TEST);

glColorMask(false, true, false, false);
glClear(GL_STENCIL_BUFFER_BIT);
drawVertices();

glColorMask(false, false, true, false);
glClear(GL_STENCIL_BUFFER_BIT);
drawVertices();

glColorMask(true, true, true, true);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);

// Restore old view port
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();

fbo_shader2.use(false);

I do not think that the problem is in this code…Like I said before, you do not need to use glReadPixels. If you want to use the texture in fbo, just use it like usual opengl textures, bind it and draw it on a polygon.
You still did not say clearly what you want to do using the fbo1_tex data. If you want to copy an entire buffer in another just draw a polygon with the source texture mapped on it, in the destination buffer.

Maybe this could help you:

http://www.gamedev.net/reference/articles/article2331.asp
http://www.gamedev.net/reference/articles/article2333.asp

You should post more code especially concerning the texture attachements.