summary refs log tree commit diff stats
path: root/libs/cocos2d/CCConfiguration.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/CCConfiguration.m
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/CCConfiguration.m')
-rwxr-xr-xlibs/cocos2d/CCConfiguration.m193
1 files changed, 193 insertions, 0 deletions
diff --git a/libs/cocos2d/CCConfiguration.m b/libs/cocos2d/CCConfiguration.m new file mode 100755 index 0000000..d51cd58 --- /dev/null +++ b/libs/cocos2d/CCConfiguration.m
@@ -0,0 +1,193 @@
1/*
2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
3 *
4 * Copyright (c) 2010 Ricardo Quesada
5 * Copyright (c) 2011 Zynga Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26#import <Availability.h>
27
28#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
29#import <UIKit/UIKit.h> // Needed for UIDevice
30#endif
31
32#import "Platforms/CCGL.h"
33#import "CCBlockSupport.h"
34#import "CCConfiguration.h"
35#import "ccMacros.h"
36#import "ccConfig.h"
37#import "Support/OpenGL_Internal.h"
38
39@implementation CCConfiguration
40
41@synthesize maxTextureSize = maxTextureSize_;
42@synthesize supportsPVRTC = supportsPVRTC_;
43@synthesize maxModelviewStackDepth = maxModelviewStackDepth_;
44@synthesize supportsNPOT = supportsNPOT_;
45@synthesize supportsBGRA8888 = supportsBGRA8888_;
46@synthesize supportsDiscardFramebuffer = supportsDiscardFramebuffer_;
47@synthesize OSVersion = OSVersion_;
48
49//
50// singleton stuff
51//
52static CCConfiguration *_sharedConfiguration = nil;
53
54static char * glExtensions;
55
56+ (CCConfiguration *)sharedConfiguration
57{
58 if (!_sharedConfiguration)
59 _sharedConfiguration = [[self alloc] init];
60
61 return _sharedConfiguration;
62}
63
64+(id)alloc
65{
66 NSAssert(_sharedConfiguration == nil, @"Attempted to allocate a second instance of a singleton.");
67 return [super alloc];
68}
69
70
71#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
72#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
73- (NSString*)getMacVersion
74{
75 SInt32 versionMajor, versionMinor, versionBugFix;
76 Gestalt(gestaltSystemVersionMajor, &versionMajor);
77 Gestalt(gestaltSystemVersionMinor, &versionMinor);
78 Gestalt(gestaltSystemVersionBugFix, &versionBugFix);
79
80 return [NSString stringWithFormat:@"%d.%d.%d", versionMajor, versionMinor, versionBugFix];
81}
82#endif // __MAC_OS_X_VERSION_MAX_ALLOWED
83
84-(id) init
85{
86 if( (self=[super init])) {
87
88 // Obtain iOS version
89 OSVersion_ = 0;
90#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
91 NSString *OSVer = [[UIDevice currentDevice] systemVersion];
92#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
93 NSString *OSVer = [self getMacVersion];
94#endif
95 NSArray *arr = [OSVer componentsSeparatedByString:@"."];
96 int idx=0x01000000;
97 for( NSString *str in arr ) {
98 int value = [str intValue];
99 OSVersion_ += value * idx;
100 idx = idx >> 8;
101 }
102 CCLOG(@"cocos2d: OS version: %@ (0x%08x)", OSVer, OSVersion_);
103
104 CCLOG(@"cocos2d: GL_VENDOR: %s", glGetString(GL_VENDOR) );
105 CCLOG(@"cocos2d: GL_RENDERER: %s", glGetString ( GL_RENDERER ) );
106 CCLOG(@"cocos2d: GL_VERSION: %s", glGetString ( GL_VERSION ) );
107
108 glExtensions = (char*) glGetString(GL_EXTENSIONS);
109
110 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize_);
111 glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &maxModelviewStackDepth_);
112#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
113 if( OSVersion_ >= kCCiOSVersion_4_0 )
114 glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed_);
115 else
116 maxSamplesAllowed_ = 0;
117#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
118 glGetIntegerv(GL_MAX_SAMPLES, &maxSamplesAllowed_);
119#endif
120
121 supportsPVRTC_ = [self checkForGLExtension:@"GL_IMG_texture_compression_pvrtc"];
122#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
123 supportsNPOT_ = [self checkForGLExtension:@"GL_APPLE_texture_2D_limited_npot"];
124#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
125 supportsNPOT_ = [self checkForGLExtension:@"GL_ARB_texture_non_power_of_two"];
126#endif
127 // It seems that somewhere between firmware iOS 3.0 and 4.2 Apple renamed
128 // GL_IMG_... to GL_APPLE.... So we should check both names
129
130#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
131 BOOL bgra8a = [self checkForGLExtension:@"GL_IMG_texture_format_BGRA8888"];
132 BOOL bgra8b = [self checkForGLExtension:@"GL_APPLE_texture_format_BGRA8888"];
133 supportsBGRA8888_ = bgra8a | bgra8b;
134#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
135 supportsBGRA8888_ = [self checkForGLExtension:@"GL_EXT_bgra"];
136#endif
137
138 supportsDiscardFramebuffer_ = [self checkForGLExtension:@"GL_EXT_discard_framebuffer"];
139
140 CCLOG(@"cocos2d: GL_MAX_TEXTURE_SIZE: %d", maxTextureSize_);
141 CCLOG(@"cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: %d",maxModelviewStackDepth_);
142 CCLOG(@"cocos2d: GL_MAX_SAMPLES: %d", maxSamplesAllowed_);
143 CCLOG(@"cocos2d: GL supports PVRTC: %s", (supportsPVRTC_ ? "YES" : "NO") );
144 CCLOG(@"cocos2d: GL supports BGRA8888 textures: %s", (supportsBGRA8888_ ? "YES" : "NO") );
145 CCLOG(@"cocos2d: GL supports NPOT textures: %s", (supportsNPOT_ ? "YES" : "NO") );
146 CCLOG(@"cocos2d: GL supports discard_framebuffer: %s", (supportsDiscardFramebuffer_ ? "YES" : "NO") );
147 CCLOG(@"cocos2d: compiled with NPOT support: %s",
148#if CC_TEXTURE_NPOT_SUPPORT
149 "YES"
150#else
151 "NO"
152#endif
153 );
154 CCLOG(@"cocos2d: compiled with VBO support in TextureAtlas : %s",
155#if CC_USES_VBO
156 "YES"
157#else
158 "NO"
159#endif
160 );
161
162 CCLOG(@"cocos2d: compiled with Affine Matrix transformation in CCNode : %s",
163#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
164 "YES"
165#else
166 "NO"
167#endif
168 );
169
170 CCLOG(@"cocos2d: compiled with Profiling Support: %s",
171#if CC_ENABLE_PROFILERS
172
173 "YES - *** Disable it when you finish profiling ***"
174#else
175 "NO"
176#endif
177 );
178
179 CHECK_GL_ERROR();
180 }
181
182 return self;
183}
184
185- (BOOL) checkForGLExtension:(NSString *)searchName
186{
187 // For best results, extensionsNames should be stored in your renderer so that it does not
188 // need to be recreated on each invocation.
189 NSString *extensionsString = [NSString stringWithCString:glExtensions encoding: NSASCIIStringEncoding];
190 NSArray *extensionsNames = [extensionsString componentsSeparatedByString:@" "];
191 return [extensionsNames containsObject: searchName];
192}
193@end