Handmade Network»Forums
60 posts
[openGL] asset pipeline sanity check
Edited by erpeo93 on Reason: Initial post
Hi everyone,
I'm at the point where I need to start putting on a production-like pipeline, as I want to put my artist in a real-scenario position.
Everything is going fine, I only have one small doubt, and that is just how to avoid calling glBind and glDrawArray one million time.

I've seen that the only two real alternatives are 2d texture arrays or 3d textures.

So my plan was this:
-the texture packer, based on the image dimensions, adds an apron to it that will make it fit one of some predefined dimensions. (64x64, 256x256, ecc )
-This way I'm able to generate a texture array with a mipmap for every fixed dimension and be done with it, I just assign every vertex the mipmap and the texture index.

I only have 2 small doubt:
-There will probably be thousands of textures (swords, legs, heads and whatever) so I need the texture array to be totally dynamic: I need the possibilty to "evict" textures from the texture array.
Is that possible? if so, how it's done? a simple glDeleteTextures?

-I've read that every mipmap has to have the same number of "layers"... and furthermore looking online it seems that I can't just say

glAddLayerTo2dTextureArray( newTexture );

but I have to pass all the layers at one time, like so:

// Read you texels here. In the current example, we have 2*2*2 = 8 texels, with each texel being 4 GLubytes.
GLubyte texels[32] = 
     // Texels for first image.
     0,   0,   0,   255,
     255, 0,   0,   255,
     0,   255, 0,   255,
     0,   0,   255, 255,
     // Texels for second image.
     255, 255, 255, 255,
     255, 255,   0, 255,
     0,   255, 255, 255,
     255, 0,   255, 255,

// Allocate the storage.
glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount);
// Upload pixel data.
// The first 0 refers to the mipmap level (level 0, since there's only 1)
// The following 2 zeroes refers to the x and y offsets in case you only want to specify a subrectangle.
// The final 0 refers to the layer index offset (we start from index 0 and have 2 levels).
// Altogether you can specify a 3D box subset of the overall texture, but only one mip level at a time.
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, width, height, layerCount, GL_RGBA, GL_UNSIGNED_BYTE, texels);

Which doesn't seem to be quite what I want.

Where should I look in your opinion? I would like to avoid texture atlases and go with this if possible, it just seems a lot cleaner to me.

Thank you.
497 posts
[openGL] asset pipeline sanity check
"evicting" an image just means allowing it to be overwritten by a new texture when needed
60 posts
[openGL] asset pipeline sanity check
Edited by erpeo93 on
"evicting" an image just means allowing it to be overwritten by a new texture when needed

and that just means a simple glDeleteTexture right?

glDeleteTextures deletes n textures named by the elements of the array textures. After a texture is deleted, it has no contents or dimensionality, and its name is free for reuse (for example by glGenTextures). If a texture that is currently bound is deleted, the binding reverts to 0 (the default texture).

I guess the answer is a clear "yes"...
Mārtiņš Možeiko
2202 posts / 1 project
[openGL] asset pipeline sanity check
No, that means calling glTexImage2D (or similar function) with new data which will overwrite previous texture data.
497 posts
[openGL] asset pipeline sanity check
it means calling glTexSubImage3D for just the layer of the evicted image with the new image data
60 posts
[openGL] asset pipeline sanity check
Oh yes, now I see.
glTexSubImage3d allows me to "resend" a single layer for a 3d texture.

There's a way to specify how many layers a 3d texture will have without actually allocating space?
Because it seems to me that both glTexImage3D with a null data param and
glTexStorage3D don't allow me to do that...

If that could be possible in some way I would just declare those 3d texture to have 0xffffffff layers and then manage the eviction myself, and submit data with just glTexImage3d when I need to load a texture...

497 posts
[openGL] asset pipeline sanity check
you'll need sparse textures for that.

60 posts
[openGL] asset pipeline sanity check
Edited by erpeo93 on
Sean Barret presentation + source code are my best bet at learning it, or would you suggest me something else/in addition?
I think that if they avoid me the business of extensions/running only on certain hardware I'll stick with that.