Skip to content

Commit d7dcfa1

Browse files
committed
Moving some metal/objc type definitions to shared header.
1 parent 5611d0c commit d7dcfa1

File tree

7 files changed

+114
-65
lines changed

7 files changed

+114
-65
lines changed

cocos2d-ios.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@
675675
D39FA9C818C1BC6B00441627 /* CCShader_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D39FA9C718C1BC6B00441627 /* CCShader_Private.h */; };
676676
D3A2E7D2181E12750033614C /* CCPhysicsShape.h in Headers */ = {isa = PBXBuildFile; fileRef = D3A2E7D0181E12750033614C /* CCPhysicsShape.h */; };
677677
D3A2E7D3181E12750033614C /* CCPhysicsShape.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A2E7D1181E12750033614C /* CCPhysicsShape.m */; };
678+
D3E3752F19CC842A0076CDBB /* CCRendererSharedTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = D3E3752E19CC842A0076CDBB /* CCRendererSharedTypes.h */; };
678679
E01E6D8C121F130E001A484F /* CCLabelBMFont.h in Headers */ = {isa = PBXBuildFile; fileRef = E01E6D8A121F130E001A484F /* CCLabelBMFont.h */; };
679680
E01E6D8D121F130E001A484F /* CCLabelBMFont.m in Sources */ = {isa = PBXBuildFile; fileRef = E01E6D8B121F130E001A484F /* CCLabelBMFont.m */; };
680681
E02BB6D6126CA93A006E46A2 /* CCAnimationCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E02BB6D4126CA93A006E46A2 /* CCAnimationCache.h */; };
@@ -1119,6 +1120,7 @@
11191120
D3A2E7D0181E12750033614C /* CCPhysicsShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsShape.h; sourceTree = "<group>"; };
11201121
D3A2E7D1181E12750033614C /* CCPhysicsShape.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCPhysicsShape.m; sourceTree = "<group>"; };
11211122
D3C12815199D40AC005D2119 /* CCShaders.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = CCShaders.metal; sourceTree = "<group>"; };
1123+
D3E3752E19CC842A0076CDBB /* CCRendererSharedTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCRendererSharedTypes.h; sourceTree = "<group>"; };
11221124
E01E6D8A121F130E001A484F /* CCLabelBMFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = CCLabelBMFont.h; sourceTree = "<group>"; };
11231125
E01E6D8B121F130E001A484F /* CCLabelBMFont.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CCLabelBMFont.m; sourceTree = "<group>"; };
11241126
E02BB6D4126CA93A006E46A2 /* CCAnimationCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAnimationCache.h; sourceTree = "<group>"; };
@@ -1894,6 +1896,7 @@
18941896
children = (
18951897
D3903B0E199528A0003AA81A /* CCRenderDispatch.h */,
18961898
D3903B0F199528A0003AA81A /* CCRenderDispatch.m */,
1899+
D3E3752E19CC842A0076CDBB /* CCRendererSharedTypes.h */,
18971900
D34CAD6519C3A7A5009BED7A /* CCRendererBasicTypes.h */,
18981901
D34CAD6A19C3AA10009BED7A /* CCRendererBasicTypes_Private.h */,
18991902
D34CAD6819C3A7B3009BED7A /* CCRendererBasicTypes.m */,
@@ -2113,6 +2116,7 @@
21132116
5B063DD019637291002B1CDE /* ALWeakDictionary.h in Headers */,
21142117
E02BB704126CADEA006E46A2 /* CCAnimation.h in Headers */,
21152118
B7D273191822F4AA0054849B /* CCBuilderReader.h in Headers */,
2119+
D3E3752F19CC842A0076CDBB /* CCRendererSharedTypes.h in Headers */,
21162120
B7E775D018527EF0004221AA /* CCAppDelegate.h in Headers */,
21172121
E0BC7D9F1342CE7B001B4DCC /* CCShader.h in Headers */,
21182122
D2DDB09319805E8400233D80 /* CCMathUtilsAndroid.h in Headers */,

