没有纹理绑定的 OpenGL 采样 [英] OpenGL Sampling with no texture bound

查看:28
本文介绍了没有纹理绑定的 OpenGL 采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当像这样在 GLSL 中采样纹理时:

When sampling a texture in GLSL like this:

vec4 color = texture(mySampler, myCoords);

如果没有纹理绑定到 mySamplercolor 似乎总是 (0, 0, 0, 1).

If there is no texture bound to mySampler, color seems to be always (0, 0, 0, 1).

这是标准行为吗?或者它可能在某些实现中undefined?我在规范中找不到任何内容.

Is this the standard behavior? Or may it be undefined on some implementations? I couldn't find anything in the specs.

推荐答案

实际上没有所谓的未绑定"——您只是绑定到称为纹理 0 的初始纹理对象.根据 OpenGL维基(http://www.opengl.org/wiki/OpenGL_Objects),

There's really no such thing as being "unbound" -- you're simply bound to the initial texture object which is known as texture 0. According to the OpenGL wiki (http://www.opengl.org/wiki/OpenGL_Objects),

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

最终,您将在着色器中获得的值取决于当时纹理对象 0 中的内容.除了一个论坛帖子之外,我真的找不到任何东西了这应该是什么:

Ultimately, the value you're going to get in the shader depends on what happens to be in Texture Object 0 at the time. I can't really find anything except one forum post that actually says what this should be:

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

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

I certainly wouldn't trust that to be consistent across all GPU drivers, yours might have it initialized to all zero, or it might be considered an incomplete texture, in which case the OpenGL spec (2.0 and later at least) says:

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)纹理绑定.

... So really the wisest course of action seems to be "don't do that." Make sure you have a valid (non-zero id) texture bound if you're going to run a sampler.

这篇关于没有纹理绑定的 OpenGL 采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