|
15 | 15 | #define GAUSSIANBLUR_OPTMIZIED_RADIUS_MAX 6
|
16 | 16 | #endif
|
17 | 17 |
|
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; |
19 | 123 |
|
20 | 124 | @property (nonatomic, weak) id<CCEffectStackProtocol> owningStack;
|
21 | 125 | @property (nonatomic) NSMutableArray* vertexFunctions;
|
|
27 | 131 | @property (nonatomic) CCEffectFunctionStitchFlags stitchFlags;
|
28 | 132 | @property (nonatomic) NSMutableDictionary* uniformTranslationTable;
|
29 | 133 |
|
| 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 | + |
30 | 147 | -(void)buildEffectShader;
|
31 | 148 | -(void)buildFragmentFunctions;
|
32 | 149 | -(void)buildVertexFunctions;
|
|
37 | 154 | + (NSSet *)defaultEffectVertexUniformNames;
|
38 | 155 |
|
39 | 156 | @end
|
| 157 | + |
40 | 158 | #endif
|
0 commit comments