Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
iOS: Correctly resize renderbuffers when rotating orientation.
Browse files Browse the repository at this point in the history
Fixes strange rendering after rotating the device.
  • Loading branch information
icculus committed Apr 3, 2011
1 parent e548e78 commit afb4098
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitopengles.m
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion src/video/uikit/SDL_uikitopenglview.h
Expand Up @@ -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;
Expand All @@ -62,6 +64,8 @@
depthBits:(int)depthBits \
majorVersion:(int)majorVersion;

- (void)updateFrame;

@end
/* *INDENT-ON* */

Expand Down
32 changes: 29 additions & 3 deletions src/video/uikit/SDL_uikitopenglview.m
Expand Up @@ -50,7 +50,6 @@ - (id)initWithFrame:(CGRect)frame \
majorVersion:(int)majorVersion \
{
NSString *colorFormat=nil;
GLuint depthBufferFormat;
BOOL useDepthBuffer;

if (rBits == 8 && gBits == 8 && bBits == 8) {
Expand All @@ -62,6 +61,8 @@ - (id)initWithFrame:(CGRect)frame \
colorFormat = kEAGLColorFormatRGB565;
}

depthBufferFormat = 0;

if (depthBits == 24) {
useDepthBuffer = YES;
depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
Expand Down Expand Up @@ -108,7 +109,7 @@ - (id)initWithFrame:(CGRect)frame \

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);
Expand All @@ -126,11 +127,36 @@ - (id)initWithFrame:(CGRect)frame \
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];
}
Expand Down
2 changes: 1 addition & 1 deletion src/video/uikit/SDL_uikitview.h
Expand Up @@ -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* */
Expand Down
1 change: 0 additions & 1 deletion src/video/uikit/SDL_uikitwindow.h
Expand Up @@ -43,7 +43,6 @@ struct SDL_WindowData
SDL_uikitviewcontroller *viewcontroller;
};


#endif /* _SDL_uikitwindow_h */

/* vi: set ts=4 sw=4 expandtab: */
6 changes: 5 additions & 1 deletion src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -55,7 +55,8 @@ - (void)loadView {
}

// 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];
Expand All @@ -79,8 +80,11 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
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);
}

Expand Down

0 comments on commit afb4098

Please sign in to comment.