From c5298b508cce9d84908ea390ec07d97478907f06 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 30 Jun 2022 21:47:07 +1000 Subject: [PATCH] iOS: Fix screen showing partial garbage when rotating device when rendering game, make home swipe bar more difficult to trigger (Thanks Pear) --- src/interop_ios.m | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/interop_ios.m b/src/interop_ios.m index d344a22b8..16b0715ee 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -71,8 +71,6 @@ static CGRect GetViewFrame(void) { @implementation CCWindow -//- (void)drawRect:(CGRect)dirty { DoDrawFramebuffer(dirty); } - - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch* t in touches) AddTouch(t); } @@ -163,6 +161,14 @@ static UITextField* kb_widget; - (BOOL)prefersStatusBarHidden { return fullscreen; } + +- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures { + // recent iOS versions have a 'bottom home bar', which when swiped up, + // switches out of ClassiCube and to the app list menu + // overriding this forces the user to swipe up twice, which should + // significantly the chance of accidentally triggering this gesture + return UIRectEdgeBottom; +} @end @implementation CCAppDelegate @@ -499,6 +505,8 @@ void Window_Create2D(int width, int height) { /*#########################################################################################################################* *--------------------------------------------------------3D window--------------------------------------------------------* *#########################################################################################################################*/ +static void GLContext_OnLayout(void); + @interface CCGLView : UIView @end @@ -507,6 +515,11 @@ void Window_Create2D(int width, int height) { + (Class)layerClass { return [CAEAGLLayer class]; } + +- (void)layoutSubviews { + [super layoutSubviews]; + GLContext_OnLayout(); +} @end void Window_Create3D(int width, int height) { @@ -531,6 +544,7 @@ void Window_Create3D(int width, int height) { static EAGLContext* ctx_handle; static GLuint framebuffer; static GLuint color_renderbuffer, depth_renderbuffer; +static int fb_width, fb_height; static void CreateFramebuffer(void) { CAEAGLLayer* layer = (CAEAGLLayer*)view_handle.layer; @@ -550,6 +564,9 @@ static void CreateFramebuffer(void) { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) Logger_Abort2(status, "Failed to create renderbuffer"); + + fb_width = WindowInfo.Width; + fb_height = WindowInfo.Height; } void GLContext_Create(void) { @@ -561,8 +578,18 @@ void GLContext_Create(void) { } void GLContext_Update(void) { + // trying to update renderbuffer here results in garbage output, + // so do instead when layoutSubviews method is called +} + +static void GLContext_OnLayout(void) { CAEAGLLayer* layer = (CAEAGLLayer*)view_handle.layer; + // only resize buffers when absolutely have to + if (fb_width == WindowInfo.Width && fb_height == WindowInfo.Height) return; + fb_width = WindowInfo.Width; + fb_height = WindowInfo.Height; + glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer); [ctx_handle renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];