Skip to content

Commit fed1125

Browse files
author
Thayer J Andrews
committed
Merge remote-tracking branch 'upstream/develop' into develop
2 parents 5cbb74b + 2267752 commit fed1125

File tree

7 files changed

+72
-7
lines changed

7 files changed

+72
-7
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.1
1+
3.2.0

cocos2d/CCConfiguration.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ typedef NS_ENUM(NSUInteger, CCDevice) {
7575

7676
GLint _maxTextureSize;
7777
BOOL _supportsPVRTC;
78+
BOOL _supportsNPOT;
7879
BOOL _supportsBGRA8888;
7980
BOOL _supportsDiscardFramebuffer;
8081
BOOL _supportsShareableVAO;
@@ -91,6 +92,12 @@ typedef NS_ENUM(NSUInteger, CCDevice) {
9192
*/
9293
@property (nonatomic, readonly) GLint maxTextureUnits;
9394

95+
/** Whether or not the GPU supports NPOT (Non Power Of Two) textures.
96+
OpenGL ES 2.0 already supports NPOT (iOS).
97+
98+
*/
99+
@property (nonatomic, readonly) BOOL supportsNPOT;
100+
94101
/** Whether or not PVR Texture Compressed is supported */
95102
@property (nonatomic, readonly) BOOL supportsPVRTC;
96103

cocos2d/CCConfiguration.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ @implementation CCConfiguration
4444

4545
@synthesize maxTextureSize = _maxTextureSize, maxTextureUnits=_maxTextureUnits;
4646
@synthesize supportsPVRTC = _supportsPVRTC;
47+
@synthesize supportsNPOT = _supportsNPOT;
4748
@synthesize supportsBGRA8888 = _supportsBGRA8888;
4849
@synthesize supportsDiscardFramebuffer = _supportsDiscardFramebuffer;
4950
@synthesize supportsShareableVAO = _supportsShareableVAO;
@@ -181,6 +182,12 @@ -(void) getOpenGLvariables
181182
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maxTextureSize);
182183
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_maxTextureUnits );
183184

185+
#ifdef __CC_PLATFORM_IOS
186+
_supportsNPOT = YES;
187+
#elif defined(__CC_PLATFORM_MAC)
188+
_supportsNPOT = [self checkForGLExtension:@"GL_ARB_texture_non_power_of_two"];
189+
#endif
190+
184191
_supportsPVRTC = [self checkForGLExtension:@"GL_IMG_texture_compression_pvrtc"];
185192

186193
// It seems that somewhere between firmware iOS 3.0 and 4.2 Apple renamed
@@ -215,6 +222,14 @@ -(GLint) maxTextureUnits
215222
return _maxTextureUnits;
216223
}
217224

