/libs/cocos2d/CCTexture2D.m
Objective C | 562 lines | 384 code | 92 blank | 86 comment | 64 complexity | 998ccdb0c813dfdec7f0358282416d56 MD5 | raw file
Possible License(s): Apache-2.0
1/* 2 3===== IMPORTANT ===== 4 5This is sample code demonstrating API, technology or techniques in development. 6Although this sample code has been reviewed for technical accuracy, it is not 7final. Apple is supplying this information to help you plan for the adoption of 8the technologies and programming interfaces described herein. This information 9is subject to change, and software implemented based on this sample code should 10be tested with final operating system software and final documentation. Newer 11versions of this sample code may be provided with future seeds of the API or 12technology. For information about updates to this and other developer 13documentation, view the New & Updated sidebars in subsequent documentation 14seeds. 15 16===================== 17 18File: Texture2D.m 19Abstract: Creates OpenGL 2D textures from images or text. 20 21Version: 1.6 22 23Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. 24("Apple") in consideration of your agreement to the following terms, and your 25use, installation, modification or redistribution of this Apple software 26constitutes acceptance of these terms. If you do not agree with these terms, 27please do not use, install, modify or redistribute this Apple software. 28 29In consideration of your agreement to abide by the following terms, and subject 30to these terms, Apple grants you a personal, non-exclusive license, under 31Apple's copyrights in this original Apple software (the "Apple Software"), to 32use, reproduce, modify and redistribute the Apple Software, with or without 33modifications, in source and/or binary forms; provided that if you redistribute 34the Apple Software in its entirety and without modifications, you must retain 35this notice and the following text and disclaimers in all such redistributions 36of the Apple Software. 37Neither the name, trademarks, service marks or logos of Apple Inc. may be used 38to endorse or promote products derived from the Apple Software without specific 39prior written permission from Apple. Except as expressly stated in this notice, 40no other rights or licenses, express or implied, are granted by Apple herein, 41including but not limited to any patent rights that may be infringed by your 42derivative works or by other works in which the Apple Software may be 43incorporated. 44 45The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 46WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 47WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 48PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 49COMBINATION WITH YOUR PRODUCTS. 50 51IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 52CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 53GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR 55DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF 56CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 57APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 59Copyright (C) 2008 Apple Inc. All Rights Reserved. 60 61*/ 62 63/* 64 * Support for RGBA_4_4_4_4 and RGBA_5_5_5_1 was copied from: 65 * https://devforums.apple.com/message/37855#37855 by a1studmuffin 66 */ 67 68#import <OpenGLES/ES1/glext.h> 69 70#import "ccConfig.h" 71#import "ccMacros.h" 72#import "CCTexture2D.h" 73#import "CCPVRTexture.h" 74#import "CCConfiguration.h" 75#import "Support/ccUtils.h" 76 77 78#if CC_FONT_LABEL_SUPPORT 79// FontLabel support 80#import "FontManager.h" 81#import "FontLabelStringDrawing.h" 82#endif// CC_FONT_LABEL_SUPPORT 83 84 85//CLASS IMPLEMENTATIONS: 86 87 88// If the image has alpha, you can create RGBA8 (32-bit) or RGBA4 (16-bit) or RGB5A1 (16-bit) 89// Default is: RGBA8888 (32-bit textures) 90static CCTexture2DPixelFormat defaultAlphaPixelFormat_ = kCCTexture2DPixelFormat_Default; 91 92// By default PVR images are treated as if they don't have the alpha channel premultiplied 93static BOOL PVRHaveAlphaPremultiplied_ = NO; 94 95@implementation CCTexture2D 96 97@synthesize contentSize=size_, pixelFormat=format_, pixelsWide=width_, pixelsHigh=height_, name=name_, maxS=maxS_, maxT=maxT_; 98@synthesize hasPremultipliedAlpha=hasPremultipliedAlpha_; 99- (id) initWithData:(const void*)data pixelFormat:(CCTexture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size 100{ 101 if((self = [super init])) { 102 glGenTextures(1, &name_); 103 glBindTexture(GL_TEXTURE_2D, name_); 104 105 [self setAntiAliasTexParameters]; 106 107 // Specify OpenGL texture image 108 109 switch(pixelFormat) 110 { 111 case kCCTexture2DPixelFormat_RGBA8888: 112 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 113 break; 114 case kCCTexture2DPixelFormat_RGBA4444: 115 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, data); 116 break; 117 case kCCTexture2DPixelFormat_RGB5A1: 118 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, data); 119 break; 120 case kCCTexture2DPixelFormat_RGB565: 121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); 122 break; 123 case kCCTexture2DPixelFormat_A8: 124 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); 125 break; 126 default: 127 [NSException raise:NSInternalInconsistencyException format:@""]; 128 129 } 130 131 size_ = size; 132 width_ = width; 133 height_ = height; 134 format_ = pixelFormat; 135 maxS_ = size.width / (float)width; 136 maxT_ = size.height / (float)height; 137 138 hasPremultipliedAlpha_ = NO; 139 } 140 return self; 141} 142 143- (void) dealloc 144{ 145 CCLOGINFO(@"cocos2d: deallocing %@", self); 146 if(name_) 147 glDeleteTextures(1, &name_); 148 149 [super dealloc]; 150} 151 152- (NSString*) description 153{ 154 return [NSString stringWithFormat:@"<%@ = %08X | Name = %i | Dimensions = %ix%i | Coordinates = (%.2f, %.2f)>", [self class], self, name_, width_, height_, maxS_, maxT_]; 155} 156 157@end 158 159@implementation CCTexture2D (Image) 160 161- (id) initWithImage:(UIImage *)uiImage 162{ 163 NSUInteger POTWide, POTHigh; 164 CGImageRef CGImage; 165 CGContextRef context = nil; 166 void* data = nil;; 167 CGColorSpaceRef colorSpace; 168 void* tempData; 169 unsigned int* inPixel32; 170 unsigned short* outPixel16; 171 BOOL hasAlpha; 172 CGImageAlphaInfo info; 173 CGSize imageSize; 174 CCTexture2DPixelFormat pixelFormat; 175 176 CGImage = uiImage.CGImage; 177 178 if(CGImage == NULL) { 179 CCLOG(@"cocos2d: CCTexture2D. Can't create Texture. UIImage is nil"); 180 [self release]; 181 return nil; 182 } 183 184 CCConfiguration *conf = [CCConfiguration sharedConfiguration]; 185 186#if CC_TEXTURE_NPOT_SUPPORT 187 if( [conf supportsNPOT] ) { 188 POTWide = CGImageGetWidth(CGImage); 189 POTHigh = CGImageGetHeight(CGImage); 190 191 } else 192#endif 193 { 194 POTWide = ccNextPOT(CGImageGetWidth(CGImage)); 195 POTHigh = ccNextPOT(CGImageGetHeight(CGImage)); 196 } 197 198 unsigned maxTextureSize = [conf maxTextureSize]; 199 if( POTHigh > maxTextureSize || POTWide > maxTextureSize ) { 200 CCLOG(@"cocos2d: WARNING: Image (%d x %d) is bigger than the supported %d x %d", POTWide, POTHigh, maxTextureSize, maxTextureSize); 201 [self release]; 202 return nil; 203 } 204 205 info = CGImageGetAlphaInfo(CGImage); 206 hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO); 207 208 size_t bpp = CGImageGetBitsPerComponent(CGImage); 209 colorSpace = CGImageGetColorSpace(CGImage); 210 211 if(colorSpace) { 212 if(hasAlpha || bpp >= 8) 213 pixelFormat = defaultAlphaPixelFormat_; 214 else { 215 CCLOG(@"cocos2d: CCTexture2D: Using RGB565 texture since image has no alpha"); 216 pixelFormat = kCCTexture2DPixelFormat_RGB565; 217 } 218 } else { 219 // NOTE: No colorspace means a mask image 220 CCLOG(@"cocos2d: CCTexture2D: Using A8 texture since image is a mask"); 221 pixelFormat = kCCTexture2DPixelFormat_A8; 222 } 223 224 imageSize = CGSizeMake(CGImageGetWidth(CGImage), CGImageGetHeight(CGImage)); 225 226 // Create the bitmap graphics context 227 228 switch(pixelFormat) { 229 case kCCTexture2DPixelFormat_RGBA8888: 230 case kCCTexture2DPixelFormat_RGBA4444: 231 case kCCTexture2DPixelFormat_RGB5A1: 232 colorSpace = CGColorSpaceCreateDeviceRGB(); 233 data = malloc(POTHigh * POTWide * 4); 234 info = hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast; 235// info = kCGImageAlphaPremultipliedLast; // issue #886. This patch breaks BMP images. 236 context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big); 237 CGColorSpaceRelease(colorSpace); 238 break; 239 240 case kCCTexture2DPixelFormat_RGB565: 241 colorSpace = CGColorSpaceCreateDeviceRGB(); 242 data = malloc(POTHigh * POTWide * 4); 243 info = kCGImageAlphaNoneSkipLast; 244 context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big); 245 CGColorSpaceRelease(colorSpace); 246 break; 247 case kCCTexture2DPixelFormat_A8: 248 data = malloc(POTHigh * POTWide); 249 info = kCGImageAlphaOnly; 250 context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info); 251 break; 252 default: 253 [NSException raise:NSInternalInconsistencyException format:@"Invalid pixel format"]; 254 } 255 256 257 CGContextClearRect(context, CGRectMake(0, 0, POTWide, POTHigh)); 258 CGContextTranslateCTM(context, 0, POTHigh - imageSize.height); 259 CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(CGImage), CGImageGetHeight(CGImage)), CGImage); 260 261 // Repack the pixel data into the right format 262 263 if(pixelFormat == kCCTexture2DPixelFormat_RGB565) { 264 //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB" 265 tempData = malloc(POTHigh * POTWide * 2); 266 inPixel32 = (unsigned int*)data; 267 outPixel16 = (unsigned short*)tempData; 268 for(unsigned int i = 0; i < POTWide * POTHigh; ++i, ++inPixel32) 269 *outPixel16++ = ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) | ((((*inPixel32 >> 8) & 0xFF) >> 2) << 5) | ((((*inPixel32 >> 16) & 0xFF) >> 3) << 0); 270 free(data); 271 data = tempData; 272 273 } 274 else if (pixelFormat == kCCTexture2DPixelFormat_RGBA4444) { 275 //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRGGGGBBBBAAAA" 276 tempData = malloc(POTHigh * POTWide * 2); 277 inPixel32 = (unsigned int*)data; 278 outPixel16 = (unsigned short*)tempData; 279 for(unsigned int i = 0; i < POTWide * POTHigh; ++i, ++inPixel32) 280 *outPixel16++ = 281 ((((*inPixel32 >> 0) & 0xFF) >> 4) << 12) | // R 282 ((((*inPixel32 >> 8) & 0xFF) >> 4) << 8) | // G 283 ((((*inPixel32 >> 16) & 0xFF) >> 4) << 4) | // B 284 ((((*inPixel32 >> 24) & 0xFF) >> 4) << 0); // A 285 286 287 free(data); 288 data = tempData; 289 290 } 291 else if (pixelFormat == kCCTexture2DPixelFormat_RGB5A1) { 292 //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGBBBBBA" 293 tempData = malloc(POTHigh * POTWide * 2); 294 inPixel32 = (unsigned int*)data; 295 outPixel16 = (unsigned short*)tempData; 296 for(unsigned int i = 0; i < POTWide * POTHigh; ++i, ++inPixel32) 297 *outPixel16++ = 298 ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) | // R 299 ((((*inPixel32 >> 8) & 0xFF) >> 3) << 6) | // G 300 ((((*inPixel32 >> 16) & 0xFF) >> 3) << 1) | // B 301 ((((*inPixel32 >> 24) & 0xFF) >> 7) << 0); // A 302 303 304 free(data); 305 data = tempData; 306 } 307 self = [self initWithData:data pixelFormat:pixelFormat pixelsWide:POTWide pixelsHigh:POTHigh contentSize:imageSize]; 308 309 // should be after calling super init 310 hasPremultipliedAlpha_ = (info == kCGImageAlphaPremultipliedLast || info == kCGImageAlphaPremultipliedFirst); 311 312 CGContextRelease(context); 313 free(data); 314 315 return self; 316} 317@end 318 319@implementation CCTexture2D (Text) 320 321- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size 322{ 323 CGSize dim; 324 325#if CC_FONT_LABEL_SUPPORT 326 ZFont *zFont = [[FontManager sharedManager] zFontWithName:name pointSize:size]; 327 if (zFont != nil) 328 dim = [string sizeWithZFont:zFont]; 329 else 330#endif 331 dim = [string sizeWithFont:[UIFont fontWithName:name size:size]]; 332 333 return [self initWithString:string dimensions:dim alignment:UITextAlignmentCenter fontName:name fontSize:size]; 334} 335 336- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size 337{ 338 NSUInteger width, 339 height, 340 i; 341 CGContextRef context; 342 void* data; 343 CGColorSpaceRef colorSpace; 344 id uiFont; 345 346 width = dimensions.width; 347 if((width != 1) && (width & (width - 1))) { 348 i = 1; 349 while(i < width) 350 i *= 2; 351 width = i; 352 } 353 height = dimensions.height; 354 if((height != 1) && (height & (height - 1))) { 355 i = 1; 356 while(i < height) 357 i *= 2; 358 height = i; 359 } 360 361 colorSpace = CGColorSpaceCreateDeviceGray(); 362 data = calloc(height, width); 363 context = CGBitmapContextCreate(data, width, height, 8, width, colorSpace, kCGImageAlphaNone); 364 CGColorSpaceRelease(colorSpace); 365 366 367 CGContextSetGrayFillColor(context, 1.0f, 1.0f); 368 CGContextTranslateCTM(context, 0.0f, height); 369 CGContextScaleCTM(context, 1.0f, -1.0f); //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential 370 UIGraphicsPushContext(context); 371 372 373#if CC_FONT_LABEL_SUPPORT 374 uiFont = [[FontManager sharedManager] zFontWithName:name pointSize:size]; 375 if (uiFont != nil) 376 [string drawInRect:CGRectMake(0, 0, dimensions.width, dimensions.height) withZFont:uiFont lineBreakMode:UILineBreakModeWordWrap alignment:alignment]; 377 else 378#endif // CC_FONT_LABEL_SUPPORT 379 { 380 uiFont = [UIFont fontWithName:name size:size]; 381 [string drawInRect:CGRectMake(0, 0, dimensions.width, dimensions.height) withFont:uiFont lineBreakMode:UILineBreakModeWordWrap alignment:alignment]; 382 } 383 if( ! uiFont ) 384 CCLOG(@"cocos2d: Texture2D: Font '%@' not found", name); 385 UIGraphicsPopContext(); 386 387 self = [self initWithData:data pixelFormat:kCCTexture2DPixelFormat_A8 pixelsWide:width pixelsHigh:height contentSize:dimensions]; 388 389 CGContextRelease(context); 390 free(data); 391 392 return self; 393} 394 395@end 396 397@implementation CCTexture2D (Drawing) 398 399- (void) drawAtPoint:(CGPoint)point 400{ 401 GLfloat coordinates[] = { 0.0f, maxT_, 402 maxS_, maxT_, 403 0.0f, 0.0f, 404 maxS_, 0.0f }; 405 GLfloat width = (GLfloat)width_ * maxS_, 406 height = (GLfloat)height_ * maxT_; 407 408 GLfloat vertices[] = { point.x, point.y, 0.0f, 409 width + point.x, point.y, 0.0f, 410 point.x, height + point.y, 0.0f, 411 width + point.x, height + point.y, 0.0f }; 412 413 glBindTexture(GL_TEXTURE_2D, name_); 414 glVertexPointer(3, GL_FLOAT, 0, vertices); 415 glTexCoordPointer(2, GL_FLOAT, 0, coordinates); 416 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 417} 418 419 420- (void) drawInRect:(CGRect)rect 421{ 422 GLfloat coordinates[] = { 0.0f, maxT_, 423 maxS_, maxT_, 424 0.0f, 0.0f, 425 maxS_, 0.0f }; 426 GLfloat vertices[] = { rect.origin.x, rect.origin.y, /*0.0f,*/ 427 rect.origin.x + rect.size.width, rect.origin.y, /*0.0f,*/ 428 rect.origin.x, rect.origin.y + rect.size.height, /*0.0f,*/ 429 rect.origin.x + rect.size.width, rect.origin.y + rect.size.height, /*0.0f*/ }; 430 431 glBindTexture(GL_TEXTURE_2D, name_); 432 glVertexPointer(2, GL_FLOAT, 0, vertices); 433 glTexCoordPointer(2, GL_FLOAT, 0, coordinates); 434 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 435} 436 437@end 438 439@implementation CCTexture2D (PVR) 440-(id) initWithPVRTCData: (const void*)data level:(int)level bpp:(int)bpp hasAlpha:(BOOL)hasAlpha length:(int)length 441{ 442// GLint saveName; 443 444 if( ! [[CCConfiguration sharedConfiguration] supportsPVRTC] ) { 445 CCLOG(@"cocos2d: WARNING: PVRTC images is not supported"); 446 [self release]; 447 return nil; 448 } 449 450 if((self = [super init])) { 451 glGenTextures(1, &name_); 452 glBindTexture(GL_TEXTURE_2D, name_); 453 454 [self setAntiAliasTexParameters]; 455 456 GLenum format; 457 GLsizei size = length * length * bpp / 8; 458 if(hasAlpha) { 459 format = (bpp == 4) ? GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; 460 } else { 461 format = (bpp == 4) ? GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; 462 } 463 if(size < 32) { 464 size = 32; 465 } 466 glCompressedTexImage2D(GL_TEXTURE_2D, level, format, length, length, 0, size, data); 467 468 size_ = CGSizeMake(length, length); 469 width_ = length; 470 height_ = length; 471 maxS_ = 1.0f; 472 maxT_ = 1.0f; 473 hasPremultipliedAlpha_ = PVRHaveAlphaPremultiplied_; 474 } 475 return self; 476} 477 478-(id) initWithPVRFile: (NSString*) file 479{ 480 if( (self = [super init]) ) { 481 CCPVRTexture *pvr = [[CCPVRTexture alloc] initWithContentsOfFile:file]; 482 if( pvr ) { 483 pvr.retainName = YES; // don't dealloc texture on release 484 485 name_ = pvr.name; // texture id 486 maxS_ = 1; // only POT texture are supported 487 maxT_ = 1; 488 width_ = pvr.width; 489 height_ = pvr.height; 490 size_ = CGSizeMake(width_, height_); 491 hasPremultipliedAlpha_ = PVRHaveAlphaPremultiplied_; 492 493 [pvr release]; 494 495 [self setAntiAliasTexParameters]; 496 } else { 497 498 CCLOG(@"cocos2d: Couldn't load PVR image"); 499 [self release]; 500 return nil; 501 } 502 } 503 return self; 504} 505 506+(void) PVRImagesHavePremultipliedAlpha:(BOOL)haveAlphaPremultiplied 507{ 508 PVRHaveAlphaPremultiplied_ = haveAlphaPremultiplied; 509} 510@end 511 512// 513// Use to apply MIN/MAG filter 514// 515@implementation CCTexture2D (GLFilter) 516 517-(void) generateMipmap 518{ 519 NSAssert( width_ == ccNextPOT(width_) && height_ == ccNextPOT(height_), @"Mimpap texture only works in POT textures"); 520 glBindTexture( GL_TEXTURE_2D, name_ ); 521 glGenerateMipmapOES(GL_TEXTURE_2D); 522} 523 524-(void) setTexParameters: (ccTexParams*) texParams 525{ 526 NSAssert( (width_ == ccNextPOT(width_) && height_ == ccNextPOT(height_)) || 527 (texParams->wrapS == GL_CLAMP_TO_EDGE && texParams->wrapT == GL_CLAMP_TO_EDGE), 528 @"GL_CLAMP_TO_EDGE should be used in NPOT textures"); 529 glBindTexture( GL_TEXTURE_2D, self.name ); 530 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texParams->minFilter ); 531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams->magFilter ); 532 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams->wrapS ); 533 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams->wrapT ); 534} 535 536-(void) setAliasTexParameters 537{ 538 ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; 539 [self setTexParameters: &texParams]; 540} 541 542-(void) setAntiAliasTexParameters 543{ 544 ccTexParams texParams = { GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; 545 [self setTexParameters: &texParams]; 546} 547@end 548 549// 550// Texture options for images that contains alpha 551// 552@implementation CCTexture2D (PixelFormat) 553+(void) setDefaultAlphaPixelFormat:(CCTexture2DPixelFormat)format 554{ 555 defaultAlphaPixelFormat_ = format; 556} 557 558+(CCTexture2DPixelFormat) defaultAlphaPixelFormat 559{ 560 return defaultAlphaPixelFormat_; 561} 562@end