首页 文章

OpenGL采样没有纹理绑定

提问于
浏览
7

在GLSL中对纹理进行采样时,如下所示:

vec4 color = texture(mySampler, myCoords);

如果没有绑定到mySampler的纹理,则颜色似乎总是(0,0,0,1) .

这是标准行为吗?或者可能在某些实现中未定义?我在规格中找不到任何东西 .

2 回答

  • 4

    有's really no such thing as being 828353 -- you'简单地绑定到初始纹理对象,称为纹理0.根据OpenGL维基(http://www.opengl.org/wiki/OpenGL_Objects),

    You are strongly encouraged to think of texture 0 as a non-existent texture.
    

    最终,除了一个forum post之外,你真正找到的东西实际上说的是这应该是什么:

    The texture 0 represents an actual texture object, the default texture.
    All textures start out as 1x1 white textures.
    

    我当然不相信在所有GPU驱动程序中保持一致,你可能会将它初始化为全零,或者它可能被认为是不完整的纹理,在这种情况下,OpenGL规范(至少2.0及更高版本)说:

    If a fragment shader uses a sampler whose associated texture object is not
    complete, the texture image unit will return (R, G, B, A) = (0, 0, 0, 1).
    

    ......所以,最明智的行动似乎是“不要这样做” . 如果要运行采样器,请确保绑定了有效(非零id)纹理 .

  • 6

    内森是正确的(但我太新/声誉太低,不能upvote) .

    我已经/肯定地看到,在某些OpenGL ES平台上,使用未绑定的纹理会在屏幕上呈现垃圾(图形内存的随机内容) . 您不能相信所有驱动程序供应商都遵循该规范 .

    永远不会引用未绑定的OpenGL对象或状态 .

相关问题