225+
-(BOOL) supportsNPOT
226+
{
227+
if( ! _openGLInitialized )
228+
[self getOpenGLvariables];
229+
230+
return _supportsNPOT;
231+
}
232+
218233
-(BOOL) supportsPVRTC
219234
{
220235
if( ! _openGLInitialized )
@@ -293,6 +308,7 @@ -(void) dumpInfo
293308
printf("cocos2d: GL_MAX_SAMPLES: %d\n", _maxSamplesAllowed);
294309
printf("cocos2d: GL supports PVRTC: %s\n", (_supportsPVRTC ? "YES" : "NO") );
295310
printf("cocos2d: GL supports BGRA8888 textures: %s\n", (_supportsBGRA8888 ? "YES" : "NO") );
311+
printf("cocos2d: GL supports NPOT textures: %s\n", (_supportsNPOT ? "YES" : "NO") );
296312
printf("cocos2d: GL supports discard_framebuffer: %s\n", (_supportsDiscardFramebuffer ? "YES" : "NO") );
297313
printf("cocos2d: GL supports shareable VAO: %s\n", (_supportsShareableVAO ? "YES" : "NO") );
298314

cocos2d/CCEffectRenderer.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,26 @@ - (BOOL)setupGLResourcesWithSize:(CGSize)size
5252

5353
glPushGroupMarkerEXT(0, "CCEffectRenderTarget: allocateRenderTarget");
5454

55+
// Textures may need to be a power of two
56+
NSUInteger powW;
57+
NSUInteger powH;
58+
59+
if( [[CCConfiguration sharedConfiguration] supportsNPOT] )
60+
{
61+
powW = size.width;
62+
powH = size.height;
63+
}
64+
else
65+
{
66+
powW = CCNextPOT(size.width);
67+
powH = CCNextPOT(size.height);
68+
}
69+
5570
static const CCTexturePixelFormat kRenderTargetDefaultPixelFormat = CCTexturePixelFormat_RGBA8888;
5671

5772
// Create a new texture object for use as the color attachment of the new
5873
// FBO.
59-
_texture = [[CCTexture alloc] initWithData:nil pixelFormat:kRenderTargetDefaultPixelFormat pixelsWide:size.width pixelsHigh:size.height contentSizeInPixels:size contentScale:[CCDirector sharedDirector].contentScaleFactor];
74+
_texture = [[CCTexture alloc] initWithData:nil pixelFormat:kRenderTargetDefaultPixelFormat pixelsWide:powW pixelsHigh:powH contentSizeInPixels:size contentScale:[CCDirector sharedDirector].contentScaleFactor];
6075
[_texture setAliasTexParameters];
6176

6277
// Save the old FBO binding so it can be restored after we create the new

cocos2d/CCRenderTexture.m

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,21 @@ -(void)create
177177

178178
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
179179

180-
void *data = calloc(pixelW*pixelH, 4);
181-
CCTexture *texture = [[CCTexture alloc] initWithData:data pixelFormat:_pixelFormat pixelsWide:pixelW pixelsHigh:pixelH contentSizeInPixels:CGSizeMake(pixelW, pixelH) contentScale:_contentScale];
180+
// textures must be power of two
181+
NSUInteger powW;
182+
NSUInteger powH;
183+
184+
if( [[CCConfiguration sharedConfiguration] supportsNPOT] ) {
185+
powW = pixelW;
186+
powH = pixelH;
187+
} else {
188+
powW = CCNextPOT(pixelW);
189+
powH = CCNextPOT(pixelH);
190+
}
191+
192+
void *data = calloc(powW*powH, 4);
193+
194+
CCTexture *texture = [[CCTexture alloc] initWithData:data pixelFormat:_pixelFormat pixelsWide:powW pixelsHigh:powH contentSizeInPixels:CGSizeMake(pixelW, pixelH) contentScale:_contentScale];
182195
self.texture = texture;
183196

184197
free(data);
@@ -199,7 +212,7 @@ -(void)create
199212
//create and attach depth buffer
200213
glGenRenderbuffers(1, &depthRenderBuffer);
201214
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderBuffer);
202-
glRenderbufferStorage(GL_RENDERBUFFER, _depthStencilFormat, (GLsizei)pixelW, (GLsizei)pixelH);
215+
glRenderbufferStorage(GL_RENDERBUFFER, _depthStencilFormat, (GLsizei)powW, (GLsizei)powH);
203216
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderBuffer);
204217

205218
// if depth format is the one with stencil part, bind same render buffer as stencil attachment

cocos2d/CCTexture.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,16 @@ - (id) initWithCGImage:(CGImageRef)cgImage contentScale:(CGFloat)contentScale
399399
pixelFormat = CCTexturePixelFormat_A8;
400400
}
401401

402-
textureWidth = CGImageGetWidth(cgImage);
403-
textureHeight = CGImageGetHeight(cgImage);
402+
if( ! [conf supportsNPOT] )
403+
{
404+
textureWidth = CCNextPOT(CGImageGetWidth(cgImage));
405+
textureHeight = CCNextPOT(CGImageGetHeight(cgImage));
406+
}
407+
else
408+
{
409+
textureWidth = CGImageGetWidth(cgImage);
410+
textureHeight = CGImageGetHeight(cgImage);
411+
}
404412

405413
#ifdef __CC_PLATFORM_IOS
406414

cocos2d/CCTexturePVR.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ - (BOOL)unpackPVRv2Data:(unsigned char*)data PVRLen:(NSUInteger)len
299299
if( flipped )
300300
CCLOGWARN(@"cocos2d: WARNING: Image is flipped. Regenerate it using PVRTexTool");
301301

302+
if( ! [configuration supportsNPOT] &&
303+
( header->width != CCNextPOT(header->width) || header->height != CCNextPOT(header->height ) ) ) {
304+
CCLOGWARN(@"cocos2d: ERROR: Loding an NPOT texture (%dx%d) but is not supported on this device", header->width, header->height);
305+
return NO;
306+
}
307+
302308
for( NSUInteger i=0; i < (unsigned int)PVR2_MAX_TABLE_ELEMENTS ; i++) {
303309
if( v2_pixel_formathash[i].pixelFormat == formatFlags ) {
304310

0 commit comments

Comments
 (0)