I'm programming on iOS using OpenGL ES and I'm trying to implement MSAA. I have succeeded in doing this. My screen comes out being anti-aliased. However, every frame the following string is logged to my output: "Failed to make complete framebuffer object 8cd6". 0x8CD6 means GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT. So, while it is working, I'm not sure what to make of this. I have read my code a hundred times and I see no mistakes with it.
The error is logged before the first time Render() is called but after Setup() has finished. I don't know exactly where, because what comes in-between those two function calls is code written by Apple.
void Setup() {
// ...
glGenFramebuffers(1, &resolveFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, resolveFramebuffer);
glGenRenderbuffers(1, &resolveColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, resolveColorRenderbuffer);
[[self context] renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, resolveColorRenderbuffer);
int backingWidth, backingHeight;
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cerr << "Failed to make complete resolve framebuffer." << std::endl;
glGenFramebuffers(1, &sampleFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, sampleFramebuffer);
GLuint sampleColorRenderbuffer;
glGenRenderbuffers(1, &sampleColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, sampleColorRenderbuffer);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_RGBA8_OES, backingWidth, backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, sampleColorRenderbuffer);
GLuint sampleDepthRenderbuffer;
glGenRenderbuffers(1, &sampleDepthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, sampleDepthRenderbuffer);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16, backingWidth, backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, sampleDepthRenderbuffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cerr << "Failed to make complete sample framebuffer." << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, resolveFramebuffer);
}
void Render() {
glBindFramebuffer(GL_FRAMEBUFFER, sampleFramebuffer);
glViewport(0, 0, renderer->DeviceWidth(), renderer->DeviceHeight());
glClearColor(0xfa/255.f, 0xe6/255.f, 0xd4/255.f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArrayOES(vertexArray);
glUseProgram(program);
GLuint mvpm = glGetUniformLocation(program, "modelViewProjectionMatrix");
GLuint nm = glGetUniformLocation(program, "normalMatrix");
glUniformMatrix4fv(mvpm, 1, GL_FALSE, modelViewProjectionMatrix.begin());
glUniformMatrix4fv(nm, 1, GL_FALSE, normalMatrix.begin());
glDrawArrays(GL_TRIANGLES, 0, verts.size()/2);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, resolveFramebuffer);
glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, sampleFramebuffer);
glResolveMultisampleFramebufferAPPLE();
const GLenum discards[] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT};
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, discards);
glBindRenderbuffer(GL_RENDERBUFFER, resolveColorRenderbuffer);
[[self context] presentRenderbuffer:GL_RENDERBUFFER];
}