这是我的设置,宽度和高度是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_FRAMEBUFFER
和GL_DRAW_FRAMEBUFFER
的快捷方式,因此您的blit是从framebuffer
到framebuffer
,这是不允许的。