【发布时间】:2015-05-11 09:08:09
【问题描述】:
我正在尝试使用 this post 建议的 DRAW 帧缓冲区初始化一个全为零的纹理。但是,我很困惑我的 DRAW 帧缓冲区只有在我将它附加到 GL_COLOR_ATTACHMENT0 时才被清除:
int levels = 2;
int potW = 2; int potH = 2;
GLuint _potTextureName;
glGenTextures(1, &_potTextureName);
glBindTexture(GL_TEXTURE_2D, _potTextureName);
glTexStorage2D(GL_TEXTURE_2D, levels, GL_RGBA32F, potW, potH);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _potTextureName, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
GLuint clearColor[4] = {0,0,0,0};
glClearBufferuiv(GL_COLOR, 0, clearColor);
修改 sn-p 以使用GL_COLOR_ATTACHMENT1,保留其他所有内容,不会清除帧缓冲区:
int levels = 2;
int potW = 2; int potH = 2;
GLuint _potTextureName;
glGenTextures(1, &_potTextureName);
glBindTexture(GL_TEXTURE_2D, _potTextureName);
glTexStorage2D(GL_TEXTURE_2D, levels, GL_RGBA32F, potW, potH);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, _potTextureName, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
GLuint clearColor[4] = {0,0,0,0};
glClearBufferuiv(GL_COLOR, 0, clearColor);
我尝试使用glDrawBuffers 代替建议的here,我也尝试使用glClearColor 和glClear,但它们的行为方式都相同。我在这里错过了什么?
【问题讨论】:
-
第二个 sn-p 对
glTexStorage2D()的格式参数使用可能不同的值。您使用的是什么 OpenGL 版本? -
我可以想象触发这种行为的一件事可能是您仍然在颜色附件 0 处绑定了一些其他纹理/渲染缓冲区,这与新图像不兼容(例如样本计数不匹配,或者层)。您应该检查帧缓冲区的完整性状态。您还应该检查 GL 错误。
-
@derhass ,感谢您指出完整性问题。结果证明是相关的,我刚刚发布了我的发现作为答案。
-
@RetoKoradi,谢谢。我编辑了我的问题以使其更清楚。我正在使用 4.1。
标签: opengl textures framebuffer