我想将两个纹理传递给片段着色器。我成功了两个2D纹理,但没有一个1D和一个2D。
这是一段片段着色器代码:
sh = shaders.compileProgram(VERTEX_SHADER, FRAGMENT_SHADER)
shaders.glUseProgram(sh)
print 'here'
glEnable(GL_TEXTURE_2D)
glEnable(GL_TEXTURE_1D)
glActiveTexture(GL_TEXTURE0)
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
t_h = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, t_h)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 800, 600, 0, GL_RGB, GL_FLOAT, pts)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glActiveTexture(GL_TEXTURE0 + 2)
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
t_bb = glGenTextures(1)
glBindTexture(GL_TEXTURE_1D, t_bb)
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB32F, len(bboxes), 0, GL_RGB, GL_FLOAT, bboxes)
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
loc_h = glGetUniformLocation(sh, "heights")
loc_bb = glGetUniformLocation(sh, "bboxes")
glUniform1i(loc_h, 0)
glUniform1i(loc_bb, 1)
这是主程序代码的一部分(注意"打印'这里'":
File "forth.py", line 282, in <module>
shader = setup()
File "forth.py", line 128, in setup
sh = shaders.compileProgram(VERTEX_SHADER, FRAGMENT_SHADER)
File "/Library/Python/2.7/site-packages/PyOpenGL-3.0.2-py2.7.egg/OpenGL/GL/shaders.py", line 196, in compileProgram
program.check_validate()
File "/Library/Python/2.7/site-packages/PyOpenGL-3.0.2-py2.7.egg/OpenGL/GL/shaders.py", line 108, in check_validate
glGetProgramInfoLog( self ),
RuntimeError: Validation failure (0): Validation Failed: Sampler error:
Samplers of different types use the same texture image unit.
- or -
A sampler's texture unit is out of range (greater than max allowed or negative).
我遇到的错误是:
{{1}}
&#39;在这里&#39;没有打印。
请知道吗?
答案 0 :(得分:1)
第一个问题是你似乎使用纹理单元2作为1D纹理:glActiveTexture(GL_TEXTURE0 + 2)
但您要将制服设为1
<{1}}
使它们保持一致。
第二个问题是PyOpenGL包装器尝试在链接后立即验证着色器,这不起作用,因为此时你还没有配置Uniforms,因此存在纹理单元冲突。如果您的GLSL版本不支持glUniform1i(loc_bb, 1)
设置默认绑定,则无法验证。
我看到的唯一方法是创建自己的帮助函数来编译程序并跳过'验证'步骤:
layout