Skip to content

Commit a0852a5

Browse files
committed
Splitting up the CCRenderer code more.
1 parent 6f36e4d commit a0852a5

File tree

8 files changed

+744
-632
lines changed

8 files changed

+744
-632
lines changed

cocos2d-ios.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@
648648
D33803EA180331A90072D8FE /* CCPhysicsJoint.m in Sources */ = {isa = PBXBuildFile; fileRef = D33803E9180331A90072D8FE /* CCPhysicsJoint.m */; };
649649
D34CAD6119C3A0B5009BED7A /* NSValue+CCRenderer.h in Headers */ = {isa = PBXBuildFile; fileRef = D34CAD5F19C3A0B5009BED7A /* NSValue+CCRenderer.h */; };
650650
D34CAD6419C3A0FD009BED7A /* NSValue+CCRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = D34CAD6219C3A0FD009BED7A /* NSValue+CCRenderer.m */; };
651+
D34CAD6719C3A7A5009BED7A /* CCRendererBasicTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = D34CAD6519C3A7A5009BED7A /* CCRendererBasicTypes.h */; };
652+
D34CAD6919C3A7B3009BED7A /* CCRendererBasicTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = D34CAD6819C3A7B3009BED7A /* CCRendererBasicTypes.m */; };
653+
D34CAD6C19C3AA10009BED7A /* CCRendererBasicTypes_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D34CAD6A19C3AA10009BED7A /* CCRendererBasicTypes_Private.h */; };
651654
D36D31B718BD3CAA00E45F08 /* CCProgressNode.m in Sources */ = {isa = PBXBuildFile; fileRef = B791E85C182074C500DAE1D7 /* CCProgressNode.m */; };
652655
D36DFA2819996EC500DEC135 /* CCRendererGLSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = D36DFA2719996EC500DEC135 /* CCRendererGLSupport.m */; };
653656
D37D197718B6665700B23FDE /* CCTiledMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 509D0817101E4FCE007E1749 /* CCTiledMap.m */; };
@@ -1101,6 +1104,9 @@
11011104
D33803E9180331A90072D8FE /* CCPhysicsJoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCPhysicsJoint.m; sourceTree = "<group>"; };
11021105
D34CAD5F19C3A0B5009BED7A /* NSValue+CCRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValue+CCRenderer.h"; sourceTree = "<group>"; };
11031106
D34CAD6219C3A0FD009BED7A /* NSValue+CCRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSValue+CCRenderer.m"; sourceTree = "<group>"; };
1107+
D34CAD6519C3A7A5009BED7A /* CCRendererBasicTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCRendererBasicTypes.h; sourceTree = "<group>"; };
1108+
D34CAD6819C3A7B3009BED7A /* CCRendererBasicTypes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCRendererBasicTypes.m; sourceTree = "<group>"; };
1109+
D34CAD6A19C3AA10009BED7A /* CCRendererBasicTypes_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCRendererBasicTypes_Private.h; sourceTree = "<group>"; };
11041110
D36DFA2719996EC500DEC135 /* CCRendererGLSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCRendererGLSupport.m; path = ../CCRendererGLSupport.m; sourceTree = "<group>"; };
11051111
D38058181889AD6000822437 /* CCRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCRenderer.h; sourceTree = "<group>"; };
11061112
D38058191889AD6000822437 /* CCRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCRenderer.m; sourceTree = "<group>"; };
@@ -1897,6 +1903,9 @@
18971903
children = (
18981904
D3903B0E199528A0003AA81A /* CCRenderDispatch.h */,
18991905
D3903B0F199528A0003AA81A /* CCRenderDispatch.m */,
1906+
D34CAD6519C3A7A5009BED7A /* CCRendererBasicTypes.h */,
1907+
D34CAD6A19C3AA10009BED7A /* CCRendererBasicTypes_Private.h */,
1908+
D34CAD6819C3A7B3009BED7A /* CCRendererBasicTypes.m */,
19001909
D38058181889AD6000822437 /* CCRenderer.h */,
19011910
D309054F18AC23110081BF11 /* CCRenderer_Private.h */,
19021911
D38058191889AD6000822437 /* CCRenderer.m */,
@@ -2048,6 +2057,7 @@
20482057
D272032418FC89A000B100FF /* CCEffect_Private.h in Headers */,
20492058
D272032D18FC89A000B100FF /* CCEffectStack.h in Headers */,
20502059
B7E260D818171D2000A0E872 /* CCTextField.h in Headers */,
2060+
D34CAD6C19C3AA10009BED7A /* CCRendererBasicTypes_Private.h in Headers */,
20512061
D268FE13198078FF00ECBCD0 /* CCEffectReflection.h in Headers */,
20522062
B7D273131822F4AA0054849B /* CCBReader.h in Headers */,
20532063
9DF37621191C594A00C6D27A /* CCEffectPixellate.h in Headers */,
@@ -2056,6 +2066,7 @@
20562066
509D0818101E4FCE007E1749 /* CCTiledMap.h in Headers */,
20572067
50F29F6F102053370046CA73 /* base64.h in Headers */,
20582068
D31C795219994197007921E1 /* CCMetalSupport_Private.h in Headers */,
2069+
D34CAD6719C3A7A5009BED7A /* CCRendererBasicTypes.h in Headers */,
20592070
50F2A105102094550046CA73 /* ZipUtils.h in Headers */,
20602071
D27451B719AE5517006DA0A1 /* CCEffectDistanceField.h in Headers */,
20612072
50CFAC391023660000175934 /* CCTMXXMLParser.h in Headers */,
@@ -2616,6 +2627,7 @@
26162627
D380581B1889AD6000822437 /* CCRenderer.m in Sources */,
26172628
A039EC00155C686B0061EE37 /* CCNode+Debug.m in Sources */,
26182629
5B063DCD19637285002B1CDE /* ALWeakArray.m in Sources */,
2630+
D34CAD6919C3A7B3009BED7A /* CCRendererBasicTypes.m in Sources */,
26192631
D2DDB0A519805E8400233D80 /* CCQuaternion.m in Sources */,
26202632
D36D31B718BD3CAA00E45F08 /* CCProgressNode.m in Sources */,
26212633
B7705FDD1831A07B0043CC67 /* OALSimpleAudio.m in Sources */,

