开发者

Why, on iOS, is glRenderbufferStorage appearing to fail?

On an iOS device (iPad) I decided to change the storage for my renderbuffer from the CAEAGLLayer that backs the view to explicit storage via glRenderbufferStorage. Sadly, the following code fails to result in a valid FBO. Can someone please tell me what I missed?:

glGenFramebuffers(1, &m_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);

glGenRenderbuffers(1, &m_colorbuffer);
glBindRenderbuffer(GL_RENDERBUFFE开发者_如何学CR, m_colorbuffer);

GLsizei width  = (GLsizei)layer.bounds.size.width;
GLsizei height = (GLsizei)layer.bounds.size.height;
glRenderbufferStorage(m_colorbuffer, GL_RGBA8_OES, width, height);

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorbuffer);

Note:

The layer size is valid and correct. This is solid production working rendering code. The only change I am making is the line:

glRenderbufferStorage(...)

previously I did:

[m_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]


in iOS, you cannot use glRenderBufferStorage to bind color attachment, you need to request the storage from EAGLContext on the view layer. Somewhere on your view code, you must use code similar to this:

// First Bind a Render Buffer
glBindRenderbuffer(GL_RENDERBUFFER, m_colorBuffer);
[context renderBufferStorage:GL_RENDERBUFFER forDrawable:(CAEAGLLayer*) self.layer];

You cannot avoid the second line as it's needed by iOS, this is the line you refer to "linkage" from renderbuffer to layer


The first argument for glRenderbufferStorage should be GL_RENDERBUFFER, not m_colorbuffer.

(It will store in m_colorbuffer because that is what's bound to the GL_RENDERBUFFER target from the previous glBindRenderbuffer call)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