2017-08-09 104 views
0

我使用的是Glumpy,我試圖將紋理綁定爲GL_RGB32F。看起來它將紋理綁定爲GL_RGB,即使我的numpy陣列的類型爲np.float32。這個數組包含的值不在0..1範圍內,我需要在片段着色器中取消這些值。glumpy.gloo將紋理綁定爲GL_RGB32F

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_RGB32FdistanceField作爲GL_R32F結合?

回答

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)]