iOS: Correctly resize renderbuffers when rotating orientation.
Fixes strange rendering after rotating the device. --HG-- extra : rebase_source : 6962fd0710f95a81773157507aca653f9a3e1115
This commit is contained in:
parent
932c46e9ca
commit
b950cf4653
6 changed files with 41 additions and 7 deletions
|
@ -132,6 +132,7 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
}
|
||||
|
||||
/* Make this window the current mouse focus for touch input */
|
||||
/* !!! FIXME: only do this if this is the primary screen. */
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SetKeyboardFocus(window);
|
||||
|
||||
|
|
|
@ -45,7 +45,9 @@
|
|||
|
||||
/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
|
||||
GLuint depthRenderbuffer;
|
||||
|
||||
|
||||
/* format of depthRenderbuffer */
|
||||
GLenum depthBufferFormat;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain, readonly) EAGLContext *context;
|
||||
|
@ -62,6 +64,8 @@
|
|||
depthBits:(int)depthBits \
|
||||
majorVersion:(int)majorVersion;
|
||||
|
||||
- (void)updateFrame;
|
||||
|
||||
@end
|
||||
/* *INDENT-ON* */
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
majorVersion:(int)majorVersion \
|
||||
{
|
||||
NSString *colorFormat=nil;
|
||||
GLuint depthBufferFormat;
|
||||
BOOL useDepthBuffer;
|
||||
|
||||
if (rBits == 8 && gBits == 8 && bBits == 8) {
|
||||
|
@ -62,6 +61,8 @@
|
|||
colorFormat = kEAGLColorFormatRGB565;
|
||||
}
|
||||
|
||||
depthBufferFormat = 0;
|
||||
|
||||
if (depthBits == 24) {
|
||||
useDepthBuffer = YES;
|
||||
depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
|
||||
|
@ -108,7 +109,7 @@
|
|||
|
||||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
|
||||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
|
||||
|
||||
|
||||
if (useDepthBuffer) {
|
||||
glGenRenderbuffersOES(1, &depthRenderbuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
|
||||
|
@ -126,11 +127,36 @@
|
|||
if ([[UIScreen mainScreen] respondsToSelector:@selector(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;
|
||||
}
|
||||
|
||||
- (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 {
|
||||
[EAGLContext setCurrentContext:context];
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
- (id)initWithSDLWindow:(SDL_Window *)_window;
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
|
||||
- (void)loadView;
|
||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
|
||||
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
|
||||
@end
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
|
|
@ -43,7 +43,6 @@ struct SDL_WindowData
|
|||
SDL_uikitviewcontroller *viewcontroller;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _SDL_uikitwindow_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -55,7 +55,8 @@
|
|||
}
|
||||
|
||||
// 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;
|
||||
UIWindow *uiwindow = data->uiwindow;
|
||||
CGRect frame = [uiwindow frame];
|
||||
|
@ -79,8 +80,11 @@
|
|||
SDL_assert(0 && "Unexpected interface orientation!");
|
||||
return;
|
||||
}
|
||||
|
||||
frame.size.width = w;
|
||||
frame.size.height = h;
|
||||
[uiwindow setFrame:frame];
|
||||
[data->view updateFrame];
|
||||
SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue