简体   繁体   English

GLSL纹理映射,最大纹理数量

[英]GLSL Texture Mapping, Max number of textures

I am working on a C++ GLSL renderer. 我正在研究C ++ GLSL渲染器。 I figured out how to map multiple textures in GLSL. 我想出了如何在GLSL中映射多个纹理。 using " glActiveTexture(GL_TEXTURE0) " I can tell my shader which texture to load. 使用“ glActiveTexture(GL_TEXTURE0) ”,我可以告诉我的着色器要加载哪个纹理。 The only problem is the constants GL_TEXTURE0 , GL_TEXTURE1 , ... , only go up to GL_TEXTURE31 . 唯一的问题是常量GL_TEXTURE0GL_TEXTURE1 ,...仅上到GL_TEXTURE31 Does this mean you can only load 32 textures for you scene? 这是否意味着您只能为场景加载32个纹理? Surely not. 当然不是。

Example: 例:

unsigned int textureIDs[2];

glGenTextures(2, textureIDs);

glActiveTexture(GL_TEXTURE0);

glBindTexture(GL_TEXTURE_2D, textureIDs[0]);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image1.x, image1.y, 0, GL_RGB, GL_UNSIGNED_BYTE, image1.data);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


glActiveTexture(GL_TEXTURE1);

glBindTexture(GL_TEXTURE_2D, textureIDs[1]);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image2.x, image2.y, 0, GL_RGB, GL_UNSIGNED_BYTE, image2.data);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

... Later on in my draw function ... ...稍后在我的绘制函数中...

int handle_loc = glGetUniformLocation( ProgramHandle, "Tex1" );

glUniform1i( handle_loc, val );

... If the variable "val" is set to 0, the texture data from image1 is mapped to my shader, if it is set to 1, the texture data from image2 is mapped to my shader. ...如果变量“ val”设置为0,则将image1的纹理数据映射到我的着色器;如果将其设置为1,则将image2的纹理数据映射到我的着色器。 ... ...

What am I doing wrong, how can I load more than 32 textures? 我在做什么错,如何加载32个以上的纹理?

The constant only goes up to GL_TEXTURE31 because that is all that is required by GL3. 该常量仅上升到GL_TEXTURE31因为这是GL3所需的全部。 There is a requirement of 16 texture image units per shader stage, and GL3 only has 2 stages (vertex and fragment). 每个着色器阶段需要16个纹理图像单元,而GL3仅具有2个阶段(顶点和片段)。

Later on GL (3.2) promoted Geometry Shaders to core, so the minimum number of texture image units became 48 (thus GL_TEXTURE47 would be the highest an implementation would have to define). 后来在GL(3.2)上将Geometry Shaders提升为核心,因此纹理图像单元的最小数量变为48(因此GL_TEXTURE47将是实现必须定义的最高数量)。

GL4 adds Tessellation Evaluation / Control stages, which bumps the minimum up to 80 (16 x 5 stages) . GL4增加了镶嵌细分评估/控制阶段,该阶段将最小值提高到80 (16 x 5阶段) At this point, however, most people stop using the constants and just use GL_TEXTURE0 + N to describe the N'th texture image unit. 然而,在这一点上,大多数人停止使用常量,而只是使用GL_TEXTURE0 + N来描述第N个纹理图像单元。


As far as the number of textures you can have loaded, that is completely independent of the number of texture image units your implementation supports. 至于可以加载的纹理数量,这完全独立于实现支持的纹理图像单元的数量。 Texture image units are binding locations, they are related to the maximum number of textures you can apply in a single invocation of a shader (in other words per-pass). 纹理图像单元是绑定位置,它们与您在一次着色器调用(即,每遍)中可以应用的最大纹理数量有关。

You can always resort to multiple passes if you require more than 16 textures in a shader stage, but I think you are confusing having textures "loaded" with having them bound to a texture image unit. 如果在着色器阶段需要16个以上的纹理,则始终可以采用多次遍历,但是我认为将纹理“加载”与将其绑定到纹理图像单元会令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM