PDA

View Full Version : Can I bind a texture to fbo & texname at same time



pango
06-02-2010, 11:23 PM
In general,we write a RTT code using FBO like below:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_CO LOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,texDstId,0);
glBindTexture(GL_TEXTURE_2D,texSrcId);
...// Rendering Code

but if I write the code like below:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_CO LOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,TexID,0);
glBindTexture(GL_TEXTURE_2D,TexID);
...// Rendering Code


the texture "TexID" is attatched to a FBO,and bind a texture name simultaneously,it is src & dst in a operation,so is it valid?whether it would cut down the performance of my program?

Alfonse Reinheart
06-03-2010, 12:27 AM
the texture "TexID" is attatched to a FBO,and bind a texture name simultaneously,it is src & dst in a operation,so is it valid?

Grammar note: spaces go after punctuation.

Yes it is valid, as long as you do not bind the same image to the FBO as you are using as texture. Remember: textures contain multiple images. A 2D texture can have several mipmaps, each of which is an image.

As long as you ensure that you don't read and write from/to the same image, you're fine. If you do, however, you're in undefined-land.

pango
06-04-2010, 01:08 AM
the texture "TexID" is attatched to a FBO,and bind a texture name simultaneously,it is src & dst in a operation,so is it valid?

Grammar note: spaces go after punctuation.

Yes it is valid, as long as you do not bind the same image to the FBO as you are using as texture. Remember: textures contain multiple images. A 2D texture can have several mipmaps, each of which is an image.

As long as you ensure that you don't read and write from/to the same image, you're fine. If you do, however, you're in undefined-land.

No, my program read and write from/to a same image, my program replace a image's color based on it's alpha channel, the replace operation is done by a cg shader, the shader read the alpha value from image, and then write a color to the same image because the image is attached to a FBO simultaneously, so whether my program is in undefied-land?

ZbuffeR
06-04-2010, 02:25 AM
To me it counts as undefined. May work, may not, depending on the GL implementation.