Skip to content

Commit c71cb5c

Browse files
author
Thayer J Andrews
committed
Merge branch 'thayer/effectApiPrivatization' into develop
2 parents 9c54490 + 596ed62 commit c71cb5c

File tree

5 files changed

+122
-116
lines changed

5 files changed

+122
-116
lines changed

cocos2d/CCEffect.h

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -13,124 +13,9 @@
1313
#import "ccTypes.h"
1414

1515
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
16-
extern NSString * const CCShaderUniformPreviousPassTexture;
17-
18-
typedef NS_ENUM(NSUInteger, CCEffectFunctionStitchFlags)
19-
{
20-
CCEffectFunctionStitchBefore = 1 << 0,
21-
CCEffectFunctionStitchAfter = 1 << 1,
22-
CCEffectFunctionStitchBoth = (CCEffectFunctionStitchBefore | CCEffectFunctionStitchAfter),
23-
};
24-
25-
typedef NS_ENUM(NSUInteger, CCEffectPrepareStatus)
26-
{
27-
CCEffectPrepareNothingToDo = 0,
28-
CCEffectPrepareFailure = 1,
29-
CCEffectPrepareSuccess = 2,
30-
};
31-
32-
@interface CCEffectFunction : NSObject
33-
34-
@property (nonatomic, readonly) NSString* body;
35-
@property (nonatomic, readonly) NSString* name;
36-
@property (nonatomic, readonly) NSArray* inputs;
37-
@property (nonatomic, readonly) NSString* inputString;
38-
@property (nonatomic, readonly) NSString* returnType;
39-
@property (nonatomic, readonly) NSString* function;
40-
41-
-(id)initWithName:(NSString*)name body:(NSString*)body inputs:(NSArray*)inputs returnType:(NSString*)returnType;
42-
+(id)functionWithName:(NSString*)name body:(NSString*)body inputs:(NSArray*)inputs returnType:(NSString*)returnType;
43-
44-
-(NSString*)callStringWithInputs:(NSArray*)inputs;
45-
46-
@end
47-
48-
@interface CCEffectFunctionInput : NSObject
49-
50-
@property (nonatomic, readonly) NSString* type;
51-
@property (nonatomic, readonly) NSString* name;
52-
@property (nonatomic, readonly) NSString* snippet;
53-
54-
-(id)initWithType:(NSString*)type name:(NSString*)name snippet:(NSString*)snippet;
55-
+(id)inputWithType:(NSString*)type name:(NSString*)name snippet:(NSString*)snippet;
56-
57-
@end
58-
59-
@interface CCEffectUniform : NSObject
60-
61-
@property (nonatomic, readonly) NSString* name;
62-
@property (nonatomic, readonly) NSString* type;
63-
@property (nonatomic, readonly) NSString* declaration;
64-
@property (nonatomic, readonly) NSValue* value;
65-
66-
-(id)initWithType:(NSString*)type name:(NSString*)name value:(NSValue*)value;
67-
+(id)uniform:(NSString*)type name:(NSString*)name value:(NSValue*)value;
68-
69-
@end
70-
71-
@interface CCEffectVarying : NSObject
72-
73-
@property (nonatomic, readonly) NSString* name;
74-
@property (nonatomic, readonly) NSString* type;
75-
@property (nonatomic, readonly) NSString* declaration;
76-
@property (nonatomic, readonly) NSInteger count;
77-
78-
-(id)initWithType:(NSString*)type name:(NSString*)name;
79-
-(id)initWithType:(NSString*)type name:(NSString*)name count:(NSInteger)count;
80-
+(id)varying:(NSString*)type name:(NSString*)name;
81-
+(id)varying:(NSString*)type name:(NSString*)name count:(NSInteger)count;
82-
83-
@end
84-
85-
@class CCEffectRenderPass;
86-
87-
typedef void (^CCEffectRenderPassBeginBlock)(CCEffectRenderPass *pass, CCTexture *previousPassTexture);
88-
typedef void (^CCEffectRenderPassUpdateBlock)(CCEffectRenderPass *pass);
89-
typedef void (^CCEffectRenderPassEndBlock)(CCEffectRenderPass *pass);
90-
91-
// Note to self: I don't like this pattern, refactor it. I think there should be a CCRenderPass that is used by CCEffect instead. NOTE: convert this to a CCRnderPassProtocol
92-
@interface CCEffectRenderPass : NSObject
93-
94-
@property (nonatomic) NSInteger renderPassId;
95-
@property (nonatomic) CCRenderer* renderer;
96-
@property (nonatomic) CCSpriteVertexes verts;
97-
@property (nonatomic) GLKMatrix4 transform;
98-
@property (nonatomic) CCBlendMode* blendMode;
99-
@property (nonatomic) CCShader* shader;
100-
@property (nonatomic) NSMutableDictionary* shaderUniforms;
101-
@property (nonatomic) BOOL needsClear;
102-
@property (nonatomic,copy) NSArray* beginBlocks;
103-
@property (nonatomic,copy) NSArray* updateBlocks;
104-
@property (nonatomic,copy) NSArray* endBlocks;
105-
@property (nonatomic,copy) NSString *debugLabel;
106-
107-
-(void)begin:(CCTexture *)previousPassTexture;
108-
-(void)update;
109-
-(void)end;
110-
-(void)enqueueTriangles;
111-
112-
@end
113-
11416
@interface CCEffect : NSObject
11517

