如何将多个立方体纹理传递到均匀的采样器中
How to pass multiple cube textures into a uniform array of samplers?
说我在着色器中有一个制服,称为:
uniform samplerCube depth_maps[];
我在CPP侧有一系列纹理ID,称为:
vector<GLuint> depth_maps;
是通过绘制到框架附加纹理的绘制而创建的。
对于单个纹理,将信息传递到数组的代码看起来或多或少如下:
glUseProgram(program);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
GLint loc = glGetUniformLocation(program, "depth_maps");
if(loc == GL_INVALID_VALUE || loc==GL_INVALID_OPERATION)
{
cerr << "Error returned when trying to find depth_map uniform."
<< "nuniform: text"
<< "Error num: " << loc
<< endl;
return;
}
glUniform1i(loc,1);
在此处的gl_texture1中指示此纹理应将其附加到纹理单元1(假设已经连接到gl_texture0的纹理(。
问题n1只有2个保证的纹理单元,此后任何一个取决于实施。
问题n2,即使我有很多,我也只知道如何独立和独立地传递它们(即,我要通过我要通过的每个纹理的上述代码,并为每个纹理定义一个新的制服(
如何将THSI数据作为连续的均匀阵列传递?
说我在着色器中有一个制服,称为:
uniform samplerCube depth_maps[];
那将是一个编译错误。除一个例外,GLSL 中的数组必须(最终(以编译时间确定的大小声明。
但是,假设您已经给了这个数组一个大小(并且您确保将包含纹理图像单元的vector
用相同的尺寸(。在统一数组上设置纹理图像单元的工作方式正是设置均匀数组上的任何值的方式。
您可以单独执行每个数组元素的glUniform1i
命令。
for(std::size_t i = 0; i < depth_maps.size(); ++i)
{
std::ostringstream os;
os << "depth_maps[" << i << "]";
std::string name = std::move(os).str();
GLint loc = glGetUniformLocation(program, name.c_str());
glUniform1i(loc, depth_maps[i]);
}
,也可以一次设置它们。
GLint loc = glGetUniformLocation(program, "depth_maps");
glUniform1iv(loc, depth_maps.size(), depth_maps.data());
相关文章:
- SFML纹理像播放器
- 着色器纹理值与创建纹理时写入的值不同
- 在不使用统一的情况下将纹理传递给 GLSL 着色器?
- 将使用太多的纹理插值器 - 带旋转的着色器
- 如何使用采样器立方体作为数组
- 帧缓冲纹理变为白色(片段着色器不会影响它)
- SDL + OpenGL ES 2.0 使用着色器显示纹理
- 使用片段着色器写入 1D 纹理后从 1D 纹理读回不起作用
- 片段着色器中的"错误:在 GLSL 1.30 及更高版本中禁止使用非常量表达式索引的采样器数组"
- 为什么找不到这个统一采样器2D?
- 如何将多个立方体纹理传递到均匀的采样器中
- GLSL 无法获取采样器3D 值
- Glgetuniform -location以外的采样器返回-1
- 来自代码采样器的Direct3D(DirectX 9.0)代码示例
- Vulkan的YCBCR采样器
- 从 Vulkan 中的 R16_UINT-3D 纹理中采样片段着色器中的值
- 如何在vc++中使用samplegrabber?未定义采样器
- glUniform无法设置采样器值
- OpenGL如何使用多采样2d纹理将深度缓冲区附加到帧缓冲区
- R32I 采样器2D 始终返回 0