Skip to content

Commit 4fe88cd

Browse files
committed
GL free configuration.
1 parent 42aa954 commit 4fe88cd

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

cocos2d/CCConfiguration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ typedef NS_ENUM(NSUInteger, CCGraphicsAPI) {
111111
@interface CCConfiguration : NSObject {
112112
CCGraphicsAPI _graphicsAPI;
113113

114+
BOOL _configured;
114115
BOOL _openGLInitialized;
115116

116117
GLint _maxTextureSize;

cocos2d/CCConfiguration.m

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ -(NSInteger) runningDevice
208208

209209
#pragma mark OpenGL getters
210210

211-
/** OpenGL Max texture size. */
212-
213211
-(void) getOpenGLvariables
214212
{
215213
if( ! _openGLInitialized ) {
@@ -256,79 +254,92 @@ -(void) getOpenGLvariables
256254

257255
_supportsShareableVAO = [self checkForGLExtension:@"GL_APPLE_vertex_array_object"];
258256

259-
_openGLInitialized = YES;
260-
261257
// Check if unsynchronized buffers are supported.
262258
if(
263259
[self checkForGLExtension:@"GL_OES_mapbuffer"] &&
264260
[self checkForGLExtension:@"GL_EXT_map_buffer_range"]
265261
){
266262
CCGraphicsBufferClass = NSClassFromString(@"CCGraphicsBufferGLUnsynchronized");
267263
}
264+
265+
_openGLInitialized = YES;
268266
});
269267
}
270268
}
271269

270+
/// Cache the current device configuration if it hasn't already been done.
271+
/// The naming here is admittedly terrible and generic but I couldn't think of something better.
272+
-(void)configure
273+
{
274+
if(!_configured){
275+
switch(self.graphicsAPI){
276+
case CCGraphicsAPIGL:
277+
[self getOpenGLvariables];
278+
break;
279+
case CCGraphicsAPIMetal:
280+
// TODO Hard coding these for now... Does the Metal API even expose any queries for limits?
281+
_maxTextureSize = 4096;
282+
_supportsPVRTC = YES;
283+
_supportsNPOT = YES;
284+
_supportsBGRA8888 = YES;
285+
_supportsDiscardFramebuffer = NO;
286+
_supportsShareableVAO = NO;
287+
_maxSamplesAllowed = 4;
288+
_maxTextureUnits = 10;
289+
_supportsPackedDepthStencil = YES;
290+
break;
291+
default: NSAssert(NO, @"Internal Error: Graphics API not set up?");
292+
}
293+
294+
_configured = YES;
295+
}
296+
}
297+
272298
-(GLint) maxTextureSize
273299
{
274-
if( ! _openGLInitialized )
275-
[self getOpenGLvariables];
300+
[self configure];
276301
return _maxTextureSize;
277302
}
278303

279304
-(GLint) maxTextureUnits
280305
{
281-
if( ! _openGLInitialized )
282-
[self getOpenGLvariables];
283-
306+
[self configure];
284307
return _maxTextureUnits;
285308
}
286309

287310
-(BOOL) supportsNPOT
288311
{
289-
if( ! _openGLInitialized )
290-
[self getOpenGLvariables];
291-
312+
[self configure];
292313
return _supportsNPOT;
293314
}
294315

295316
-(BOOL) supportsPVRTC
296317
{
297-
if( ! _openGLInitialized )
298-
[self getOpenGLvariables];
299-
318+
[self configure];
300319
return _supportsPVRTC;
301320
}
302321

303322
-(BOOL) supportsPackedDepthStencil
304323
{
305-
if( ! _openGLInitialized )
306-
[self getOpenGLvariables];
307-
308-
return _supportsPackedDepthStencil;
324+
[self configure];
325+
return _supportsPackedDepthStencil;
309326
}
310327

311328
-(BOOL) supportsBGRA8888
312329
{
313-
if( ! _openGLInitialized )
314-
[self getOpenGLvariables];
315-
330+
[self configure];
316331
return _supportsBGRA8888;
317332
}
318333

319334
-(BOOL) supportsDiscardFramebuffer
320335
{
321-
if( ! _openGLInitialized )
322-
[self getOpenGLvariables];
323-
336+
[self configure];
324337
return _supportsDiscardFramebuffer;
325338
}
326339

327340
-(BOOL) supportsShareableVAO
328341
{
329-
if( ! _openGLInitialized )
330-
[self getOpenGLvariables];
331-
342+
[self configure];
332343
return _supportsShareableVAO;
333344
}
334345

0 commit comments

Comments
 (0)