View Full Version : glTexImage2D - where does it copy from

06-24-2009, 07:26 AM

I wanted to make sure I understood - this isn't written explicitly anywhere: the source of the pixels that are copied into the texture depends on the format given with glCopyTexImage2D?
for example
if i specify GL_DEPTH_COMPONENT, then the texture image format will be depth component and also, pixels will be arriving from the depth buffer and not the color buffer, as would have been if i would have specified GL_RGBA or something.


06-24-2009, 10:24 AM
It's all right there for you...


Your assumptions about the source of the texture data are not correct.
Data is uploaded to VRAM from system memory, and a copy is kept in system memory (in case the VRAM copy gets flushed).

Reading from Depth Buffers etc. is a completely different kettle of fish.

Dark Photon
06-24-2009, 12:03 PM
It's all right there for you...


I think you might have misunderstood his question. The API he's asking about is glCopyTexImage2D. Man page is here (http://www.opengl.org/sdk/docs/man/xhtml/glCopyTexImage2D.xml). I gather we should ignore the incorrect API name he used in the subject.

As the man page says, this copies pixels from the current GL_READ_BUFFER (which you of course set with glReadBuffer()).

However, I think his question is how does this API know to read from the color buffer, depth buffer, stencil buffer, accumulation buffer, etcetc. within this active read buffer as the source of the data that is copied to the texture.

Man page doesn't really address, but it alludes to the answer in the errors:

GL_INVALID_OPERATION is generated if internalformat is GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, or GL_DEPTH_COMPONENT32 and there is no depth buffer

06-24-2009, 10:44 PM
Dark Photon - good catch on that line in the errors - it doesn't implicilty state what i wanted to know, but it is reassuring -

it seems the peeps who wrote the api find it obvious that you would like to copy the depth buffer to a depth texture - i imagine that if i would like to do something crazy like render to a color buffer, and then use it as a depth texture, i'd need some other way.