glCompressedTexImage without specifying data?

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.

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.

Well, glCompressedTexSubImage exists…

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.