我正在使用 Android 上的 opengl es2.0 进行屏幕外处理。
我创建了一个渲染缓冲区,并将其附加到帧缓冲区 FBO,在渲染到 FBO 后,我尝试通过 getReadPixels() 方法从该 FBO 获取像素。但我一无所获。
代码如下所示:
GLuint resultFBO;// FBO
GLuint rboId; //render buffer id
glGenRenderbuffers(1, &rboId);
glBindRenderbuffer(GL_RENDERBUFFER, rboId);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, image_width, image_height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glGenFramebuffers(1, &resultFBO);
glBindFramebuffer(GL_FRAMEBUFFER, resultFBO);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, rboId);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status == GL_FRAMEBUFFER_COMPLETE) {
//LOGH("Single FBO setup successfully.");
} else {
LOGH("Problem in setup FBO texture: %d .", status);
}
//After render to the FBO
glBindFramebuffer(GL_FRAMEBUFFER, resultFBO);
glReadPixels(0, 0, w, h, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, imageSetData);