|
26 | 26 | #import "CCShader.h"
|
27 | 27 |
|
28 | 28 | #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" |
177 | 30 |
|
178 | 31 |
|
179 | 32 | /// A rendering queue.
|
|
0 commit comments