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