Can I bind a texture to fbo & texname at same time

In general,we write a RTT code using FBO like below:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_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_COLOR_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?

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?

To me it counts as undefined. May work, may not, depending on the GL implementation.