handmade.network » Forums » [openGL] asset pipeline sanity check
erpeo93
54 posts

None

#15788 [openGL] asset pipeline sanity check
4 months ago Edited by erpeo93 on July 16, 2018, 1:37 p.m. 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

1
glAddLayerTo2dTextureArray( newTexture );


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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 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,
};

glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D_ARRAY,texture);
// 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.
Leonardo

None
ratchetfreak
412 posts
#15789 [openGL] asset pipeline sanity check
4 months ago

"evicting" an image just means allowing it to be overwritten by a new texture when needed
erpeo93
54 posts

None

#15790 [openGL] asset pipeline sanity check
4 months ago Edited by erpeo93 on July 17, 2018, 2:32 p.m.

ratchetfreak
"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"...

None
mmozeiko
Mārtiņš Možeiko
1826 posts / 1 project
#15793 [openGL] asset pipeline sanity check
4 months ago

No, that means calling glTexImage2D (or similar function) with new data which will overwrite previous texture data.
ratchetfreak
412 posts
#15794 [openGL] asset pipeline sanity check
4 months ago

it means calling glTexSubImage3D for just the layer of the evicted image with the new image data
erpeo93
54 posts

None

#15801 [openGL] asset pipeline sanity check
4 months ago

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...


None
ratchetfreak
412 posts
#15802 [openGL] asset pipeline sanity check
4 months ago

you'll need sparse textures for that.

erpeo93
54 posts

None

#15803 [openGL] asset pipeline sanity check
4 months ago Edited by erpeo93 on July 18, 2018, 4:36 p.m.

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.

None