iOS:更改renderbuffer后,glCheckFramebufferStatus返回GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES

时间:2013-04-05 18:03:32

标签: iphone ios objective-c opengl-es render

我正在制作一个绘画应用程序。 我想更改延音以添加重做和撤消功能。 但是在渲染之后我无法制作完整的帧缓冲区。

CAEAGLLayer* pGLLayer = ( CAEAGLLayer* )self.layer;
pGLLayer.opaque = YES;
pGLLayer.drawableProperties = [ NSDictionary dictionaryWithObjectsAndKeys:[ NSNumber numberWithBool:YES ],
                                                                 kEAGLDrawablePropertyRetainedBacking,
                                                                 kEAGLColorFormatRGBA8,
                                                                 kEAGLDrawablePropertyColorFormat,
                                                                                                                                     nil ];     
mpGLContext = [ [EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 ];
[ EAGLContext setCurrentContext:mpGLContext ];
glGenFramebuffers( 1, &FrameBuffer );
glBindFramebuffer( GL_FRAMEBUFFER, FrameBuffer );   
glGenRenderbuffers( 1, &firstColorBuffer );
glBindRenderbuffer( GL_RENDERBUFFER, firstColorBuffer );
[ mpGLContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:( CAEAGLLayer* )self.layer ];
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, firstColorBuffer );
glOrthof( 0.0f, 320.0f, 480.0f, 0.0f, 0.5f, -0.5f );
glViewport( 0, 0, 320, 480 );

    // here status is GL_FRAMEBUFFER_COMPLETE
    GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );

/** render function  **/
glGenRenderbuffers( 1, &secondColorBuffer );
glBindRenderbuffer( GL_RENDERBUFFER, secondColorBuffer );
[ mpGLContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:( CAEAGLLayer* )self.layer ];
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, firstColorBuffer );

// here status is GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES
GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );

glCheckFramebufferStatus返回GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES。 但我绑定renderbuffer。 所以帧缓冲有一个附件。 我应该在此代码中修复什么来制作完整的帧缓冲区。

1 个答案:

答案 0 :(得分:0)

尝试在/** render function **/

之后替换来电
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, firstColorBuffer );

glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, secondColorBuffer );

您要附加firstColorBuffer两次并根据docummentation最后附上一个损坏的附件:

  

之前对附件逻辑缓冲区的任何附件   当前绑定的framebuffer对象已损坏。