Are massive textures related to sampler arrays?

OpenGL has array textures indicated in shaders by specific types of samplers:

sampler2DArray array_texture; 

But GLSL also allows you to combine samplers into arrays:

 sampler2D array_of_textures[10]; 

Are these two functions related to each other? How do they differ?

+5
source share
1 answer

Let me understand the difference by analogy. GLSL samplers are similar to C ++ pointers; they refer to another object of this type. Therefore, consider the following C ++ code:

 int* pi; std::array<int, 5>* pai; std::array<int*, 5> api; 

pi is a pointer to a single object of type int (let it ignore the fact that technically it can be a pointer to an array of int s).

pai also a pointer. But it does not point to int ; it points to an array of int s. That " array of int s" is the only object with a single continuous memory allocation.

api not a pointer; this is an array. In particular, it is an array of pointers to int s. Each individual pointer can point to individual int objects. Each individual pointer is independent of the others, and the objects they point to are completely unrelated, except that they must all be int s.

pi as sampler2D . pai is similar to sampler2DArray : one pointer / sampler that references multiple int / 2D textures that are all in the same object. api is similar to sampler2D[] : one name, which is several pointers / samplers, each of which is independently connected, referring to objects that are not connected to each other, except that they must all be int / sampler2D s.

An array texture is a separate structure from a texture without an array. Array textures have a special texture purpose. Access to array textures in GLSL explicitly requires a separate type of sampler that matches the target. The texture access function, which takes the texture of the array, gets an additional component of the texture coordinate, providing access to the array. When you assign a texture to a texture sampler in an array, you assign a single texture object with any number of layers in the array with which it was created.

In contrast, a sampler array is simply a collection of several independent samples grouped under the same name. Textures are assigned to locations in the array independently of each other, and any texture of the corresponding type can be used. Each element of the array occupies an additional anchor point.

The biggest difference besides resource consumption is this: you can select a sampler from an array using a run-time index (in OpenGL 4.x, in pre-4.x you had to use a compile-time constant. Arrays are mostly useless).

But not an arbitrary runtime index. You can only use an index, which is a dynamic uniform expression . That is, for all calls in the drawing command, each call that executes this command should lead to the same index.

Massive textures do not have such indexing restrictions; the index of the array that you provide to them in the texturing commands can be any runtime value (within the array, of course).

But array textures have other limitations. Each β€œtexture” in an array texture has the same size; therefore, if you create a 512x512x20 array texture, each sub-texture is 512x512. For sampler arrays, the size of each texture in the array can vary. Of course, it is also important that each index in the sample array occupies a reference point; you only have 16 of these steps (although maybe more, 16 is the minimum requirement).

+5
source

Source: https://habr.com/ru/post/1275440/


All Articles