Permalink
Browse files

some fixes

  • Loading branch information...
1 parent 6598883 commit ca30689143294cf9e744b2217fefe29a144ae557 @ricardoquesada committed Apr 10, 2012
Showing with 50 additions and 32 deletions.
  1. +2 −2 test-memory/HelloWorldLayer.m
  2. +41 −29 test-memory/libs/cocos2d/CCTexture2D.m
  3. +7 −1 test-memory/libs/cocos2d/CCTexturePVR.m
@@ -47,9 +47,9 @@ -(id) init
// CCSprite *sprite = [CCSprite spriteWithFile:@"texture2048x2048_rgba4444.pvr"];
// CCSprite *sprite = [CCSprite spriteWithFile:@"texture2048x2048_rgb888.pvr"];
// CCSprite *sprite = [CCSprite spriteWithFile:@"texture2047x2047_rgba8888.pvr"];
-// CCSprite *sprite = [CCSprite spriteWithFile:@"texture2047x2047_rgba8888.png"];
+ CCSprite *sprite = [CCSprite spriteWithFile:@"texture2047x2047_rgba8888.png"];
// CCSprite *sprite = [CCSprite spriteWithFile:@"texture1536x1536_rgba8888.png"];
- CCSprite *sprite = [CCSprite spriteWithFile:@"texture1025x1025_rgba8888.png"];
+// CCSprite *sprite = [CCSprite spriteWithFile:@"texture1025x1025_rgba8888.png"];
[sprite setPosition:ccp( s.width/2, s.height/2)];
[sprite setScale:0.25f];
@@ -116,11 +116,17 @@ @implementation CCTexture2D
- (id) initWithData:(const void*)data pixelFormat:(CCTexture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size
{
if((self = [super init])) {
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
+
+// glPixelStorei(GL_UNPACK_ALIGNMENT,1);
+//
glGenTextures(1, &name_);
ccGLBindTexture2D( name_ );
- [self setAntiAliasTexParameters];
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+
// Specify OpenGL texture image
@@ -267,22 +273,25 @@ - (id) initWithCGImage:(CGImageRef)cgImage
colorSpace = CGImageGetColorSpace(cgImage);
if(colorSpace) {
- if( hasAlpha ) {
- pixelFormat = defaultAlphaPixelFormat_;
- info = kCGImageAlphaPremultipliedLast;
- }
- else
- {
- info = kCGImageAlphaNoneSkipLast;
-
- if( bpp >= 8 )
- pixelFormat = kCCTexture2DPixelFormat_RGB888;
- else
- pixelFormat = kCCTexture2DPixelFormat_RGB565;
-
- CCLOG(@"cocos2d: CCTexture2D: Using %@ texture since image has no alpha", (bpp>=8) ? @"RGB888" : @"RGB565" );
-
- }
+ pixelFormat = defaultAlphaPixelFormat_;
+ info = kCGImageAlphaPremultipliedLast;
+
+// if( hasAlpha ) {
+// pixelFormat = defaultAlphaPixelFormat_;
+// info = kCGImageAlphaPremultipliedLast;
+// }
+// else
+// {
+// info = kCGImageAlphaNoneSkipLast;
+//
+// if( bpp >= 8 )
+// pixelFormat = kCCTexture2DPixelFormat_RGB888;
+// else
+// pixelFormat = kCCTexture2DPixelFormat_RGB565;
+//
+// CCLOG(@"cocos2d: CCTexture2D: Using %@ texture since image has no alpha", (bpp>=8) ? @"RGB888" : @"RGB565" );
+//
+// }
} else {
// NOTE: No colorspace means a mask image
CCLOG(@"cocos2d: CCTexture2D: Using A8 texture since image is a mask");
@@ -299,7 +308,9 @@ - (id) initWithCGImage:(CGImageRef)cgImage
case kCCTexture2DPixelFormat_RGB5A1:
case kCCTexture2DPixelFormat_RGB565:
case kCCTexture2DPixelFormat_RGB888:
- colorSpace = CGColorSpaceCreateDeviceRGB();
+ colorSpace = CGColorSpaceCreateDeviceRGB();
+ int malloc_size = POTHigh * POTWide * 4;
+ NSLog(@"Additional malloc: %d", malloc_size);
data = malloc(POTHigh * POTWide * 4);
// info = hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast;
// info = kCGImageAlphaPremultipliedLast; // issue #886. This patch breaks BMP images.
@@ -676,7 +687,8 @@ -(id) initWithPVRFile: (NSString*) relPath
[pvr release];
- [self setAntiAliasTexParameters];
+
+// [self setAntiAliasTexParameters];
} else {
CCLOG(@"cocos2d: Couldn't load PVR image: %@", relPath);
@@ -780,15 +792,15 @@ -(void) generateMipmap
-(void) setTexParameters: (ccTexParams*) texParams
{
- NSAssert( (width_ == ccNextPOT(width_) && height_ == ccNextPOT(height_)) ||
- (texParams->wrapS == GL_CLAMP_TO_EDGE && texParams->wrapT == GL_CLAMP_TO_EDGE),
- @"GL_CLAMP_TO_EDGE should be used in NPOT textures");
-
- ccGLBindTexture2D( name_ );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texParams->minFilter );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams->magFilter );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams->wrapS );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams->wrapT );
+// NSAssert( (width_ == ccNextPOT(width_) && height_ == ccNextPOT(height_)) ||
+// (texParams->wrapS == GL_CLAMP_TO_EDGE && texParams->wrapT == GL_CLAMP_TO_EDGE),
+// @"GL_CLAMP_TO_EDGE should be used in NPOT textures");
+//
+// ccGLBindTexture2D( name_ );
+// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texParams->minFilter );
+// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams->magFilter );
+// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams->wrapS );
+// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams->wrapT );
}
-(void) setAliasTexParameters
@@ -296,9 +296,15 @@ - (BOOL)createGLTexture
if (name_ != 0)
ccGLDeleteTexture( name_ );
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, &name_);
ccGLBindTexture2D( name_ );
+
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT,1);
}

0 comments on commit ca30689

Please sign in to comment.