这是我的设置,宽度和高度是GLKView的边界*缩放

private func initFrameBuffer() -> GLuint {
    var framebuffer_id: GLuint = 0
    glGenFramebuffers(1, &framebuffer_id)
    glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebuffer_id)
    return framebuffer_id
}

private func initRenderBuffer(_ width: GLsizei, _ height: GLsizei) -> GLuint {
    var renderBuffer_id: GLuint = 0
    glGenRenderbuffers(1, &renderBuffer_id)
    glBindRenderbuffer(GLenum(GL_RENDERBUFFER), renderBuffer_id)
    glRenderbufferStorage(GLenum(GL_RENDERBUFFER), GLenum(GL_RGBA8), width, height)
    glFramebufferRenderbuffer(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_RENDERBUFFER), renderBuffer_id)
    return renderBuffer_id
}

func blitz() {
    glBindFramebuffer(GLenum(GL_FRAMEBUFFER), frameBuffer)
    bindDrawable()
    glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GLbitfield(GL_COLOR_BUFFER_BIT), GLenum(GL_LINEAR))
}


我在blitz()中调用draw(_ rect),并且什么也没有发生,所以当我检查错误时,它给了我GL_INVALID_OPERATION

我还尝试获取ios FBO的ID并手动绑定它来代替调用bindDrawble(),这也失败了。

最佳答案

glBlitFramebuffer从当前绑定的GL_READ_FRAMEBUFFER复制到当前绑定的GL_DRAW_FRAMEBUFFER。绑定到目标GL_FRAMEBUFFER是将FBO同时绑定到GL_READ_FRAMEBUFFERGL_DRAW_FRAMEBUFFER的快捷方式,因此您的blit是从framebufferframebuffer,这是不允许的。

09-16 02:02