将整数值传递给 glUniformSubroutinesuiv
Passing integer value to glUniformSubroutinesuiv
我正在收集我在 GLSL 着色器中使用子例程的第一次经验。我正在使用双通道边缘检测着色器,它在第一通道中将场景渲染为纹理,然后在第二通道中覆盖边缘。片段着色器有以下两个子程序,看起来像这样:
#version 430
/* Subroutines */
subroutine vec4 RenderPassType();
layout (location = 0) subroutine uniform RenderPassType renderPass;
...
layout (index = 1) subroutine(RenderPassType)
vec4 pass1()
{
...
}
layout (index = 2) subroutine(RenderPassType)
vec4 pass2()
{
...
}
void main()
{
out_color = renderPass();
}
在我的 OpenGL 代码中,我检索子例程的索引并按以下方式设置子例程统一:
GLuint subroutineIndexPass1{0};
GLuint subroutineIndexPass2{0};
subroutineIndexPass1 = glGetSubroutineIndex(prg_phongShading->GetProgramHandle(), GL_FRAGMENT_SHADER, "pass1");
subroutineIndexPass2 = glGetSubroutineIndex(prg_phongShading->GetProgramHandle(), GL_FRAGMENT_SHADER, "pass2");
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &subroutineIndexPass1);
但是,我已经在着色器本身中将索引定义为布局说明符!我不能这样做:
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, 1);
因此我的问题是:如何将整数文字值传递给 glUniformSubroutinesuiv
?有没有比指定 GLuint index = 1
并将其作为参数传递给函数更优雅的解决方案?
Is there a more elegant solution than specifying GLuint index = 1
and pass this as argument to the function?
没有
我正在收集我在 GLSL 着色器中使用子例程的第一次经验。我正在使用双通道边缘检测着色器,它在第一通道中将场景渲染为纹理,然后在第二通道中覆盖边缘。片段着色器有以下两个子程序,看起来像这样:
#version 430
/* Subroutines */
subroutine vec4 RenderPassType();
layout (location = 0) subroutine uniform RenderPassType renderPass;
...
layout (index = 1) subroutine(RenderPassType)
vec4 pass1()
{
...
}
layout (index = 2) subroutine(RenderPassType)
vec4 pass2()
{
...
}
void main()
{
out_color = renderPass();
}
在我的 OpenGL 代码中,我检索子例程的索引并按以下方式设置子例程统一:
GLuint subroutineIndexPass1{0};
GLuint subroutineIndexPass2{0};
subroutineIndexPass1 = glGetSubroutineIndex(prg_phongShading->GetProgramHandle(), GL_FRAGMENT_SHADER, "pass1");
subroutineIndexPass2 = glGetSubroutineIndex(prg_phongShading->GetProgramHandle(), GL_FRAGMENT_SHADER, "pass2");
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &subroutineIndexPass1);
但是,我已经在着色器本身中将索引定义为布局说明符!我不能这样做:
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, 1);
因此我的问题是:如何将整数文字值传递给 glUniformSubroutinesuiv
?有没有比指定 GLuint index = 1
并将其作为参数传递给函数更优雅的解决方案?
Is there a more elegant solution than specifying
GLuint index = 1
and pass this as argument to the function?
没有