我正在使用Glumpy而我正在尝试将纹理绑定为GL_RGB32F
。看起来它将纹理绑定为GL_RGB
,即使我的numpy数组是np.float32
类型。此数组包含的值超出0..1范围,我需要在片段着色器中取消剪切这些值。
compute = gloo.Program(compute_vertex, compute_fragment, count=4)
compute["matte"] = matte
compute["matte"].interpolation = gl.GL_NEAREST
compute["matte"].wrapping = gl.GL_CLAMP_TO_EDGE
compute["distanceField"] = alpha
compute["distanceField"].interpolation = gl.GL_NEAREST
compute["distanceField"].wrapping = gl.GL_CLAMP_TO_EDGE
compute["position"] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
compute["texcoord"] = [(0, 0), (0, 1), (1, 0), (1, 1)]
print(matte.dtype)
print(gl.GL_RGB32F)
print(compute["matte"].gpu_format)
print(compute["distanceField"].gpu_format)
输出
float32
GL_RGB32F (34837)
GL_RGB (6407)
GL_RED (6403)
如何将matte
数组绑定为GL_RGB32F
,将distanceField
绑定为GL_R32F
?
答案 0 :(得分:0)
找到答案。在numpy数组上使用view(gloo.TextureFloat2D)
,否则,在内部会自动调用view(Texture2D)
。
compute = gloo.Program(compute_vertex, compute_fragment, count=4)
compute["matte"] = matte.view(gloo.TextureFloat2D)
compute["matte"].interpolation = gl.GL_NEAREST
compute["matte"].wrapping = gl.GL_CLAMP_TO_EDGE
compute["distanceField"] = alpha.view(gloo.TextureFloat2D)
compute["distanceField"].interpolation = gl.GL_NEAREST
compute["distanceField"].wrapping = gl.GL_CLAMP_TO_EDGE
compute["position"] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
compute["texcoord"] = [(0, 0), (0, 1), (1, 0), (1, 1)]