Commit b950cf46 authored by Ryan C. Gordon's avatar Ryan C. Gordon

iOS: Correctly resize renderbuffers when rotating orientation.

Fixes strange rendering after rotating the device.

--HG--
extra : rebase_source : 6962fd0710f95a81773157507aca653f9a3e1115
parent 932c46e9
...@@ -132,6 +132,7 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -132,6 +132,7 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
} }
/* Make this window the current mouse focus for touch input */ /* Make this window the current mouse focus for touch input */
/* !!! FIXME: only do this if this is the primary screen. */
SDL_SetMouseFocus(window); SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window); SDL_SetKeyboardFocus(window);
......
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */ /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
GLuint depthRenderbuffer; GLuint depthRenderbuffer;
/* format of depthRenderbuffer */
GLenum depthBufferFormat;
} }
@property (nonatomic, retain, readonly) EAGLContext *context; @property (nonatomic, retain, readonly) EAGLContext *context;
...@@ -62,6 +64,8 @@ ...@@ -62,6 +64,8 @@
depthBits:(int)depthBits \ depthBits:(int)depthBits \
majorVersion:(int)majorVersion; majorVersion:(int)majorVersion;
- (void)updateFrame;
@end @end
/* *INDENT-ON* */ /* *INDENT-ON* */
......
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
majorVersion:(int)majorVersion \ majorVersion:(int)majorVersion \
{ {
NSString *colorFormat=nil; NSString *colorFormat=nil;
GLuint depthBufferFormat;
BOOL useDepthBuffer; BOOL useDepthBuffer;
if (rBits == 8 && gBits == 8 && bBits == 8) { if (rBits == 8 && gBits == 8 && bBits == 8) {
...@@ -62,6 +61,8 @@ ...@@ -62,6 +61,8 @@
colorFormat = kEAGLColorFormatRGB565; colorFormat = kEAGLColorFormatRGB565;
} }
depthBufferFormat = 0;
if (depthBits == 24) { if (depthBits == 24) {
useDepthBuffer = YES; useDepthBuffer = YES;
depthBufferFormat = GL_DEPTH_COMPONENT24_OES; depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
...@@ -126,11 +127,36 @@ ...@@ -126,11 +127,36 @@
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
self.contentScaleFactor = [UIScreen mainScreen].scale; self.contentScaleFactor = [UIScreen mainScreen].scale;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.autoresizingMask = 0; // don't allow autoresize, since we need to do some magic in -(void)updateFrame.
} }
return self; return self;
} }
- (void)updateFrame {
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, 0);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, 0);
glDeleteRenderbuffersOES(1, &viewRenderbuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
if (depthRenderbuffer != 0) {
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight);
}
// !!! FIXME: use the screen this is on!
/* Use the main screen scale (for retina display support) */
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
self.contentScaleFactor = [UIScreen mainScreen].scale;
}
- (void)setCurrentContext { - (void)setCurrentContext {
[EAGLContext setCurrentContext:context]; [EAGLContext setCurrentContext:context];
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
- (id)initWithSDLWindow:(SDL_Window *)_window; - (id)initWithSDLWindow:(SDL_Window *)_window;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient; - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
- (void)loadView; - (void)loadView;
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
@end @end
/* *INDENT-OFF* */ /* *INDENT-OFF* */
......
...@@ -43,7 +43,6 @@ struct SDL_WindowData ...@@ -43,7 +43,6 @@ struct SDL_WindowData
SDL_uikitviewcontroller *viewcontroller; SDL_uikitviewcontroller *viewcontroller;
}; };
#endif /* _SDL_uikitwindow_h */ #endif /* _SDL_uikitwindow_h */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
...@@ -55,7 +55,8 @@ ...@@ -55,7 +55,8 @@
} }
// Send a resized event when the orientation changes. // Send a resized event when the orientation changes.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
SDL_WindowData *data = self->window->driverdata; SDL_WindowData *data = self->window->driverdata;
UIWindow *uiwindow = data->uiwindow; UIWindow *uiwindow = data->uiwindow;
CGRect frame = [uiwindow frame]; CGRect frame = [uiwindow frame];
...@@ -79,8 +80,11 @@ ...@@ -79,8 +80,11 @@
SDL_assert(0 && "Unexpected interface orientation!"); SDL_assert(0 && "Unexpected interface orientation!");
return; return;
} }
frame.size.width = w; frame.size.width = w;
frame.size.height = h; frame.size.height = h;
[uiwindow setFrame:frame];
[data->view updateFrame];
SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h); SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment