Reputation: 2593
In case of 3D textures,
For three-dimensional textures, the z index refers to the third dimension. What does this exactly mean?
For two-dimensional array textures, the z index refers to the slice index. is it like if we have 4 layers of 2D textures, then if z=2, it will refer to 2nd 2D texture slice.?
So what is difference when we have targets GL_TEXTURE_3D and GL_TEXTURE_2D_ARRAY except diff between texture cordinates?
Upvotes: 3
Views: 2162
Reputation: 473212
For three-dimensional textures, the z index refers to the third dimension. What does this exactly mean?
Whatever you want it to mean.
A texture is nothing more than a lookup table. The index of this lookup table is called a texture coordinate. What a texture coordinate means depends entirely on how you intend to use it. It could be a position in space. It could be the XYZ of a function of three dimensions. It could be a lot of things.
Stop thinking of textures as pictures.
In a 2D texture, the S and T components of the texture coordinate represent how far along the X and Y axes of the texture to access. If S is 1, then it means the right side. If S is 0, it means the left side. And so forth.
The same goes for a 3D texture and the STP coordinates. If P is 0, then it means the "farthest" depth of the 3D texture. If P is 1, it means the "nearest" depth.
In terms of the data you upload, it always works based on a right-handed coordinate system. So the bottom/left/back is the (0, 0, 0) point, and the top/right/front is the (1, 1, 1) point. The first depth layer you provide in your data is the farthest depth layer, the next layer is the second-farthest, etc.
For two-dimensional array textures, the z index refers to the slice index. is it like if we have 4 layers of 2D textures, then if z=2, it will refer to 2nd 2D texture slice.?
No, it will refer to the third. Zero-based index, just like everything else in C/C++.
So what is difference when we have targets GL_TEXTURE_3D and GL_TEXTURE_2D_ARRAY except diff between texture cordinates?
There is no filtering between layers of a 2D array. If you use GL_TEXTURE_MAG_FILTER with GL_LINEAR in a 3D texture, it will sample values from 8 texels and interpolate in all 3 directions. If you do that with a 2D array, it will pick a specific Z-layer to sample from, and pick 4 texels within that layer to interpolate between.
Mipmaps work differently. A 3D texture contains 3D images. Therefore, each mipmap is 3D as well. Therefore, mipmap reduction works three-dimensionally. If the base layer is 32x32x32, then the next mipmap will be 16x16x16.
2D array textures contain 2D images. They contain an array of 2D images, but that's an implementation detail; it's just a collection of 2D images. Each 2D image has its own mipmaps, but these are 2D mipmaps. Therefore, each mipmap of a 2D array texture uses the same number of images as all of the others. Thus, if the base layer of a 2D array uses 32x32 2D images, and there are 32 of these images, the next mipmap layer will use 16x16 2D images, but there will still be 32 of them.
Array textures use integer values for the third component of the texture coordinate (the array layer to fetch from). 3D textures use normalized values for all three components.
In short, except for the functions you use to upload data to them, they have nothing at all in common.
Find out more by looking at the various pages on the OpenGL wiki about textures.
Upvotes: 6
Reputation: 1852
The 3D texture can interpolate in all three dimensions while the 2D array of textures only interpolates in the two image dimensions, not across the slices.
Upvotes: 3