iOS OpenGL ES-将屏幕渲染到应用程序上的FBO,稍后重新绘制



我想将屏幕渲染为纹理,这样当我再次回到应用程序时,我就可以将纹理"粘贴"到屏幕上。目前在我的应用程序中,我正在绘制一个kEAGLDrawablePropertyRetainedBack设置为TRUE的波形。它是有效的,但在我从应用程序辞职并再次回来后,屏幕被清除了。kEAGLDrawablePropertyRetainedBacking为TRUE时,这种正常行为是真的吗?当我回到我的应用程序时,我负担不起重新绘制所有内容的fps。

我已经偶然发现了这一点:如何在OpenGL ES中保存和重新绘制屏幕内容,并试图将答案应用于我的需求,但我仍然有问题。

关于另一个问题的答案,以下是我如何尝试的。

@property (nonatomic) GLuint framebuffer;
@property (nonatomic) GLuint texture;

在glkviewcontroller中加载时的代码。

- (void)viewDidLoad  {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate) name:UIApplicationWillTerminateNotification object:nil];
    glGenFramebuffers(1, &_framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER_OES, _framebuffer);

    glGenTextures(1, &_texture);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, _texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 768, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_TEXTURE_2D);
.....

当这个视图控制器被通知应用程序辞职时,我使用这个功能:

 -(void)appWillResignActive
{
    glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, _texture, 0);
    if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
        NSLog(@"Error!");
}

在检查了上面的状态后,我仍然出现错误。这里可能有什么问题?我是OpenGL ES的新手,如果这是一个新手问题,请原谅。谢谢

Nevermind在上下文初始化之前,我正在尝试上面的纹理和帧缓冲区绑定。

    // Create an OpenGL ES 2.0 context and provide it to the
    // view
    view.context = [[AGLKContext alloc]
                    initWithAPI:kEAGLRenderingAPIOpenGLES2];
    view.delegate = self;
   // Make the new context current
   [AGLKContext setCurrentContext:view.context];

将代码放在这之后可以进行检查。

最新更新