Texture Object loaded with TexSubImage

Is it possible to bind a texture object with a call to glTexSubImage ?
Creation would look like :

// In a texture manager : 

// A first Texture Object :

// and another

Also, can I change the format and/or internal and/or the target (as long as it’s compatible with the texSubImage call) format of the pixels between the two SubTextures ?
Thanks for your replies !

What do you mean bind a texture object with glTexSubImage? glBindTexture binds the texture. What are you trying to do?

glGenTextures generates a texture object
glBindTexture binds a texture object
glTexImage2D loads a C++ data array into the currently bound texture
glTexSubImage2D loads a C++ data array into the currently bound texture as well, but only into a specific region. You can do this multiple times for the same bound texture.

When you make a texture, there are no “sub textures” floating around. Just the texture. Calling glTexSubImage only changes a portion of a texture region, then its done. No subtexture business.

The glTexSubImage call should match the format, type, and target of the original glTexImage call as that is what determines the attributes of the texture. If you look at the documentation for glTexSubImage2D, you can jump down to the error section and get a good idea what you can and can’t do including using different types and targets than the one specified in glTexImage2D.


More precisely:
glTexImage* allocates a data block for a MIPmap, sets its format, and copies the data you provide into it (if any)
glTexSubImage* only copies the data you provide into the existing MIPmap data block

So after you call glTexImage* once for a texture MIPmap level, you should never call it again. Use glTexSubImage* to change the contents.

If you provide a data pointer to glTexImage* it must be for the whole MIPmap. But for glTexSubImage*, it can be for the whole MIPmap OR a subregion of the MIPmap.

Also note that if your texture has a compressed internal format and you provide uncompressed texels to these calls, they’ll cause the driver to do run-time texel compression which can be time consuming.

To clarify what strattonbrazil said, when you call glTexImage2D, you fix the internalFormat for the texture MIPmap and the layout (e.g. 2D, 3D, etc.) for the texture, and the driver allocates the data block for that MIPmap.

So in the future when you change the texels via glTexSubImage, you should use the same target.

The internalFormat as I said is fixed and you can’t change it via glTexSubImage – there’s no such argument.

And the format/type arguments can be whatever you need as they don’t describe the format of the texels in the texture, but rather the format of the texels in the data block you’re providing to glTexImage/glTexSubImage to copy into the texture.

Ok, here’s the story
I’ve developped a Buffer Object manager which creates Buffer Objects of size 4Mb, and fills them whenever a user creates a Buffer Object from my engine (so it’s completely transparent) :
So basically, when a user binds his buffer Object, he’s binding a subsections of the 4Mb buffer, really (saves me somes binds - can’t use VAO’s but I’m privileging flexibility).

Now, I’m thinking about designing a texture manager working the same way. That’s why I dared to ask if I could use texSubImage… But it seems I can’t so, user will have to create the “giga” texture before sending it to my GL manager, which is no big deal anyway.

So thanks for your replies, things are clear to me now !