阵列纹理与采样器阵列有关吗? [英] Are array textures related to sampler arrays?

查看:86
本文介绍了阵列纹理与采样器阵列有关吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenGL具有阵列纹理,在着色器中由特定的采样器类型表示:

OpenGL has array textures, denoted in shaders by specific sampler types:

sampler2DArray array_texture;

但是GLSL还允许将采样器聚合为数组:

But GLSL also allows samplers to be aggregated into arrays:

sampler2D array_of_textures[10];

这两个功能是否相互关联?它们有什么不同?

Are these two features related to each other? How are they different?

推荐答案

让我们理解类比的区别. GLSL中的采样器类似于C ++中的指针.他们引用给定类型的其他对象.因此,请考虑以下C ++代码:

Let's understand the distinction by analogy. Samplers in GLSL are like pointers in C++; they reference some other object of a given type. So consider the following C++ code:

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

pi是指向int类型的单个对象的指针(让我们忽略一个事实,从技术上讲,它可能是指向int s数组的指针).

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

pai也是一个指针.但这并不指向int;它指向intarray. "int s中的array"是一个对象,具有一个连续的存储分配.

pai is also a pointer. But it doesn't point to an int; it points to an array of ints. That "array of ints" is a single object, with a single contiguous allocation of storage.

api不是指针;它是一个 array .具体来说,它是指向int的指针的数组.每个单独的指针都可以指向单独的int对象.每个指针都与其余指针无关,并且它们指向的对象完全不相关,除了它们都必须为int的事实.

api is not a pointer; it is an array. Specifically, it is an array of pointers to ints. Each individual pointer can point to individual int objects. Each individual pointer is independent from the rest, and the objects they point to are completely unrelated, save for the fact that they all must be ints.

这与OpenGL和纹理有什么关系?

What does this have to do with OpenGL and textures?

  • pi就像sampler2D.
  • pai就像sampler2DArray:单个指针/采样器,引用多个都驻留在单个对象中的多个int/2D纹理.
  • api就像sampler2D[]:一个表示多个指针/采样器的单个名称,每个指针/采样器都是独立绑定的,引用无关的对象,但它们都必须为int/ s.
  • pi is like sampler2D.
  • pai is like sampler2DArray: a single pointer/sampler which references multiple int/2D textures that all reside in a single object.
  • api is like a sampler2D[]: a single name which represents multiple pointers/samplers, each of which is independently bound, referencing objects that are unrelated save for the fact that they all must be int/sampler2Ds.

数组纹理是与非数组纹理不同的构造.阵列纹理具有特殊的纹理目标.在GLSL中访问数组纹理需要显式地使用与目标匹配的独特采样器类型.采用数组纹理的纹理访问功能会占用额外的纹理坐标分量,从而提供要访问的数组层.当您将纹理分配给数组纹理采样器时,您将分配单个纹理对象,无论其创建多少数组层.

An array texture is a distinct construct from a non-array texture. Array textures have a special texture target. Accessing array textures in GLSL requires explicitly using a distinct sampler type that matches the target. Texture accessing functions that take array textures take an extra texture coordinate component, providing the array layer to be accessed. When you assign a texture to an array texture sampler, you are assigning a single texture object, with whatever number of array layers it was created with.

相比之下,采样器数组只是一个编译时大小的集合,该集合包含多个以一个名称分组的独立采样器.将纹理分别分配给数组中的位置,并且可以使用任何适当类型的纹理.数组的每个元素都占据一个附加的绑定点.

By contrast, a sampler array is simply a compile-time sized collection of multiple independent samplers grouped under one name. Textures are assigned to locations in the array independently, with any texture of the appropriate type being able to be used. Each element of the array takes up a additional binding point.

除了资源消耗之外,最大的不同是:您可以使用运行时索引从数组中选择一个采样器(在OpenGL 4.x中;在4.x之前的版本中,您必须使用编译时常量.因此,sampler数组基本上没用).

The biggest difference besides resource consumption is this: you can pick a sampler from the array using a runtime index (in OpenGL 4.x; in pre-4.x, you had to use a compile-time constant. So sampler arrays were basically useless).

但不是任意运行时索引.您只能使用动态统一表达式的索引.也就是说,对于绘图命令中的所有调用,执行该指令必须的每个调用都会产生相同的索引.

But not an arbitrary runtime index. You can only use an index which is a dynamically uniform expression. That is, for all invocations in the drawing command, each invocation that executes that instruction must result in the same index.

数组纹理没有这样的索引限制;您在纹理获取命令中为其提供的数组索引可以是任何运行时值(当然,在数组内).

Array textures have no such indexing limitations; the array index you provide them in texture fetching commands can be any runtime value (within the array, of course).

但是数组纹理确实还有其他限制.阵列纹理中的每个纹理"都具有相同的大小.因此,如果您创建512x512x20 2D阵列纹理,则每个子纹理均为512x512.对于采样器阵列,阵列中每个纹理的大小可以变化.当然,每个采样器数组索引都占用一个绑定点这一事实也很重要.每个阶段只有16个(虽然可能更多;最低要求是16个).

But array textures do have other limitations. Every "texture" in an array texture has the same size; so if you create a 512x512x20 2D array texture, each sub-texture is 512x512. For sampler arrays, the size of each texture in the array can vary. Of course, the fact that each sampler array index takes up a binding point is also important; you only have 16 of those per-stage (though possibly more; 16 is the minimum requirement).

这篇关于阵列纹理与采样器阵列有关吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