Permalink
Browse files

Merge Alterplay changes

  • Loading branch information...
2 parents 4bbb3f2 + 18625da commit f6346fa47da9e5f1437d04af02a38150c9f5150f @epatel committed Jan 6, 2012
Showing with 36 additions and 13 deletions.
  1. +36 −13 src/EPGLTransitionView.m
View
@@ -36,26 +36,49 @@ + (Class)layerClass
return [CAEAGLLayer class];
}
+- (UIImage *)imageWithView:(UIView *)view
+{
+ if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
+ UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]); //Retina support
+ else
+ UIGraphicsBeginImageContext(view.bounds.size);
+ [view.layer renderInContext:UIGraphicsGetCurrentContext()];
+ UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ return img;
+}
+
- (id)initWithView:(UIView*)view
delegate:(id<EPGLTransitionViewDelegate>)_delegate;
{
if ((self = [super initWithFrame:view.frame])) {
maxTextureSize = 512;
- size = view.bounds.size;
- if (size.height > 512 || size.width > 512) // Big screen? iPad!
- maxTextureSize = 1024;
+ size = UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? view.bounds.size : CGSizeMake(view.bounds.size.height, view.bounds.size.width);
+
+ //Retina support
+ if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
+ CGFloat contentScale = [[UIScreen mainScreen] scale];
+ size.width *= contentScale;
+ size.height *= contentScale;
+ self.contentScaleFactor = contentScale;
+ }
+
+ maxTextureSize = 512;
+
+ while (size.height > maxTextureSize || size.width > maxTextureSize) {
+ maxTextureSize *= 2; // properly setup maxTextureSize size for iPhone & future iPad Retina screen
+ }
+
delegate = _delegate;
[delegate retain];
[self setClearColorRed:0.0
green:0.0
blue:0.0
alpha:0.0];
- // Get a image of the screen
- UIGraphicsBeginImageContext(view.bounds.size);
- [view.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
+
+ UIImage *image = [self imageWithView:view];
// Allocate some memory for the texture
GLubyte *textureData = (GLubyte*)calloc(maxTextureSize*4, maxTextureSize);
@@ -68,6 +91,7 @@ - (id)initWithView:(UIView*)view
maxTextureSize*4,
CGImageGetColorSpace(image.CGImage),
kCGImageAlphaPremultipliedLast);
+
CGContextDrawImage(textureContext,
CGRectMake(0, maxTextureSize-size.height, size.width, size.height),
image.CGImage);
@@ -115,7 +139,8 @@ - (id)initWithView:(UIView*)view
GL_RENDERBUFFER_OES,
depthRenderbuffer);
- glViewport(0, 0, view.frame.size.width, view.frame.size.height);
+
+ glViewport(0, 0, size.width, size.height);
glEnable(GL_DEPTH_TEST);
@@ -162,10 +187,8 @@ - (void)prepareTextureTo:(UIView*)view
break;
}
view.bounds = r;
- UIGraphicsBeginImageContext(view.bounds.size);
- [view.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
+
+ UIImage *image = [self imageWithView:view];
// Allocate some memory for the texture
GLubyte *textureData = (GLubyte*)calloc(maxTextureSize*4, maxTextureSize);

0 comments on commit f6346fa

Please sign in to comment.