PDA

View Full Version : Use of FBO and GL_TEXTURE_RECTANGLE_ARB



alblackck
08-12-2008, 06:44 PM
Hello,

I am new to this forum. I just started using OpenGL extensions about 3 months ago.

I am trying to render to both a color and a depth texture(GL_TEXTURE_RECTANGLE_ARB) that are attached to an FBO. I am using Cg shaders to do per-vertex and per-fragment operations. After I render I use those textures again in a different render (using a different Cg shader), but it's either not rendering to the texture the first time, or the second shader is not capturing the values. Howerver, when I use a query to check how many fragments made it to the frame buffer the first time, and it returns many fragments, so i don't know if and why the texture is not capturing the values.

I need to berify which exact card Im using at the lab ( it's something like Ge Force 79... something), but i'll post it up when i have the info.

Here's where i initialize the FBO and textures:



glGenTextures(2, g_dirLayerDepthTexId);
glGenTextures(2, g_dirLayerColorTexId);
glGenFramebuffersEXT(2, g_depthPeelingFboId);

for (int i = 0; i < 2; i++)
{
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, g_dirLayerDepthTexId[i]);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT24_ARB,
sampling.g_imageWidth, sampling.g_imageHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);

glBindTexture(GL_TEXTURE_RECTANGLE_ARB, g_dirLayerColorTexId[i]);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, sampling.g_imageWidth, sampling.g_imageHeight,
0, GL_RGBA, GL_FLOAT, 0);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_depthPeelingFboId[i]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_RECTANGLE_ARB, g_dirLayerDepthTexId[i], 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_RECTANGLE_ARB, g_dirLayerColorTexId[i], 0);
}


Here's where I bind and try to render to the first FBO



glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_depthPeelingFboId[currLayer]);
glDrawBuffer(g_drawBuffers[0]);

glMatrixMode(GL_PROJECTION);
glViewport(0, 0, sampling.g_imageWidth, sampling.g_imageHeight);
glMatrixMode(GL_MODELVIEW);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_DEPTH_TEST);

glBeginQuery(GL_SAMPLES_PASSED_ARB, g_peelingQuery);

//LAYER RENDER
cgGLBindProgram(cgVProgram_DirPeel); checkForCgError("Binding DirPeel Vertex Shader");
cgGLBindProgram(cgFProgram_DirPeel); checkForCgError("Binding DirPeel Fragment Shader");

cgSetMatrixParameterfr ( cgVParam_DirPeel_dirViewProjMat, dirView.viewProjMat ); checkForCgError("Setting DirPeel Vertex Shader Param 'dirViewProjMat'");
cgSetMatrixParameterfr ( cgVParam_DirPeel_dirTextCoordMat, dirTextCoordMat ); checkForCgError("Setting DirPeel Vertex Shader Param 'dirTextCoordMat'");
cgSetParameter3fv ( cgFParam_DirPeel_lNormal, lights[0]->normals+3 ); checkForCgError("Setting DirPeel Fragment Shader Param 'lNormal'");
cgSetParameter3fv ( cgFParam_DirPeel_gAmbient, lights[0]->materials[1].ambient ); checkForCgError("Setting DirPeel Fragment Shader Param 'gAmbient'");
cgSetParameter3fv ( cgFParam_DirPeel_Id, lights[0]->materials[1].diffuse ); checkForCgError("Setting DirPeel Fragment Shader Param 'Id'");
cgSetParameter3fv ( cgFParam_DirPeel_Is, lights[0]->materials[1].specular ); checkForCgError("Setting DirPeel Fragment Shader Param 'Is'");
cgSetParameter3fv ( cgFParam_DirPeel_objSpaceLPos, lights[0]->position ); checkForCgError("Setting DirPeel Fragment Shader Param 'objSpaceLPos'");
cgSetParameter3fv ( cgFParam_DirPeel_objSpaceEPos, dirView.eye ); checkForCgError("Setting DirPeel Fragment Shader Param 'objSpaceEPos'");
cgGLSetTextureParameter( cgFParam_DirPeel_pervDepthLayer, g_dirLayerDepthTexId[prevLayer] ); checkForCgError("Setting DirPeel Fragment Shader Param 'pervDepthLayer'");

lightPass = 2;
DrawScene();

cgGLUnbindProgram(cgVProfile); checkForCgError("Binding DirPeel Vertex Shader");
cgGLUnbindProgram(cgFProfile); checkForCgError("Binding DirPeel Fragment Shader");


Any suggestions?

arekkusu
08-12-2008, 07:03 PM
1) Verify your rendering got there with glReadPixels, or glGetTexImage.
2) Verify you can draw a simple textured quad with a rectangle texture. Remember that you need to use a rect sampler, and denormalized coordinates.

alblackck
08-14-2008, 06:47 AM
Hey, yeah, the data is not reaching the frame buffer, the texture is not capturing the values. What am I doing wrong though? before I tried doing the same thing with a GL_TEXTURE_2D, and instead of a depth texture i used a render buffer to capture the depth values, and the colors got there (I also created a mip map with the 2D texture) but now I don't get anything.

BTW. the draw buffer I specify here:

glDrawBuffer(g_drawBuffers[0]);

is GL_COLOR_ATTACHMENT0_EXT, so it's the same as:

glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

and, the card that I am using is NVIDIA GeForce 7950 GX2

alblackck
08-14-2008, 12:29 PM
actually i just found out that the rendering does take place. I need to test again the second Cg shader to see if it actually works

alblackck
08-15-2008, 08:31 AM
So the I can render to the GL_TEXTUE_RECTANGLE_ARB. When I map it to a quad, and render the quad, it renders correctly. However, when i try to use the shader, it doesn't. How am I supposed to specify a GL_TEXTURE_RECTANGLE_ARB to a Cg shader?

Ilian Dinev
08-16-2008, 03:41 AM
How about:


glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,0); // ensure this unit is not a 2D!
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,MyRectTextu re); // makes texUnit0 a rectangle-texture

//----[ here bind the cg shader ]---------[
cgBindShaderBlahBlah(myRectShader);
//----------------------------------------/

// now set the shader's texture-ID
cgSetUniformBlahBlah("TheRectTexture",0);

// finally, start drawing your geometry
... glBegin blahblah glEnd glVertexPointer

Ilian Dinev
08-16-2008, 03:44 AM
Also, you can use semantics in Cg shaders, which are a wonderful thing.

Just specify:
samplerRect TheRectTexture : TEXUNIT0;


and this way you don't need to set the texture-unit in your app
(the cgSetUniformBlahBlah("TheRectTexture",0) line)

alblackck
08-19-2008, 12:48 PM
ok, I tried something like that, and it works. Now I'm having a different problem with rendering a depth texture, but I'm going to open another topic for that.

alblackck
08-19-2008, 12:48 PM
thanks a lot btw