gpt4 book ai didi

c++ - OpenGL:GL_FRAMEBUFFER_UNSUPPORTED 在帧缓冲区附件的特定组合上

转载 作者:行者123 更新时间:2023-11-30 01:47:57 24 4
gpt4 key购买 nike

我正在尝试将多个目标附加到帧缓冲区对象。我有以下问题:

使用 float 纹理附件和深度附件时没有错误。使用 float 纹理附件和整数纹理附件时也没有错误。尽管这些组合有效,但我不能同时使用 float 、整数和深度附件。这会导致 GL_FRAMEBUFFER_UNSUPPORTED 状态。

这是我的代码:

//working:
Framebuffer fb = Framebuffer(
1280,720,
{
//AttachmentInfo(GL_DEPTH_COMPONENT16,GL_DEPTH_ATTACHMENT),
AttachmentInfo(GL_RG32F,GL_COLOR_ATTACHMENT0),
AttachmentInfo(GL_RGB16UI,GL_COLOR_ATTACHMENT1),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT2),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT3),
AttachmentInfo(GL_RGBA16F,GL_COLOR_ATTACHMENT4),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT5),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT6),
}
);

//working:
Framebuffer fb = Framebuffer(
1280,720,
{
AttachmentInfo(GL_DEPTH_COMPONENT16,GL_DEPTH_ATTACHMENT),
AttachmentInfo(GL_RG32F,GL_COLOR_ATTACHMENT0),
//AttachmentInfo(GL_RGB16UI,GL_COLOR_ATTACHMENT1),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT2),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT3),
AttachmentInfo(GL_RGBA16F,GL_COLOR_ATTACHMENT4),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT5),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT6),
}
);

//NOT working:
Framebuffer fb = Framebuffer(
1280,720,
{
AttachmentInfo(GL_DEPTH_COMPONENT16,GL_DEPTH_ATTACHMENT),
AttachmentInfo(GL_RG32F,GL_COLOR_ATTACHMENT0),
AttachmentInfo(GL_RGB16UI,GL_COLOR_ATTACHMENT1),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT2),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT3),
AttachmentInfo(GL_RGBA16F,GL_COLOR_ATTACHMENT4),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT5),
AttachmentInfo(GL_RGB32F,GL_COLOR_ATTACHMENT6),
}
);

注意:我只在使用 NVidia GTX 970 显卡时遇到此错误。在较旧的 ATI 卡上没有发生错误。

我使用 glbinding 在每次 gl* 函数调用后调用 glGetError,所以我知道没有发生其他错误。

这是我的Framebuffer 对象的构造函数代码:

Framebuffer::Framebuffer(uint width,uint height,initializer_list<AttachmentInfo> attachments)
:width(width),height(height)
{
glGenFramebuffers(1,&fbID);
glBindFramebuffer(GL_FRAMEBUFFER,fbID);

if(std::none_of(attachments.begin(),attachments.end(),[](const AttachmentInfo& a){
return a.attachment == GL_DEPTH_ATTACHMENT;
})){
//depth test needs either a depth renderbuffer or depth attachment.
unsigned int rboID=0;
glGenRenderbuffers(1, &rboID);
glBindRenderbuffer(GL_RENDERBUFFER, rboID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,rboID);
}

vector<GLenum> buffers;
glActiveTexture(GL_TEXTURE0);

for(AttachmentInfo attachment:attachments){
GLuint tID;
glGenTextures(1, &tID);
glBindTexture(GL_TEXTURE_2D,tID);

GLint param;
glGetInternalformativ(GL_TEXTURE_2D, attachment.internalFormat, GL_FRAMEBUFFER_RENDERABLE, 1, &param);

if(param != GL_FULL_SUPPORT){
_log(WARNING,"Internal format " << attachment.internalFormat << " support is " << GLenum(param) << ".");
}

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GLint(GL_LINEAR));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GLint(GL_LINEAR));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GLint(GL_CLAMP_TO_EDGE));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GLint(GL_CLAMP_TO_EDGE));

if(attachment.attachment == GL_DEPTH_ATTACHMENT){
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GLint(GL_COMPARE_REF_TO_TEXTURE));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GLint(GL_LESS));
}
glTexStorage2D(GL_TEXTURE_2D,1,attachment.internalFormat,width,height);
glFramebufferTexture(GL_FRAMEBUFFER, attachment.attachment, tID, 0);

if(Tools::startsWith(glbinding::Meta::getString(attachment.attachment),"GL_COLOR_ATTACHMENT")){
buffers.push_back(attachment.attachment);
}
texMap[attachment.attachment]=new Texture(tID,GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,0);
}
if(buffers.empty()){
buffers.push_back(GL_NONE);
}
glDrawBuffers(buffers.size(),buffers.data());

GLenum error=glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(error != GL_FRAMEBUFFER_COMPLETE){
_log(ERROR,"Framebuffer error: " << error);
}
unbind();
}

我真的不知道我能做些什么来让它发挥作用......

最佳答案

Im really out of ideas what I can do to make it work...

您的 OpenGL 实现告诉您,您选择的配置不受支持。你必须接受这一点。 OpenGL 规范不要求所有实现都支持特定的格式组合,因此如果您希望编程具有可移植性和健壮性,如果您遇到 GL_FRAMEBUFFER_UNSUPPORTED 错误,则必须逐渐降低格式要求,直到可行找到组合。

关于支持的内容的一个很好的提示是枚举所有支持创建 OpenGL 上下文的 FBConfigs;通常这是允许的 FBO 配置的子集。

关于c++ - OpenGL:GL_FRAMEBUFFER_UNSUPPORTED 在帧缓冲区附件的特定组合上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30952948/

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