Fixed spacing
authorSam Lantinga <slouken@libsdl.org>
Tue, 01 Feb 2011 08:53:22 -0800
changeset 51295690ebc772c7
parent 5128 f2c2f0ecba5f
child 5130 ec13e48ee0d9
Fixed spacing
src/video/uikit/SDL_uikitopenglview.m
     1.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Sun Jan 30 13:42:05 2011 -0800
     1.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Tue Feb 01 08:53:22 2011 -0800
     1.3 @@ -37,128 +37,124 @@
     1.4  @synthesize context;
     1.5  
     1.6  + (Class)layerClass {
     1.7 -	return [CAEAGLLayer class];
     1.8 +    return [CAEAGLLayer class];
     1.9  }
    1.10  
    1.11  - (id)initWithFrame:(CGRect)frame \
    1.12 -	  retainBacking:(BOOL)retained \
    1.13 -	  rBits:(int)rBits \
    1.14 -	  gBits:(int)gBits \
    1.15 -	  bBits:(int)bBits \
    1.16 -	  aBits:(int)aBits \
    1.17 -	  depthBits:(int)depthBits \
    1.18 +      retainBacking:(BOOL)retained \
    1.19 +      rBits:(int)rBits \
    1.20 +      gBits:(int)gBits \
    1.21 +      bBits:(int)bBits \
    1.22 +      aBits:(int)aBits \
    1.23 +      depthBits:(int)depthBits \
    1.24  {
    1.25 -	
    1.26 -	NSString *colorFormat=nil;
    1.27 -	GLuint depthBufferFormat;
    1.28 -	BOOL useDepthBuffer;
    1.29 -	
    1.30 -	if (rBits == 8 && gBits == 8 && bBits == 8) {
    1.31 -		/* if user specifically requests rbg888 or some color format higher than 16bpp */
    1.32 -		colorFormat = kEAGLColorFormatRGBA8;
    1.33 -	}
    1.34 -	else {
    1.35 -		/* default case (faster) */
    1.36 -		colorFormat = kEAGLColorFormatRGB565;
    1.37 -	}
    1.38 -	
    1.39 -	if (depthBits == 24) {
    1.40 -		useDepthBuffer = YES;
    1.41 -		depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
    1.42 -	}
    1.43 -	else if (depthBits == 0) {
    1.44 -		useDepthBuffer = NO;
    1.45 -	}
    1.46 -	else {
    1.47 -		/* default case when depth buffer is not disabled */
    1.48 -		/* 
    1.49 -		   strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone.
    1.50 -		   perhaps that's the only depth format iPhone actually supports
    1.51 -		*/
    1.52 -		useDepthBuffer = YES;
    1.53 -		depthBufferFormat = GL_DEPTH_COMPONENT16_OES;
    1.54 -	}
    1.55 -	
    1.56 -	if ((self = [super initWithFrame:frame])) {
    1.57 -		// Get the layer
    1.58 -		CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
    1.59 -		
    1.60 -		eaglLayer.opaque = YES;
    1.61 -		eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
    1.62 -										[NSNumber numberWithBool: retained], kEAGLDrawablePropertyRetainedBacking, colorFormat, kEAGLDrawablePropertyColorFormat, nil];
    1.63 -		
    1.64 -		context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1];
    1.65 -		
    1.66 -		if (!context || ![EAGLContext setCurrentContext:context]) {
    1.67 -			[self release];
    1.68 -			return nil;
    1.69 -		}
    1.70 -		
    1.71 -		/* create the buffers */
    1.72 -		glGenFramebuffersOES(1, &viewFramebuffer);
    1.73 -		glGenRenderbuffersOES(1, &viewRenderbuffer);
    1.74 -		
    1.75 -		glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    1.76 -		glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    1.77 -		[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
    1.78 -		glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
    1.79 -		
    1.80 -		glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    1.81 -		glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
    1.82 -		
    1.83 -		if (useDepthBuffer) {
    1.84 -			glGenRenderbuffersOES(1, &depthRenderbuffer);
    1.85 -			glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
    1.86 -			glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight);
    1.87 -			glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    1.88 -		}
    1.89 -			
    1.90 -		if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
    1.91 -			return NO;
    1.92 -		}
    1.93 -		/* end create buffers */
    1.94 -	}
    1.95 -	return self;
    1.96 +    NSString *colorFormat=nil;
    1.97 +    GLuint depthBufferFormat;
    1.98 +    BOOL useDepthBuffer;
    1.99 +    
   1.100 +    if (rBits == 8 && gBits == 8 && bBits == 8) {
   1.101 +        /* if user specifically requests rbg888 or some color format higher than 16bpp */
   1.102 +        colorFormat = kEAGLColorFormatRGBA8;
   1.103 +    }
   1.104 +    else {
   1.105 +        /* default case (faster) */
   1.106 +        colorFormat = kEAGLColorFormatRGB565;
   1.107 +    }
   1.108 +    
   1.109 +    if (depthBits == 24) {
   1.110 +        useDepthBuffer = YES;
   1.111 +        depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
   1.112 +    }
   1.113 +    else if (depthBits == 0) {
   1.114 +        useDepthBuffer = NO;
   1.115 +    }
   1.116 +    else {
   1.117 +        /* default case when depth buffer is not disabled */
   1.118 +        /* 
   1.119 +           strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone.
   1.120 +           perhaps that's the only depth format iPhone actually supports
   1.121 +        */
   1.122 +        useDepthBuffer = YES;
   1.123 +        depthBufferFormat = GL_DEPTH_COMPONENT16_OES;
   1.124 +    }
   1.125 +    
   1.126 +    if ((self = [super initWithFrame:frame])) {
   1.127 +        // Get the layer
   1.128 +        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
   1.129 +        
   1.130 +        eaglLayer.opaque = YES;
   1.131 +        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
   1.132 +                                        [NSNumber numberWithBool: retained], kEAGLDrawablePropertyRetainedBacking, colorFormat, kEAGLDrawablePropertyColorFormat, nil];
   1.133 +        
   1.134 +        context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1];
   1.135 +        
   1.136 +        if (!context || ![EAGLContext setCurrentContext:context]) {
   1.137 +            [self release];
   1.138 +            return nil;
   1.139 +        }
   1.140 +        
   1.141 +        /* create the buffers */
   1.142 +        glGenFramebuffersOES(1, &viewFramebuffer);
   1.143 +        glGenRenderbuffersOES(1, &viewRenderbuffer);
   1.144 +        
   1.145 +        glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
   1.146 +        glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
   1.147 +        [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
   1.148 +        glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
   1.149 +        
   1.150 +        glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
   1.151 +        glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
   1.152 +        
   1.153 +        if (useDepthBuffer) {
   1.154 +            glGenRenderbuffersOES(1, &depthRenderbuffer);
   1.155 +            glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
   1.156 +            glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight);
   1.157 +            glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
   1.158 +        }
   1.159 +            
   1.160 +        if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
   1.161 +            return NO;
   1.162 +        }
   1.163 +        /* end create buffers */
   1.164 +    }
   1.165 +    return self;
   1.166  }
   1.167  
   1.168  - (void)setCurrentContext {
   1.169 -	[EAGLContext setCurrentContext:context];
   1.170 +    [EAGLContext setCurrentContext:context];
   1.171  }
   1.172  
   1.173  
   1.174  - (void)swapBuffers {
   1.175 -	glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
   1.176 -	[context presentRenderbuffer:GL_RENDERBUFFER_OES];
   1.177 +    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
   1.178 +    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
   1.179  }
   1.180  
   1.181  
   1.182  - (void)layoutSubviews {
   1.183 -	[EAGLContext setCurrentContext:context];
   1.184 +    [EAGLContext setCurrentContext:context];
   1.185  }
   1.186  
   1.187  - (void)destroyFramebuffer {
   1.188 -	
   1.189 -	glDeleteFramebuffersOES(1, &viewFramebuffer);
   1.190 -	viewFramebuffer = 0;
   1.191 -	glDeleteRenderbuffersOES(1, &viewRenderbuffer);
   1.192 -	viewRenderbuffer = 0;
   1.193 -	
   1.194 -	if (depthRenderbuffer) {
   1.195 -		glDeleteRenderbuffersOES(1, &depthRenderbuffer);
   1.196 -		depthRenderbuffer = 0;
   1.197 -	}
   1.198 +    glDeleteFramebuffersOES(1, &viewFramebuffer);
   1.199 +    viewFramebuffer = 0;
   1.200 +    glDeleteRenderbuffersOES(1, &viewRenderbuffer);
   1.201 +    viewRenderbuffer = 0;
   1.202 +    
   1.203 +    if (depthRenderbuffer) {
   1.204 +        glDeleteRenderbuffersOES(1, &depthRenderbuffer);
   1.205 +        depthRenderbuffer = 0;
   1.206 +    }
   1.207  }
   1.208  
   1.209  
   1.210  - (void)dealloc {
   1.211 -		
   1.212 -	[self destroyFramebuffer];
   1.213 -	if ([EAGLContext currentContext] == context) {
   1.214 -		[EAGLContext setCurrentContext:nil];
   1.215 -	}
   1.216 -	[context release];	
   1.217 -	[super dealloc];
   1.218 -	
   1.219 +    [self destroyFramebuffer];
   1.220 +    if ([EAGLContext currentContext] == context) {
   1.221 +        [EAGLContext setCurrentContext:nil];
   1.222 +    }
   1.223 +    [context release];    
   1.224 +    [super dealloc];
   1.225  }
   1.226  
   1.227  @end