116-
@property (nonatomic, readonly) CCShader* shader; // Note: consider adding multiple shaders (one for reach renderpass, this will help break up logic and avoid branching in a potential uber shader).
117-
@property (nonatomic, readonly) NSMutableDictionary* shaderUniforms;
118-
@property (nonatomic, readonly) NSInteger renderPassesRequired;
119-
@property (nonatomic, readonly) BOOL supportsDirectRendering;
120-
@property (nonatomic, readonly) BOOL readyForRendering;
12118
@property (nonatomic, copy) NSString *debugName;
12219

123-
124-
-(id)initWithFragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varying:(NSArray*)varying;
125-
-(id)initWithFragmentFunction:(NSMutableArray*) fragmentFunctions fragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varying:(NSArray*)varying;
126-
-(id)initWithFragmentFunction:(NSMutableArray*) fragmentFunctions vertexFunctions:(NSMutableArray*)vertexFunctions fragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varying:(NSArray*)varying;
127-
128-
-(CCEffectPrepareStatus)prepareForRendering;
129-
-(CCEffectRenderPass *)renderPassAtIndex:(NSInteger)passIndex;
130-
131-
-(BOOL)stitchSupported:(CCEffectFunctionStitchFlags)stitch;
132-
133-
-(void)setVarying:(NSArray*)varying;
134-
13520
@end
13621
#endif

cocos2d/CCEffectNode.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "CCNode_Private.h"
2323
#import "CCRenderer_private.h"
2424
#import "CCRenderTexture_Private.h"
25+
#import "CCEffect_Private.h"
2526

2627
#if __CC_PLATFORM_MAC
2728
#import <ApplicationServices/ApplicationServices.h>

cocos2d/CCEffectRenderer.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "CCTexture.h"
1515
#import "ccUtils.h"
1616

17+
#import "CCEffect_Private.h"
1718
#import "CCSprite_Private.h"
1819
#import "CCTexture_Private.h"
1920

cocos2d/CCEffect_Private.h

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,111 @@
1515
#define GAUSSIANBLUR_OPTMIZIED_RADIUS_MAX 6
1616
#endif
1717

