Permalink
Browse files

Retina support for EPGLTransitionView

  • Loading branch information...
1 parent 4bbb3f2 commit 6f975e0649f674243f957d50087659d7bede6554 @Remint Remint committed Dec 22, 2011
Oops, something went wrong.
@@ -36,26 +36,44 @@ + (Class)layerClass
return [CAEAGLLayer class];
}
+- (UIImage *)imageWithView:(UIView *)view
+{
+ UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, view.contentScaleFactor); //Retina support
+ [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;
+
+ //Retina support
+ CGFloat contentScale = view.contentScaleFactor;
+ 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 +86,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 +134,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 +182,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 6f975e0

Please sign in to comment.