In these days we have been adding 2D texture arrays to the Texture Class and we have committed this new feature today into the CVS.
I found the Overview Paragraph of the OpenGL specification for EXT_texture_arrays pretty clear, so it follows an edited "copy and paste" of it:
more details at: http://developer.download.nvidia.com/op ... _array.txt... A 2d array texture is a collection of two-dimensional images of identical size and format, arranged in layers ... The depth specify the number of layers in the image. An array texture is accessed as a single unit in a programmable shader, using a single coordinate vector. A single layer is selected, and that layer is then accessed as though it were a two-dimensional texture. The layer used is specified using the "t" or "r" texture coordinate for 2D array textures, respectively. The layer coordinate is provided as an unnormalized floating-point value in the range [0,<n>-1], where <n> is the number of layers in the array texture. Texture lookups do not filter between layers, though such filtering can be achieved using programmable shaders. When mipmapping is used, each level of an array texture has the same number of layers as the base level; the number of layers is not reduced as the image size decreases. This extension does not provide for the use of array textures with fixed-function fragment processing.
As stated in the specification texture arrays must be used in conjunction with a fragment shader. The gp4 Fragment Program (gp4fp) profile must be used to compile the fragment shader source code.
To create a 2D texture array:
- Code: Select all
mtex_0 = TexturePool.load_2d_texture_array("textures/south00#.jpg");
To access the texture array within the fragment program:
- Code: Select all
//Cg profile gp4fp
void fshader(float3 l_texcoord:TEXCOORD0
uniform sampler2DArray mtex_0:TEXUNIT0)
o_color = tex2DARRAY(mtex_0,l_texcoord);
3. Why texture arrays?
The motivation for the texture arrays technique is performance. 2D texture arrays can be used to draw a multi-textured model in one pass (reducing state changes), or can be used in conjunction with hardware instancing to render different instances of a model with a different texture.