我正在使用OpenGL ES在iOS上编程,我正在尝试实现MSAA。我成功地做到了这一点。我的屏幕出现了反锯齿。但是,以下字符串的每一帧都记录到我的输出中:“无法生成完整的帧缓冲对象8cd6”。 0x8CD6表示GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT。所以,虽然它正在工作,但我不知道该怎么做。我已经阅读了我的代码一百次,我发现它没有错误。
在第一次调用Render()之前但在Setup()完成之后记录错误。我不确切知道在哪里,因为这两个函数调用之间的内容是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];
}