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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/src/video/uikit/SDL_uikitopenglview.m b/src/video/uikit/SDL_uikitopenglview.m
index f0237ca..0c2a6b1 100644
--- a/src/video/uikit/SDL_uikitopenglview.m
+++ b/src/video/uikit/SDL_uikitopenglview.m
@@ -183,15 +183,11 @@
- (void)updateFrame
{
- glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
- glBindRenderbuffer(GL_RENDERBUFFER, 0);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
- glDeleteRenderbuffers(1, &viewRenderbuffer);
+ GLint prevRenderbuffer = 0;
+ glGetIntegerv(GL_RENDERBUFFER_BINDING, &prevRenderbuffer);
- glGenRenderbuffers(1, &viewRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
@@ -201,9 +197,7 @@
glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
}
- glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
-
- [self setDebugLabels];
+ glBindRenderbuffer(GL_RENDERBUFFER, prevRenderbuffer);
}
- (void)setDebugLabels
@@ -278,8 +272,15 @@
{
[super layoutSubviews];
- [EAGLContext setCurrentContext:context];
- [self updateFrame];
+ CGSize layersize = self.layer.bounds.size;
+ int width = (int) (layersize.width * self.layer.contentsScale);
+ int height = (int) (layersize.height * self.layer.contentsScale);
+
+ /* Update the color and depth buffer storage if the layer size has changed. */
+ if (width != backingWidth || height != backingHeight) {
+ [EAGLContext setCurrentContext:context];
+ [self updateFrame];
+ }
}
- (void)destroyFramebuffer