PDA

View Full Version : glCompressedTexImage without specifying data?



dv
07-08-2011, 08:18 AM
Hello,

I can use glTexImage without specifying data to initialize an empty texture, which I can later will with glTexSubImage. Can I do the same with glCompressedTexImage? It is not documented what happens if I set imageSize and data to zero.

BionicBytes
07-08-2011, 08:51 AM
I can use glTexImage without specifying data to initialize an empty texture, which I can later will with glTexSubImage.
Yes. Pass NULL in as the data pointer.

Can I do the same with glCompressedTexImage?
I don't think so. How are you going to generate the data to upload into the texture? If you had already compressed the texture image and persisted it, then perhaps you could read that data back in an upload to GL.

dv
07-08-2011, 01:53 PM
Well, glCompressedTexSubImage exists..

Dark Photon
07-11-2011, 06:15 PM
I can use glTexImage without specifying data to initialize an empty texture, which I can later will with glTexSubImage. Can I do the same with glCompressedTexImage? It is not documented what happens if I set imageSize and data to zero.
Whether you can call glCompressedTexImage*() with data = NULL depends...

Dim memory from years ago: glTexImage2D takes a NULL pointer to data to allocate but not initialize. So you'd just use glTexImage2D to allocate a compressed texture without initializing it, whether using a compressed texture format or not, and then use glCompressedTexSubImage2D to load content into the allocated texture later for a compressed texture and glTexSubImage2d to load content later into a non-compressed texture.

Memory fuzzy here, but IIRC the original compressed texture extension spec didn't allow for NULL pointer for data to glCompressedTexImage*. GL 2.1 spec doesn't explicitly allow it either. But latest GL 4.1 spec does. Somewhere along the way this changed.

Anyway, check the spec for whichever version of OpenGL you're targetting, and use glTexImage* to alloc and not init if it doesn't say you can pass data = NULL to glCompressedTexImage*.

Checking the GL 4.1 man pages, looks like this data = NULL allowance for glCompressedTexImage* didn't make it into the man pages. glTexImage* explicitly does define that data = NULL is valid.