当使用 GL_RGBA16F_ARB 纹理时,它只包含垃圾,但我没有收到错误消息

发布于 2024-07-14 21:28:57 字数 1649 浏览 9 评论 0原文

我生成这样的纹理:

GLuint id;

glGenTextures(1, &id);

glBindTexture(GL_TEXTURE_2D, id);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage2D(
    GL_TEXTURE_2D, 0,
    GL_RGBA16,
    //GL_RGBA16F_ARB, //< Won't work
    256, 256, 0, GL_RGBA, GL_FLOAT, NULL
);

glBindTexture(GL_TEXTURE_2D, 0);

我将其附加到帧缓冲区对象 (FBO) 进行渲染。 当我将内部格式设置为 GL_RGBA16 时,所有这些都非常有效。 但是,我需要更高的动态范围,并且认为 GL_RGBA16F_ARB 可能可以解决问题。

不幸的是,如果我在上面给出的代码中将 GL_RGBA16 替换为 GL_RGBA16F_ARB ,纹理似乎停止工作。 我没有尝试渲染到 FBO/纹理棒,当我使用纹理时,它包含随机垃圾。 (事实证明,有很多紫色)如果我收到一条错误消息暗示可能出了什么问题,那么这不会那么令人沮丧,但我似乎找不到错误消息。 换句话说,glGetError()glTexImage2D 调用后返回 0,并且 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) 返回 < code>GL_FRAMEBUFFER_COMPLETE_EXT 当我附加纹理时,

我还没有搞乱glClampColorARB(...) ...但是:)

  1. 我是否忘记检查某个地方/方式中的错误我没想到吗?
  2. GL_RGBA16F_ARB-纹理是否需要我未给予的任何特殊处理?
  3. 还有其他可能出错的地方吗?

我很困惑,因为 GL_RGBA16 一切都很顺利... :(

编辑: 当使用 GL_RGBA16F_ARB 时,我尝试渲染的第一帧在我看来,我应该在某处收到错误消息..?

编辑: 通过检查 ShadowIce 的工作代码示例,我发现如果我更改了 <我的 FBO 上的深度缓冲区,并将 glRenderBufferStorageEXT(...) GL_DEPTH_COMPONENT24 作为其第二个参数,而不是 GL_DEPTH_COMPONENT16我不知道为什么它有效,但显然它确实有效,

而且如果我在那里进行相反的替换,ShadowIce 的代码也会像我的那样崩溃。

I generate a texture like this:

GLuint id;

glGenTextures(1, &id);

glBindTexture(GL_TEXTURE_2D, id);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage2D(
    GL_TEXTURE_2D, 0,
    GL_RGBA16,
    //GL_RGBA16F_ARB, //< Won't work
    256, 256, 0, GL_RGBA, GL_FLOAT, NULL
);

glBindTexture(GL_TEXTURE_2D, 0);

I attach it to a framebuffer object (FBO) for rendering to. All of this works like a charm when I set the internal format to GL_RGBA16. However, I need a higher dynamic range and was thinking that GL_RGBA16F_ARB might do the trick.

Unfortunately, if I replace GL_RGBA16 with GL_RGBA16F_ARB in the code given above, the texture seems to stop working. Nothing I try to render to the FBO/texture sticks, and when I use the texture it contains random garbage. (A lot of purple, as it turns out) This would not be so frustrating if I had gotten an error message hinting at what might be wrong, but I can't seem to find one. In other words, glGetError() returns 0 after the glTexImage2D-call, and glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) returns GL_FRAMEBUFFER_COMPLETE_EXT when I have attached the texture

I haven't messed with glClampColorARB(...) ... yet :)

  1. Have I forgotten to check for errors in a place/way that I haven't thought of?
  2. Do GL_RGBA16F_ARB-textures require any special treatment that I haven't given?
  3. Is there anything else that might be wrong?

I'm stumped, since everything works smoothly with GL_RGBA16... :(

EDIT: When using GL_RGBA16F_ARB, the first frame I try to render to screen doesn't make it. Seems to me that I should be getting an error message somewhere..?

EDIT: By inspecting ShadowIce's working code example I figured out that the problems disappeared if I changed the depth buffer on my FBO, and give glRenderBufferStorageEXT(...) GL_DEPTH_COMPONENT24 as its second parameter, rather than GL_DEPTH_COMPONENT16. I have no idea why this works, but apparently it does work.

Also, ShadowIce's code breaks like mine if I do the opposite substitution there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟沫凡尘 2024-07-21 21:28:57

设置具有浮动纹理的帧缓冲区不应该做任何特殊的事情。 我会检查一些事情:

  1. 在调用 glCheckFramebufferStatusEXT 之前,FBO 绑定和绘制/读取缓冲区设置是否正确? 也可以在绘制之前尝试对其进行测试。
  2. 经过简单的 glClear 和特定的透明颜色后,纹理看起来还好吗? 如果是,则您的着色器(如果您使用任何)或绘制到 FBO 的方式可能有问题。
  3. 您的驱动程序是最新的吗? 在不同硬件的PC上问题是否仍然存在?
  4. GL_RGBA32F_ARB怎么样?

编辑:

  1. 检查帧缓冲区和纹理的 ID,并检查纹理 ID 是否与附加到 fbo 的纹理 ID 匹配(使用 glGetFramebufferAttachmentParameteriv)。 通常情况下,我猜如果它与 RGBA 纹理一起工作,那么一切都可以,但随机数据(尤其是紫色)是一个好兆头,表明没有任何内容写入纹理或没有正确清除。

我编写了一个应该可以工作的小示例应用程序,也许有帮助。 我只在 Windows 上测试过它,因此对于 Linux,您可能需要稍微更改一下:链接

There shouldn't be anything special to do for setting up a framebuffer with float textures. Some things I would check:

  1. Is the FBO bound and the draw/read buffer set correctly before you call glCheckFramebufferStatusEXT? Also try testing it right before you draw to it.
  2. Does the texture look ok after a simple glClear with a specific clear color? If yes, there might be something wrong with your shaders (if you use any) or the way you draw to the FBO.
  3. Are your drivers up to date? And does the problem still exist on a PC with different hardware?
  4. How about GL_RGBA32F_ARB?

Edit:

  1. Check the id of your framebuffer and texture, also check if the texture id matches the one attached to your fbo (with glGetFramebufferAttachmentParameteriv). Normally I would guess that everything is ok with that if it works with a RGBA texture but random data (especially purple) is a good sign that nothing was written to the texture or it wasn't cleared properly.

I have written a small example application that should work, maybe that helps. I have only tested it on windows, so for linux you might need to change it a bit: link

匿名。 2024-07-21 21:28:57

GL_HALF_FLOAT_ARB 可能会代替 GL_FLOAT 作为类型。

GL_HALF_FLOAT_ARB might work as the type instead of GL_FLOAT.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文