18-
@interface CCEffect()
18+
extern NSString * const CCShaderUniformPreviousPassTexture;
19+
20+
typedef NS_ENUM(NSUInteger, CCEffectFunctionStitchFlags)
21+
{
22+
CCEffectFunctionStitchBefore = 1 << 0,
23+
CCEffectFunctionStitchAfter = 1 << 1,
24+
CCEffectFunctionStitchBoth = (CCEffectFunctionStitchBefore | CCEffectFunctionStitchAfter),
25+
};
26+
27+
typedef NS_ENUM(NSUInteger, CCEffectPrepareStatus)
28+
{
29+
CCEffectPrepareNothingToDo = 0,
30+
CCEffectPrepareFailure = 1,
31+
CCEffectPrepareSuccess = 2,
32+
};
33+
34+
@interface CCEffectFunction : NSObject
35+
36+
@property (nonatomic, readonly) NSString* body;
37+
@property (nonatomic, readonly) NSString* name;
38+
@property (nonatomic, readonly) NSArray* inputs;
39+
@property (nonatomic, readonly) NSString* inputString;
40+
@property (nonatomic, readonly) NSString* returnType;
41+
@property (nonatomic, readonly) NSString* function;
42+
43+
-(id)initWithName:(NSString*)name body:(NSString*)body inputs:(NSArray*)inputs returnType:(NSString*)returnType;
44+
+(id)functionWithName:(NSString*)name body:(NSString*)body inputs:(NSArray*)inputs returnType:(NSString*)returnType;
45+
46+
-(NSString*)callStringWithInputs:(NSArray*)inputs;
47+
48+
@end
49+
50+
@interface CCEffectFunctionInput : NSObject
51+
52+
@property (nonatomic, readonly) NSString* type;
53+
@property (nonatomic, readonly) NSString* name;
54+
@property (nonatomic, readonly) NSString* snippet;
55+
56+
-(id)initWithType:(NSString*)type name:(NSString*)name snippet:(NSString*)snippet;
57+
+(id)inputWithType:(NSString*)type name:(NSString*)name snippet:(NSString*)snippet;
58+
59+
@end
60+
61+
@interface CCEffectUniform : NSObject
62+
63+
@property (nonatomic, readonly) NSString* name;
64+
@property (nonatomic, readonly) NSString* type;
65+
@property (nonatomic, readonly) NSString* declaration;
66+
@property (nonatomic, readonly) NSValue* value;
67+
68+
-(id)initWithType:(NSString*)type name:(NSString*)name value:(NSValue*)value;
69+
+(id)uniform:(NSString*)type name:(NSString*)name value:(NSValue*)value;
70+
71+
@end
72+
73+
@interface CCEffectVarying : NSObject
74+
75+
@property (nonatomic, readonly) NSString* name;
76+
@property (nonatomic, readonly) NSString* type;
77+
@property (nonatomic, readonly) NSString* declaration;
78+
@property (nonatomic, readonly) NSInteger count;
79+
80+
-(id)initWithType:(NSString*)type name:(NSString*)name;
81+
-(id)initWithType:(NSString*)type name:(NSString*)name count:(NSInteger)count;
82+
+(id)varying:(NSString*)type name:(NSString*)name;
83+
+(id)varying:(NSString*)type name:(NSString*)name count:(NSInteger)count;
84+
85+
@end
86+
87+
@class CCEffectRenderPass;
88+
89+
typedef void (^CCEffectRenderPassBeginBlock)(CCEffectRenderPass *pass, CCTexture *previousPassTexture);
90+
typedef void (^CCEffectRenderPassUpdateBlock)(CCEffectRenderPass *pass);
91+
typedef void (^CCEffectRenderPassEndBlock)(CCEffectRenderPass *pass);
92+
93+
// Note to self: I don't like this pattern, refactor it. I think there should be a CCRenderPass that is used by CCEffect instead. NOTE: convert this to a CCRnderPassProtocol
94+
@interface CCEffectRenderPass : NSObject
95+
96+
@property (nonatomic) NSInteger renderPassId;
97+
@property (nonatomic) CCRenderer* renderer;
98+
@property (nonatomic) CCSpriteVertexes verts;
99+
@property (nonatomic) GLKMatrix4 transform;
100+
@property (nonatomic) CCBlendMode* blendMode;
101+
@property (nonatomic) CCShader* shader;
102+
@property (nonatomic) NSMutableDictionary* shaderUniforms;
103+
@property (nonatomic) BOOL needsClear;
104+
@property (nonatomic,copy) NSArray* beginBlocks;
105+
@property (nonatomic,copy) NSArray* updateBlocks;
106+
@property (nonatomic,copy) NSArray* endBlocks;
107+
@property (nonatomic,copy) NSString *debugLabel;
108+
109+
-(void)begin:(CCTexture *)previousPassTexture;
110+
-(void)update;
111+
-(void)end;
112+
-(void)enqueueTriangles;
113+
114+
@end
115+
116+
@interface CCEffect ()
117+
118+
@property (nonatomic, readonly) CCShader* shader; // Note: consider adding multiple shaders (one for reach renderpass, this will help break up logic and avoid branching in a potential uber shader).
119+
@property (nonatomic, readonly) NSMutableDictionary* shaderUniforms;
120+
@property (nonatomic, readonly) NSInteger renderPassesRequired;
121+
@property (nonatomic, readonly) BOOL supportsDirectRendering;
122+
@property (nonatomic, readonly) BOOL readyForRendering;
19123

20124
@property (nonatomic, weak) id<CCEffectStackProtocol> owningStack;
21125
@property (nonatomic) NSMutableArray* vertexFunctions;
@@ -27,6 +131,19 @@
27131
@property (nonatomic) CCEffectFunctionStitchFlags stitchFlags;
28132
@property (nonatomic) NSMutableDictionary* uniformTranslationTable;
29133

134+
135+
-(id)initWithFragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varying:(NSArray*)varying;
136+
-(id)initWithFragmentFunction:(NSMutableArray*) fragmentFunctions fragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varying:(NSArray*)varying;
137+
-(id)initWithFragmentFunction:(NSMutableArray*) fragmentFunctions vertexFunctions:(NSMutableArray*)vertexFunctions fragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varying:(NSArray*)varying;
138+
139+
-(CCEffectPrepareStatus)prepareForRendering;
140+
-(CCEffectRenderPass *)renderPassAtIndex:(NSInteger)passIndex;
141+
142+
-(BOOL)stitchSupported:(CCEffectFunctionStitchFlags)stitch;
143+
144+
-(void)setVarying:(NSArray*)varying;
145+
146+
30147
-(void)buildEffectShader;
31148
-(void)buildFragmentFunctions;
32149
-(void)buildVertexFunctions;
@@ -37,4 +154,5 @@
37154
+ (NSSet *)defaultEffectVertexUniformNames;
38155

39156
@end
157+
40158
#endif

cocos2d/CCSprite.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#import "CCEffect.h"
4545
#import "CCEffectRenderer.h"
4646
#import "CCEffectStack.h"
47+
#import "CCEffect_Private.h"
4748

4849
#pragma mark -
4950
#pragma mark CCSprite

0 commit comments

Comments
 (0)