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

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

问题描述

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

When sampling a texture in GLSL like this:

vec4 color = texture(mySampler, myCoords);

如果没有纹理绑定到 mySampler ,则 color 似乎总是(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的初始纹理对象即可. Wiki( 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天全站免登陆