cocos2d-tests-ios.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@
11971197
GCC_PREFIX_HEADER = "cocos2d-ui-tests/ios/Prefix.pch";
11981198
INFOPLIST_FILE = "cocos2d-ui-tests/ios/Resources/Info.plist";
11991199
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
1200+
MTL_HEADER_SEARCH_PATHS = "/Users/slembcke/Development/cocos2d-iphone/cocos2d";
12001201
ONLY_ACTIVE_ARCH = YES;
12011202
OTHER_LDFLAGS = (
12021203
"-lz",
@@ -1228,6 +1229,7 @@
12281229
GCC_PREFIX_HEADER = "cocos2d-ui-tests/ios/Prefix.pch";
12291230
INFOPLIST_FILE = "cocos2d-ui-tests/ios/Resources/Info.plist";
12301231
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
1232+
MTL_HEADER_SEARCH_PATHS = "/Users/slembcke/Development/cocos2d-iphone/cocos2d";
12311233
OTHER_LDFLAGS = (
12321234
"-lz",
12331235
"-lsqlite3",

cocos2d/CCRenderer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ -(void)prepareWithProjection:(const GLKMatrix4 *)projection framebuffer:(CCFrame
291291
globalShaderUniforms[CCShaderUniformViewSize] = [NSValue valueWithGLKVector2:globals.viewSize];
292292

293293
CCTime t = director.scheduler.currentTime;
294-
globals.time = GLKVector4Make(t, t/2.0f, t/8.0f, t/8.0f);
294+
globals.time = GLKVector4Make(t, t/2.0f, t/4.0f, t/8.0f);
295295
globals.sinTime = GLKVector4Make(sinf(t*2.0f), sinf(t), sinf(t/2.0f), sinf(t/4.0f));
296296
globals.cosTime = GLKVector4Make(cosf(t*2.0f), cosf(t), cosf(t/2.0f), cosf(t/4.0f));
297297
globalShaderUniforms[CCShaderUniformTime] = [NSValue valueWithGLKVector4:globals.time];

cocos2d/CCRendererBasicTypes.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,9 @@
2323
*/
2424

2525
#import "ccTypes.h"
26+
#import "CCRendererSharedTypes.h"
2627

2728

28-
/// Standard interleaved vertex format for Cocos2D.
29-
typedef struct CCVertex {
30-
/// Vec4 position (x, y, z, w)
31-
GLKVector4 position;
32-
/// 2xVec2 texture coordinates (x, y)
33-
GLKVector2 texCoord1, texCoord2;
34-
/// Vec4 color (RGBA)
35-
GLKVector4 color;
36-
} CCVertex;
37-
3829
/// Multiply the vertex's position by the given transform. Pass the rest.
3930
static inline CCVertex
4031
CCVertexApplyTransform(CCVertex v, const GLKMatrix4 *transform)

cocos2d/CCRendererSharedTypes.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* cocos2d for iPhone: http://www.cocos2d-iphone.org
3+
*
4+
* Copyright (c) 2013 Apportable Inc.
5+
* Copyright (c) 2013-2014 Cocos2D Authors
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+
// This header contains type definitions that are imported into both Obj-C and Metal code.
27+
28+
29+
#if __METAL_VERSION__
30+
#include <simd/simd.h>
31+
using namespace metal;
32+
33+
// Make aliases for GLKMath types so struct definitions can be shared.
34+
typedef float2 GLKVector2;
35+
typedef float3 GLKVector3;
36+
typedef float4 GLKVector4;
37+
typedef float2x2 GLKMatrix2;
38+
typedef float3x3 GLKMatrix3;
39+
typedef float4x4 GLKMatrix4;
40+
#endif
41+
42+
/// Standard interleaved vertex format for Cocos2D.
43+
typedef struct CCVertex {
44+
/// Vec4 position (x, y, z, w)
45+
GLKVector4 position;
46+
/// 2xVec2 texture coordinates (x, y)
47+
GLKVector2 texCoord1, texCoord2;
48+
/// Vec4 color (RGBA)
49+
GLKVector4 color;
50+
} CCVertex;
51+
52+
#if __METAL_VERSION__
53+
/// Default vertex shader output for Metal.
54+
typedef struct CCFragData {
55+
float4 position [[position]];
56+
float2 texCoord1;
57+
float2 texCoord2;
58+
half4 color;
59+
} CCFragData;
60+
#endif
61+
62+
/// Standard set of global uniform values (used with Metal).
63+
typedef struct CCGlobalUniforms {
64+
/// Projection matrix.
65+
GLKMatrix4 projection;
66+
/// Inverse of projection matrix.
67+
GLKMatrix4 projectionInv;
68+
/// Size of the render target in points.
69+
GLKVector2 viewSize;
70+
/// Size of the render target in pixels.
71+
GLKVector2 viewSizeInPixels;
72+
/// Current time [t, t/2, t/4, t/8]
73+
GLKVector4 time;
74+
/// Sine of the current time [sin(t*2), sin(t), sin(t/2), sin(t/4)]
75+
GLKVector4 sinTime;
76+
/// Cosine of the current time [cos(t*2), cos(t), cos(t/2), cos(t/4)]
77+
GLKVector4 cosTime;
78+
/// Random per-frame vec4. All components are in the range [0, 1].
79+
GLKVector4 random01;
80+
} CCGlobalUniforms;

cocos2d/CCRenderer_Private.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,6 @@
2929
#import "CCRenderDispatch.h"
3030
#import "CCRendererBasicTypes_Private.h"
3131

32-
// Struct used for packing the global uniforms.
33-
// NOTE: Must match the definition in CCShaders.metal!
34-
typedef struct CCGlobalUniforms {
35-
GLKMatrix4 projection;
36-
GLKMatrix4 projectionInv;
37-
GLKVector2 viewSize;
38-
GLKVector2 viewSizeInPixels;
39-
GLKVector4 time;
40-
GLKVector4 sinTime;
41-
GLKVector4 cosTime;
42-
GLKVector4 random01;
43-
} CCGlobalUniforms;
44-
4532
/// Options dictionary for the disabled blending mode.
4633
extern NSDictionary *CCBLEND_DISABLED_OPTIONS;
4734

cocos2d/Platforms/iOS/CCShaders.metal

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,35 @@
1+
/*
2+
* cocos2d for iPhone: http://www.cocos2d-iphone.org
3+
*
4+
* Copyright (c) 2013 Apportable Inc.
5+
* Copyright (c) 2013-2014 Cocos2D Authors
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+
126
#include <metal_stdlib>
227
#include <simd/simd.h>
328

29+
#include "CCRendererSharedTypes.h"
430

531
using namespace metal;
632

7-
8-
// Make aliases for GLKMath types so struct definitions can be shared.
9-
#if __METAL_VERSION__
10-
typedef float2 GLKVector2;
11-
typedef float3 GLKVector3;
12-
typedef float4 GLKVector4;
13-
typedef float2x2 GLKMatrix2;
14-
typedef float3x3 GLKMatrix3;
15-
typedef float4x4 GLKMatrix4;
16-
#endif
17-
18-
19-
20-
// Default vertex attributes.
21-
typedef struct CCVertex {
22-
GLKVector4 position;
23-
GLKVector2 texCoord1, texCoord2;
24-
GLKVector4 color;
25-
} CCVertex;
26-
27-
// Default fragment varyings.
28-
typedef struct CCFragData {
29-
float4 position [[position]];
30-
float2 texCoord1;
31-
float2 texCoord2;
32-
half4 color;
33-
} CCFragData;
34-
35-
// Standard set of global uniform values.
36-
// NOTE: Must match the definition in CCRenderer_Private.h!
37-
typedef struct CCGlobalUniforms {
38-
GLKMatrix4 projection;
39-
GLKMatrix4 projectionInv;
40-
GLKVector2 viewSize;
41-
GLKVector2 viewSizeInPixels;
42-
GLKVector4 time;
43-
GLKVector4 sinTime;
44-
GLKVector4 cosTime;
45-
GLKVector4 random01;
46-
} CCGlobalUniforms;
47-
4833
// Default vertex function.
4934
vertex CCFragData
5035
CCVertexFunctionDefault(

0 commit comments

Comments
 (0)