gpt4 book ai didi

opengl - 写入浮点 FBO 时的低精度和钳位

转载 作者:行者123 更新时间:2023-12-04 23:27:14 27 4
gpt4 key购买 nike

我有一个按以下方式创建的 FBO:

glGenRenderbuffers(1, &m_depthStencilBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, m_width, m_height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);

glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_texture);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, m_width, m_height, 0, GL_RGBA, GL_FLOAT, 0);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

glGenFramebuffers(1, &m_frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_frameBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, m_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
assert(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER));
glBindFramebuffer(GL_FRAMEBUFFER, 0);
assert(GL_NO_ERROR == glGetError());

然后我用这个最小的片段程序渲染到这个:
void main() {
gl_FragColor = float4(3.001001f, 2.00002f, 7.00003f, 4.00004f);
}

如果我读出这样的像素:
glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, &pixels[0]);

并检查由上述片段程序写入的像素,它们是 (1, 1, 1, 1)。我只添加了 glReadPixels出于测试目的,如果我尝试使用 textureRect 在另一个片段程序中对 FBO 进行采样,我会遇到同样的问题。 .

最佳答案

是的,它将被限制在 (0, 1) 范围内 - 查看 glClampColor并禁用颜色钳制。

希望这可以帮助!

关于opengl - 写入浮点 FBO 时的低精度和钳位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10950743/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com