gpt4 book ai didi

c++ - glReadPixels 不适用于获取 OpenGL ES 1.0 的深度

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:54:51 27 4
gpt4 key购买 nike

<分区>

我正在尝试使用 glReadPixels 函数从深度缓冲区获取深度值。它总是返回 0 给我。

首先,我创建深度缓冲区附件:

glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[self.context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

if (USE_DEPTH_BUFFER)
{
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
}

然后我调用 glReadPixels 函数从深度缓冲区获取深度值:

float depth = 0.0f;

glReadPixels(point.x, self.renderUIView.frame.size.height - point.y, 1, 1, GL_DEPTH_COMPONENT16_OES, GL_FLOAT, &depth);

但它不起作用,深度值始终为 0。我尝试从 glGetError() 获取错误代码,它返回 1280。我错过了什么设置吗?

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