PDA

View Full Version : Framebuffer object gone wrong



M/\dm/\n
03-04-2008, 11:48 AM
Hi! I tried to recompile one of my projects yesterday and it always gets stuck at one place. I don't know if it's 8800GT I have just put in or coding error, but I'm stuck.

Here is the code:


glGenTextures(1, &dyn_cubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, dyn_cubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, mta);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

glBindRenderbuffer(GL_RENDERBUFFER_EXT, rb_dcm);
GLenum e = glGetError(); //OK here
if(e)
__asm int 3;
GLenum aa = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);//0x8cd5 (COMPLETE)
glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, dyn_cm_size, dyn_cm_size);
GLenum bb = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);//0x8cd5 (COMPLETE)
e = glGetError();//0x502 (INVALID_OPERATION)
if(e)
__asm int 3;
glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
e = glGetError();
if(e)
__asm int 3;


I tried to change depth component to 16 and 32, but nothing helps. I don't understand how frame buffer can be complete yet throw an invalid operation error?!

Does anyone have an idea?

-NiCo-
03-04-2008, 12:31 PM
I don't understand how frame buffer can be complete yet throw an invalid operation error?!


It's possible if you didn't actually bind the framebuffer you want to investigate to the framebuffer target, in this case you're most likely checking if the window provided framebuffer is complete.

Did you generate the renderbuffer storage rb_dcm before binding it?

M/\dm/\n
03-04-2008, 03:51 PM
Whops... I didn't. Strangely it worked before. Still nothing works as expected anyway.

glInterceptor throws:
================================================== =
GL ERROR - Function wglGetPixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglGetPixelFormat generated error GL_INVALID_OPERATION
================================================== =
Since I generate 2 frame buffers that might be the fault. I will do more investigation.

M/\dm/\n
03-04-2008, 04:08 PM
Ok, I got it, the frame buffer for dynamic cube map is all wrong.


glGenTextures(1, &dyn_cubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, dyn_cubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, mta);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

/*glGenRenderbuffers(1, &rb_dcm);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, rb_dcm);
glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, dyn_cm_size, dyn_cm_size);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);

glGenFramebuffers(1, &fb_dcm);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb_dcm);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP, dyn_cubemap, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb_dcm);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);*/

I guess it binds in some other way, I will have to do some more research tomorrow.

-NiCo-
03-05-2008, 04:38 AM
Oh, I forgot... you can't use GL_TEXTURE_CUBE_MAP as the textarget parameter of glFramebufferTexture2D, it should be something like GL_TEXTURE_CUBE_MAP_POSITIVE_X, no?

M/\dm/\n
03-05-2008, 08:33 AM
Yep, my bad. I need to bind each of the faces as glFramebufferTexture2D. I have to figure out how to render to them first though. The face goes to level parameter and the textarget is cubemapface_ext or something like that. I will try to check that in the evening and report back.

M/\dm/\n
03-10-2008, 03:10 PM
I'm out of ideas... I managed to get 0 glErrors, but as soon as I turn my cubemap framebuffer on, I get a black screen :(

Maybe it's Vista x64 issue?

Here is the full init code:


void InitGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glShadeModel(GL_SMOOTH);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
wglSwapInterval(vsync);
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &mta);
if(mta>aniso_lvl)
mta=aniso_lvl;

objs = new cObject[objcount];
objs[0].LoadObj("Objects/1.obj");
objs[0].CreateVBO();
objs[1].LoadObj("Objects/2.obj");
objs[1].CreateVBO();
objs[2].LoadObj("Objects/3.obj");
objs[2].CreateVBO();
objs[3].LoadObj("Objects/5.obj");
objs[3].CreateVBO();

Textures.Load("bricks", "Textures/bricks.tga");
Textures.Load("bricksbm", "Textures/bricksbm.tga");
Textures.Load("tiles", "Textures/tiles.tga");
Textures.Load("tilesbm", "Textures/tilesbm.tga");
Textures.Load("iron", "Textures/iron.tga");
Textures.Load("ironbm", "Textures/ironbm.tga");
Textures.Load("stone", "Textures/stone.tga");
Textures.Load("stonebm", "Textures/stonebm.tga");
Textures.Load("cork", "Textures/cork.tga");
Textures.Load("corkbm", "Textures/corkbm.tga");
Textures.Load("wood", "Textures/wood.tga");
Textures.Load("woodbm", "Textures/woodbm.tga");
Textures.Load("floor", "Textures/floor.tga");
Textures.Load("floorbm", "Textures/floorbm.tga");

Textures.Load("skypx", "Textures/CubeMaps/posx.bmp");
Textures.Load("skynx", "Textures/CubeMaps/negx.bmp");
Textures.Load("skypy", "Textures/CubeMaps/posy.bmp");
Textures.Load("skyny", "Textures/CubeMaps/negy.bmp");
Textures.Load("skypz", "Textures/CubeMaps/posz.bmp");
Textures.Load("skynz", "Textures/CubeMaps/negz.bmp");

Shaders.Load("bump", "Shaders/vshBM.sh", "Shaders/fshBM.sh");
Shaders.Load("parallax", "Shaders/vshPM.sh", "Shaders/fshPM.sh");
Shaders.Load("relief", "Shaders/vshRM.sh", "Shaders/fshRM.sh");
Shaders.Load("cube", "Shaders/vshCM.sh", "Shaders/fshCM.sh");
Shaders.Load("cube_refr", "Shaders/vshCM_REF.sh", "Shaders/fshCM_REF.sh");
Shaders.Load("hdr", "Shaders/vshHDR.sh", "Shaders/fshHDR.sh");

glGenTextures(1, &dyn_cubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, dyn_cubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, mta);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB8, dyn_cm_size, dyn_cm_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

glGenRenderbuffers(1, &rb_dcm);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, rb_dcm);
glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, dyn_cm_size, dyn_cm_size);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);

glGenFramebuffers(1, &fb_dcm);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb_dcm);

/*glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, dyn_cubemap, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, dyn_cubemap, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, dyn_cubemap, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, dyn_cubemap, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, dyn_cubemap, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, dyn_cubemap, 0);*/
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, dyn_cubemap, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb_dcm);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);

glGenTextures(1, &color_tex);
glBindTexture(GL_TEXTURE_2D, color_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, Resolution.width, Resolution.height, 0, GL_RGB, GL_HALF_FLOAT_ARB, NULL);

glGenRenderbuffers(1, &rb);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, rb);
glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, Resolution.width, Resolution.height);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);

glGenFramebuffers(1, &fb);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, color_tex, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

frametime.UpdateBase();
}

glIntercept isn't complaining anymore. If I do error checking framebuffers are complete and good.

It seems to me that things mess up if I use 2 framebuffers. While I use only dynamic cubemap or only floating point texture to render screen to, everything is OK, as soon as both are on, nothing works.