The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Fri, 21 Nov 2014 10:03:02 -0400
branchiOS-improvements
changeset 9526b1e51123fbea
parent 9525 64e3f446d6d7
child 9527 bbd9326ecacf
The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
src/video/uikit/SDL_uikitopenglview.m
     1.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Fri Nov 21 03:29:57 2014 -0400
     1.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Fri Nov 21 10:03:02 2014 -0400
     1.3 @@ -183,15 +183,11 @@
     1.4  
     1.5  - (void)updateFrame
     1.6  {
     1.7 -    glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
     1.8 -    glBindRenderbuffer(GL_RENDERBUFFER, 0);
     1.9 -    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
    1.10 -    glDeleteRenderbuffers(1, &viewRenderbuffer);
    1.11 +    GLint prevRenderbuffer = 0;
    1.12 +    glGetIntegerv(GL_RENDERBUFFER_BINDING, &prevRenderbuffer);
    1.13  
    1.14 -    glGenRenderbuffers(1, &viewRenderbuffer);
    1.15      glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
    1.16      [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
    1.17 -    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
    1.18  
    1.19      glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
    1.20      glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
    1.21 @@ -201,9 +197,7 @@
    1.22          glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
    1.23      }
    1.24  
    1.25 -    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
    1.26 -
    1.27 -    [self setDebugLabels];
    1.28 +    glBindRenderbuffer(GL_RENDERBUFFER, prevRenderbuffer);
    1.29  }
    1.30  
    1.31  - (void)setDebugLabels
    1.32 @@ -278,8 +272,15 @@
    1.33  {
    1.34      [super layoutSubviews];
    1.35  
    1.36 -    [EAGLContext setCurrentContext:context];
    1.37 -    [self updateFrame];
    1.38 +    CGSize layersize = self.layer.bounds.size;
    1.39 +    int width = (int) (layersize.width * self.layer.contentsScale);
    1.40 +    int height = (int) (layersize.height * self.layer.contentsScale);
    1.41 +
    1.42 +    /* Update the color and depth buffer storage if the layer size has changed. */
    1.43 +    if (width != backingWidth || height != backingHeight) {
    1.44 +        [EAGLContext setCurrentContext:context];
    1.45 +        [self updateFrame];
    1.46 +    }
    1.47  }
    1.48  
    1.49  - (void)destroyFramebuffer