我在 ios 上进行屏幕外渲染时遇到问题。下面是设置帧缓冲区对象和相关缓冲区的代码。它与苹果开发者中心的代码基本相同。
glGenFramebuffers(1, &pick_id);
glBindFramebuffer(GL_FRAMEBUFFER, pick_id);
GLuint color_id, depth_id;
glGenRenderbuffers(1, &color_id);
glBindRenderbuffer(GL_RENDERBUFFER, color_id);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, screen_width, screen_height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_id);
glGenRenderbuffers(1, &depth_id);
glBindRenderbuffer(GL_RENDERBUFFER, depth_id);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screen_width, screen_height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_id);
std::cout << pick_id << " " << color_id << " " << depth_id << std::endl;
switch(glCheckFramebufferStatus(GL_FRAMEBUFFER))
{
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: std::cout << "framebuffer incomplete attachment" << std::endl; break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: std::cout << "framebuffer incomplete missing attachment" << std::endl; break;
case GL_FRAMEBUFFER_UNSUPPORTED: std::cout << "framebuffer unsupported" << std::endl; break;
case GL_FRAMEBUFFER_COMPLETE: std::cout << "framebuffer complete" << std::endl; break;
}
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glFinish();
GLubyte pix[] = {0, 0, 0};
glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pix);
std::cout << (int)pix[0] << " " << (int)pix[1] << " " << (int)pix[2] << std::endl;
当它运行时,它会打印出“帧缓冲区完成”,所以我假设帧缓冲区对象已正确设置。但我希望对 glReadPixels 的调用能够返回我设置的清晰颜色(红色)——而不是返回黑色。
我在这里有什么遗漏吗?我正在尝试让屏幕外渲染工作以在我的应用程序中拾取对象。