我想使用函数glReadPixels()
来截取我的场景。如果我不使用多重采样,它会很好用。但如果我这样做,我会GL_INVALID_OPERATION
进去glResolveMultisampleFramebufferAPPLE()
。有没有办法解决这个问题?
我的保存功能:
var wid = GLint()
var hei = GLint()
glGetRenderbufferParameteriv(GLenum(GL_RENDERBUFFER), GLenum(GL_RENDERBUFFER_WIDTH), &wid)
glGetRenderbufferParameteriv(GLenum(GL_RENDERBUFFER), GLenum(GL_RENDERBUFFER_HEIGHT), &hei)
let byteLength = Int(hei * wid) * 4
let bytes = UnsafeMutablePointer<GLubyte>.alloc(byteLength)
// init non-multisampled frame buffer
var framebuffer: GLuint = 0
var colorRenderbuffer: GLuint = 0
glGenFramebuffersOES(1, &framebuffer)
glBindFramebufferOES(GLenum(GL_FRAMEBUFFER_OES), framebuffer)
glGenRenderbuffersOES(1, &colorRenderbuffer)
glBindRenderbufferOES(GLenum(GL_RENDERBUFFER_OES), colorRenderbuffer)
glRenderbufferStorageOES(GLenum(GL_RENDERBUFFER_OES), GLenum(GL_RGBA8_OES), wid, hei)
glFramebufferRenderbufferOES(GLenum(GL_FRAMEBUFFER_OES), GLenum(GL_COLOR_ATTACHMENT0_OES), GLenum(GL_RENDERBUFFER_OES), colorRenderbuffer)
glBindFramebufferOES(GLenum(GL_DRAW_FRAMEBUFFER_APPLE), framebuffer)
var default: GLint = 0
glGetIntegerv(GLenum(GL_FRAMEBUFFER_BINDING_OES), &default)
glBindFramebufferOES(GLenum(GL_READ_FRAMEBUFFER_APPLE), GLuint(default));
myglGetError() // OK
glResolveMultisampleFramebufferAPPLE()
myglGetError() // GL_INVALID_OPERATION
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebuffer)
glReadPixels(0, 0, GLsizei(wid), GLsizei(hei), GLenum(GL_RGBA), GLenum(GL_UNSIGNED_BYTE), bytes)
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), GLuint(default));
glDeleteFramebuffers(1, &framebuffer)
GLKit
我使用由with初始化的默认帧缓冲区glkView.drawableMultisample = GLKViewDrawableMultisample.Multisample4X