PDA

View Full Version : FBO,MRT and multisampling



wlb2010f
08-24-2010, 03:12 AM
Hi there:
I have 2 problem with fbo;
1:
I bound 4 textures to 1 fbo with
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_fbo.tId[i], 0);
4 textures are diffrent size. 512 * 512, 256 * 256, 128 * 128 and 64 * 64
after I rendered secen,only the smallest size texture is correct, and all the others only update part of image(which equal to 64 * 64 at lower- left corner),is that means FBO MRT doesn't support different target size?

2:
I created 2 fbos, one use glRenderbufferStorageMultisample to get multisampling working,and after rendered secen, i use glBlitFramebufferEXT(0, 0,w1, h1, 0, 0, w2, h2, GL_COLOR_BUFFER_BIT, GL_NEAREST) to render fbo1 to fbo2's texture;
if w1 == w2 && h1 == h2, witch means fbo2's size same as fbo1's render storage, it works ,otherwise i get a black image.
so my quesstion is : does it have to be same size when blit from a multisampled fbo to other texture binded fbo?

Thanks for your helps

trinitrotoluene
08-24-2010, 05:44 AM
When you blit a multisampled fbo, the source and the destination must have the same dimension. If not, a GL_INVALID_OPERATION is generated. So the answer of your question is yes. See the glBlitFramebuffer (http://www.opengl.org/sdk/docs/man4/xhtml/glBlitFramebuffer.xml) documentation at the end.

wlb2010f
08-24-2010, 08:59 AM
Thanks for your reply trinitoluene.
According to the answer, it seems that it isn't possible to get downsampled(and also multisampled) secen image in one path. Then only 2 choicese left.
1. gen a MS supported FBO with full screen size, blit to an equal size texture bind fbo, then generate 4 fbos and render quads for each one to get downsampled images.
2. almost same as above, but just use blit to get 4 texture binded fbos.(I should be able to use blit here,because the new fbo's include the full screen one isn't MSed anymore)
Which one should be faster?, because I have tried it on my project, I didn't see much FPS diffrence.
Btw, is there any other faster way to do this?
Tanks for your helps!

trinitrotoluene
08-24-2010, 04:37 PM
I don't know if it is possible to do that. Suppose we have 2 FBO. The first FBO is multisample and the second is a FBO with a mipmap texture attached. Limit the base and max level of your mipmap. The mipmap texture have level 0 attached to color attachment 0, level 1 to color attachment 1 ... level 3 to color attachment 3. First resolve (blit) your multisampled FBO with the mipmap texture at level 0 which must have the same size. Then blit the level 0 in level 1, level 0 in level 2, level 0 in level 3. The problem is that I never tested to blit a FBO with the same id for the read and the write target but with different color attachment for read and write buffer. So maybe you can try this:



//resolve the multisample framebuffer and generate level 0
glBindFramebuffer(GL_READ_FRAMEBUFFER,fbo_multisam ple);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fbo_mipmap);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0,0,
512,512,
0,0,
512,512,
GL_COLOR_ATTACMENT,GL_NEAREST);

//Blit to generate level 1
glBindFramebuffer(GL_READ_FRAMEBUFFER,fbo_mipmap);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fbo_mipmap);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0,0,
512,512,
0,0,
256,256,
GL_COLOR_ATTACMENT,GL_LINEAR);

//Blit to generate level 2


glDrawBuffer(GL_COLOR_ATTACHMENT2);
glBlitFramebuffer(0,0,
512,512,
0,0,
128,128,
GL_COLOR_ATTACMENT,GL_LINEAR);

//Blit to generate level 3

glDrawBuffer(GL_COLOR_ATTACHMENT3);
glBlitFramebuffer(0,0,
512,512,
0,0,
64,64,
GL_COLOR_ATTACMENT,GL_LINEAR);

wlb2010f
08-25-2010, 12:41 AM
Thank you trinitrotoluene
I will try this method. And it seems that you recomand blit rather than draw quad. Also this method should be almost equvalent as the method I metioned above except I gen 4 fbos and you only use one. And fbo itself doesn'y have storage, so it doesn't save memory either.
Am I right?

trinitrotoluene
08-25-2010, 06:36 AM
And it seems that you recommend blit rather than draw quad I don't know if I understand you well, but you must do the 4 framebuffer blit to texture first, then use the generated texture data on a quad or any other surface that have the right texture coordinates set.


Also this method should be almost equvalent as the method I metioned above except I gen 4 fbos and you only use one. And fbo itself doesn'y have storage, so it doesn't save memory either. Am I right? Yes, I was suggesting this method only because your 4 textures size is a sub set of a mipmap texture of size 512x512.

BionicBytes
08-26-2010, 01:35 AM
ARB Framebuffer spec does say it supports attachments of different sizes (does not generate incomplete FBO) - but actually using those different sizes - thats a different story!

Also the spec is carefully worded with regard to BlitFrameBuffer, The SRC and DST FBOs do not have to always be the same size - depending on the operation. Colour attchments can be different sizes and will be stretched if GL_LINEAR is specified. If GL_NEAREST is used - no copy is performed.
For Depth/Stencil operations you must use GL_NEAREST and this means the W and H must be the same.