cocos2d/CCRenderer.h

Lines changed: 1 addition & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -26,154 +26,7 @@
2626
#import "CCShader.h"
2727

2828
#import "NSValue+CCRenderer.h"
29-
30-
31-
@class CCTexture;
32-
33-
/// Standard interleaved vertex format for Cocos2D.
34-
typedef struct CCVertex {
35-
/// Vec4 position (x, y, z, w)
36-
GLKVector4 position;
37-
/// 2xVec2 texture coordinates (x, y)
38-
GLKVector2 texCoord1, texCoord2;
39-
/// Vec4 color (RGBA)
40-
GLKVector4 color;
41-
} CCVertex;
42-
43-
/// Multiply the vertex's position by the given transform. Pass the rest.
44-
static inline CCVertex
45-
CCVertexApplyTransform(CCVertex v, const GLKMatrix4 *transform)
46-
{
47-
return (CCVertex){
48-
GLKMatrix4MultiplyVector4(*transform, v.position),
49-
v.texCoord1, v.texCoord2, v.color,
50-
};
51-
}
52-
53-
/// Interpolate between two CCVertex values.
54-
static inline CCVertex
55-
CCVertexLerp(CCVertex a, CCVertex b, float t)
56-
{
57-
return (CCVertex){
58-
GLKVector4Lerp(a.position, b.position, t),
59-
GLKVector2Lerp(a.texCoord1, b.texCoord1, t),
60-
GLKVector2Lerp(a.texCoord2, b.texCoord2, t),
61-
GLKVector4Lerp(a.color, b.color, t),
62-
};
63-
}
64-
65-
/// Vertex/element buffer.
66-
/// It's recommended to use the CCRenderBuffer*() functions to manipulate this.
67-
typedef struct CCRenderBuffer {
68-
/// Read only pointer to the start of the vertex buffer.
69-
CCVertex *vertexes;
70-
/// Read only pointer to the start of the element index buffer.
71-
GLushort *elements;
72-
/// Offset of the first vertex in the buffer.
73-
GLushort startIndex;
74-
} CCRenderBuffer;
75-
76-
/// Set a vertex in the buffer.
77-
static inline void
78-
CCRenderBufferSetVertex(CCRenderBuffer buffer, int index, CCVertex vertex)
79-
{
80-
buffer.vertexes[index] = vertex;
81-
}
82-
83-
/// Set a triangle in the buffer.
84-
/// The CCRenderBuffer must have been created using [CCRenderer enqueueTriangles:andVertexes:withState:].
85-
static inline void
86-
CCRenderBufferSetTriangle(CCRenderBuffer buffer, int index, GLushort a, GLushort b, GLushort c)
87-
{
88-
uint16_t offset = buffer.startIndex;
89-
buffer.elements[3*index + 0] = a + offset;
90-
buffer.elements[3*index + 1] = b + offset;
91-
buffer.elements[3*index + 2] = c + offset;
92-
}
93-
94-
/// Set a line in the buffer.
95-
/// The CCRenderBuffer must have been created using [CCRenderer enqueueLines:andVertexes:withState:].
96-
static inline void
97-
CCRenderBufferSetLine(CCRenderBuffer buffer, int index, GLushort a, GLushort b)
98-
{
99-
uint16_t offset = buffer.startIndex;
100-
buffer.elements[2*index + 0] = a + offset;
101-
buffer.elements[2*index + 1] = b + offset;
102-
}
103-
104-
/// Check if the given bounding box as specified by it's center and extents (half with/height) is visible onscreen.
105-
static inline BOOL
106-
CCRenderCheckVisbility(const GLKMatrix4 *transform, GLKVector2 center, GLKVector2 extents)
107-
{
108-
// Center point in clip coordinates.
109-
GLKVector4 csc = GLKMatrix4MultiplyVector4(*transform, GLKVector4Make(center.x, center.y, 0.0f, 1.0f));
110-
111-
// x, y in clip space.
112-
float cshx = fmaxf(fabsf(extents.x*transform->m00 + extents.y*transform->m10), fabsf(extents.x*transform->m00 - extents.y*transform->m10));
113-
float cshy = fmaxf(fabsf(extents.x*transform->m01 + extents.y*transform->m11), fabsf(extents.x*transform->m01 - extents.y*transform->m11));
114-
115-
// Check the bounds against the clip space viewport using a conservative w-value.
116-
float w = fabs(csc.w) + fmaxf(fabsf(extents.x*transform->m03 + extents.y*transform->m13), fabsf(extents.x*transform->m03 - extents.y*transform->m13));
117-
return ((fabs(csc.x) - cshx < w) && (fabs(csc.y) - cshy < w));
118-
}
119-
120-
121-
/// Key used to set the source color factor for [CCBlendMode blendModeWithOptions:].
122-
extern const NSString *CCBlendFuncSrcColor;
123-
/// Key used to set the destination color factor for [CCBlendMode blendModeWithOptions:].
124-
extern const NSString *CCBlendFuncDstColor;
125-
/// Key used to set the color equation for [CCBlendMode blendModeWithOptions:].
126-
extern const NSString *CCBlendEquationColor;
127-
/// Key used to set the source alpha factor for [CCBlendMode blendModeWithOptions:].
128-
extern const NSString *CCBlendFuncSrcAlpha;
129-
/// Key used to set the destination alpha factor for [CCBlendMode blendModeWithOptions:].
130-
extern const NSString *CCBlendFuncDstAlpha;
131-
/// Key used to set the alpha equation for [CCBlendMode blendModeWithOptions:].
132-
extern const NSString *CCBlendEquationAlpha;
133-
134-
135-
/// Blending mode identifiers used with CCNode.blendMode.
136-
@interface CCBlendMode : NSObject
137-
138-
/// Blending options for this mode.
139-
@property(nonatomic, readonly) NSDictionary *options;
140-
141-
/// Return a cached blending mode with the given options.
142-
+(CCBlendMode *)blendModeWithOptions:(NSDictionary *)options;
143-
144-
/// Disabled blending mode. Use this with fully opaque surfaces for extra performance.
145-
+(CCBlendMode *)disabledMode;
146-
/// Regular alpha blending.
147-
+(CCBlendMode *)alphaMode;
148-
/// Pre-multiplied alpha blending. (This is usually the default)
149-
+(CCBlendMode *)premultipliedAlphaMode;
150-
/// Additive blending. (Similar to PhotoShop's linear dodge mode)
151-
+(CCBlendMode *)addMode;
152-
/// Multiply blending mode. (Similar to PhotoShop's burn mode)
153-
+(CCBlendMode *)multiplyMode;
154-
155-
@end
156-
157-
158-
/// A render state encapsulates how an object will be draw.
159-
/// What shader it will use, what texture, what blending mode, etc.
160-
@interface CCRenderState : NSObject<NSCopying>
161-
162-
/// A simple render state you can use that draws solid colors.
163-
+(instancetype)debugColor;
164-
165-
/// Create a cached blending mode for a given blending mode, shader and main texture.
166-
+(instancetype)renderStateWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader mainTexture:(CCTexture *)mainTexture;
167-
168-
/// Create an uncached blending mode for a given blending mode, shader and set of uniform values.
169-
/// Allowing the uniform dictionary to be copied allows the render state to be immutable and used more optimally.
170-
+(instancetype)renderStateWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms copyUniforms:(BOOL)copyUniforms;
171-
172-
/// Initialize an uncached blending mode for a given blending mode, shader and set of uncopied uniform values.
173-
/// Use [CCRenderState renderStateWithBlendMode:blendMode shader:shader shaderUniforms:shaderUniforms copyUniforms:NO] instead.
174-
-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms __deprecated;
175-
176-
@end
29+
#import "CCRendererBasicTypes.h"
17730

17831

17932
/// A rendering queue.

0 commit comments

Comments
 (0)