PDA

View Full Version : FBO resolution problems



Nowhere-01
06-27-2011, 09:02 AM
Hey, could anyone explain why my secondary(used for shadows and reflections/refractions) FBO's behave such way:

If i use texture resolution greater than my application viewport height, then framebuffer's viewport is getting smaller(bigger fb texture resolution - smaller viewport) and screwed up.


For example: if my resolution is 1280x1024, everything works as it should if framebuffer texture size is less-equal to 1024 , no matter i use 128 or 256 or 1024. But if i make it 2048x2048 it screw up.

FBO TEXTURE SETUP:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
glBindTexture(GL_TEXTURE_2D, FB_TEX[3]);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, Shadow_Size, Shadow_Size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);[/QUOTE]</div>

FBO SETUP:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FB_ID[3]);


glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, FB_TEX[3], 0);

CheckFBO(3);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);[/QUOTE]</div>

RENDER:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FB_ID[3]);
glClear(GL_DEPTH_BUFFER_BIT);

glPushMatrix();
ChangeSize(Shadow_Size, Shadow_Size, 90);

gluLookAt(Lights[0].Position_x2[0], Lights[0].Position_x2[1], Lights[0].Position_x2[2], Lights[0].Position_x2[0] - 1, Lights[0].Position_x2[1] - 1, Lights[0].Position_x2[2] - 1, 0, 1, 0);
glCullFace(GL_FRONT);
glColorMask(false, false, false, false);

setTextureMatrix();

for(unsigned int i = 0; Objects[i].SModel != -1; i++)
Objects[i].FRender(2);

glCullFace(GL_BACK);
glColorMask(true, true, true, true);
glPopMatrix();

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);[/QUOTE]</div>

CHANGE SIZE FUNC:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
void ChangeSize(GLsizei w, GLsizei h, GLfloat pers = 45.0f, GLfloat zfar = 800.0f, GLfloat znear = 0.2f)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(pers, (GLfloat)w/(GLfloat)h, znear, zfar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
};[/QUOTE]</div>

Nowhere-01
06-28-2011, 05:42 AM
Fixed... I had scissor test enabled. Without rectangle size specified, it used main window size for some reason. It doesn't affect performance, right? And is it ok to use 2048x2048 framebuffer? I can't find any strict info on it's limitations.

_arts_
06-28-2011, 05:59 AM
Check MAX_RENDERBUFFER_SIZE_EXT for the maximum sized available for your graphic card/driver.

Nowhere-01
06-28-2011, 08:08 AM
Thanks, but i meant more global info. Like maximum resolution that supported by every opengl 2.0+ card(i mean common resolution).

_arts_
06-29-2011, 03:11 AM
There is no common resolution. You just could expect that graphic cards supporting FBO could do 2048*2048 (I think even 4096*4096) renderbuffers for example. But nothing prevents a constructor to support less.

Have a look at this extension specs: http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt
You can even check the ARB extension, but it is very similar.

tksuoran
06-29-2011, 03:25 AM
The EXT version of framebuffer extension says at least renderbuffer size of 1 pixel (!) is required. So basically no meaningful minimum value is set, and you have to use the query.

If you use textures with your framebuffer, then OpenGL 2.1 specifies a minimum value of 64 for MAX_TEXTURE_SIZE. For OoenGL 3.0 the value is 1024. But I guess the extension could still reject some texture sizes if attached to framebuffer object.

You best bet is to query for the maximum supported sizes at runtime, and try with smaller resolution if an attempt fails. Limiting to power of two sizes may also help.