gpt4 book ai didi

c++ - 使用自定义帧缓冲区时深度测试不起作用

转载 作者:行者123 更新时间:2023-11-30 05:05:46 26 4
gpt4 key购买 nike

我正在研究帧缓冲区,并且在我的场景中制作了一面镜子。除了深度测试外,它工作正常。卡住了试图让它工作。 (渲染到默认帧缓冲区时 - 深度测试工作正常)。将不胜感激任何帮助。这是代码:

glEnable( GL_DEPTH_TEST );

glViewport( 0, 0, 512, 512 );

unsigned int fbo;
glGenFramebuffers( 1, &fbo );
glBindFramebuffer( GL_FRAMEBUFFER, fbo );

unsigned int rbo;
glGenRenderbuffers( 1, &rbo );
glBindRenderbuffer( GL_RENDERBUFFER, rbo );
glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH, 512, 512 );
glBindRenderbuffer( GL_RENDERBUFFER, 0 );

glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, rbo ); //if remove this, mirror works but without depth test
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
this->mirror->texturePack[0]->textureId(), 0 );

//render scene from mirror camera

glBindFramebuffer( GL_FRAMEBUFFER, 0 );
glViewport( 0, 0, this->width(), this->height() );

//render scene from main camera

最佳答案

您的 farme 缓冲区不完整,因为 GL_DEPTH 不是渲染缓冲区存储的有效内部格式。 参见 glRenderbufferStorage .尝试 GL_DEPTH_COMPONENT16GL_DEPTH_COMPONENT24GL_DEPTH_COMPONENT32:

glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 512, 512 );

参见 OpenGL 4.6 core profile specification, 9.4 Framebuffer Completeness, page 323 :

The internal formats of the attached images can affect the completeness of the framebuffer, so it is useful to first define the relationship between the internal format of an image and the attachment points to which it can be attached.

• An internal format is depth-renderable if it is DEPTH_COMPONENT or one of the formats from table 8.13 whose base internal format is DEPTH_- COMPONENT or DEPTH_STENCIL. No other formats are depth-renderable.


请注意,可以通过以下方式检查帧缓冲区的完整性:

glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE

关于c++ - 使用自定义帧缓冲区时深度测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48239370/

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