ios上的帧缓冲对象渲染 [英] framebuffer object rendering on ios
问题描述
我在使用ios进行屏幕外渲染时遇到问题。下面是设置帧缓冲对象和相关缓冲区的代码。它与苹果公司在其开发人员中心的代码基本相同。
I'm having problems getting offscreen rendering working on ios. Below is the code for setting up a framebuffer object and associated buffers. It is basically the same as the code that apple have on their developer centre.
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;
当它运行时,它打印出'framebuffer complete',所以我假设已经设置了framebuffer对象正确的。但是我希望调用glReadPixels给我回复我设置的清晰颜色(红色) - 而不是它返回黑色。
When this is run it prints out 'framebuffer complete', so I assume the framebuffer object has been set up correctly. But I would expect the call to glReadPixels to give me back the clear colour (red) which I have set - instead it returns black.
这里有什么我想念的?我正试图让屏幕外渲染在我的应用程序中挑选对象。
Is there anything I am missing here? I'm trying to get the offscreen rendering working for picking objects in my app.
推荐答案
这似乎是上面的代码是正确的。唯一的问题是在ios上你需要使用GL_RGBA作为glreadpixels的参数,GL_RGB不起作用。
It seems to be that the code above is correct. The only problem is that on ios you need to use GL_RGBA as argument to glreadpixels, GL_RGB does not work.
这篇关于ios上的帧缓冲对象渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!