Skip to content

Commit 1738292

Browse files
committed
Merge pull request #903 from thayerandrews/develop
CCEffects - API cleanup, test cleanup, bug fixes
2 parents 6caf6b3 + 540198e commit 1738292

40 files changed

+293
-250
lines changed

cocos2d-ui-tests/tests/CCCacheTest.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ @implementation CCCacheTest
5353
{
5454
DemoCache *_cache;
5555
int _testStep;
56-
NSValue *_A;
57-
NSValue *_B;
56+
NSValue *_valueA;
57+
NSValue *_valueB;
5858
}
5959

6060
- (NSArray*) testConstructors
@@ -94,12 +94,12 @@ - (void)stepClicked:(id)sender
9494

9595
case 1:
9696
CCLOG(@"-- objectA in use");
97-
_A = [_cache objectForKey:@"objectA"];
97+
_valueA = [_cache objectForKey:@"objectA"];
9898
break;
9999

100100
case 2:
101101
CCLOG(@"-- objectB in use");
102-
_B = [_cache objectForKey:@"objectB"];
102+
_valueB = [_cache objectForKey:@"objectB"];
103103
break;
104104

105105
case 3:
@@ -109,7 +109,7 @@ - (void)stepClicked:(id)sender
109109

110110
case 4:
111111
CCLOG(@"-- objectA not in use anymore");
112-
_A = nil;
112+
_valueA = nil;
113113
break;
114114

115115
case 5:
@@ -119,13 +119,13 @@ - (void)stepClicked:(id)sender
119119

120120
case 6:
121121
CCLOG(@"-- New objectA should be created");
122-
_A = [_cache objectForKey:@"objectA"];
122+
_valueA = [_cache objectForKey:@"objectA"];
123123
break;
124124

125125
case 7:
126126
CCLOG(@"-- No new objectB should be created");
127127
[_cache flush];
128-
_B = [_cache objectForKey:@"objectB"];
128+
_valueB = [_cache objectForKey:@"objectB"];
129129
break;
130130

131131
default:

cocos2d-ui-tests/tests/CCEffectPongTest.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#import "CCEffectNode.h"
1313
#import "CCEffectGaussianBlur.h"
1414

15-
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
1615

1716
#define PADDLE_SCALE 0.5f
1817
#define PADDLE_X_OFFSET 10.0f
@@ -377,7 +376,3 @@ - (void)decreasePixellate:(CCTime)interval
377376

378377
@end
379378

380-
#endif
381-
382-
383-

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#import "CCEffectNode.h"
55
#import "CCEffectGaussianBlur.h"
66

7-
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
87

98
@interface CCEffectsTest : TestBase @end
109
@implementation CCEffectsTest
@@ -492,23 +491,111 @@ -(void)setupHueEffectTest
492491
}
493492
}
494493

494+
-(void)setupStackTest
495+
{
496+
self.subTitle = @"Effect Stacking Test";
497+
498+
CCSprite *reflectEnvironment = [CCSprite spriteWithImageNamed:@"Images/MountainPanorama.jpg"];
499+
reflectEnvironment.positionType = CCPositionTypeNormalized;
500+
reflectEnvironment.position = ccp(0.5f, 0.5f);
501+
reflectEnvironment.visible = NO;
502+
[self.contentNode addChild:reflectEnvironment];
503+
504+
CCSprite *refractEnvironment = [CCSprite spriteWithImageNamed:@"Images/StoneWall.jpg"];
505+
refractEnvironment.positionType = CCPositionTypeNormalized;
506+
refractEnvironment.position = ccp(0.5f, 0.5f);
507+
refractEnvironment.scale = 0.5;
508+
[self.contentNode addChild:refractEnvironment];
509+
510+
NSArray *effects = @[
511+
[CCEffectGaussianBlur effectWithPixelBlurRadius:7.0],
512+
[CCEffectBloom effectWithPixelBlurRadius:8 intensity:1.0f luminanceThreshold:0.0f],
513+
[CCEffectBrightness effectWithBrightness:0.25f],
514+
[CCEffectContrast effectWithContrast:1.0f],
515+
[CCEffectPixellate effectWithBlockSize:8.0f],
516+
[CCEffectSaturation effectWithSaturation:-1.0f],
517+
[CCEffectHue effectWithHue:90.0f],
518+
[CCEffectGlass effectWithRefraction:0.5f refractionEnvironment:refractEnvironment reflectionEnvironment:reflectEnvironment normalMap:nil],
519+
[CCEffectRefraction effectWithRefraction:0.5f environment:refractEnvironment normalMap:nil],
520+
[CCEffectReflection effectWithFresnelBias:0.2f fresnelPower:2.0f environment:reflectEnvironment normalMap:nil],
521+
];
522+
523+
524+
CCSprite *sprite = [CCSprite spriteWithImageNamed:@"Images/ShinyBallColor.png"];
525+
sprite.positionType = CCPositionTypeNormalized;
526+
sprite.position = ccp(0.1f, 0.9f);
527+
sprite.scale = 0.5f;
528+
529+
sprite.effect = [[CCEffectStack alloc] initWithEffects:@[effects[4]]];
530+
sprite.normalMapSpriteFrame = [CCSpriteFrame frameWithImageNamed:@"Images/ShinyBallNormals.png"];
531+
sprite.colorRGBA = [CCColor colorWithRed:0.75f green:0.75f blue:0.75f alpha:0.75f];
532+
533+
[self.contentNode addChild:sprite];
534+
535+
[sprite runAction:[CCActionRepeatForever actionWithAction:[CCActionSequence actions:
536+
[CCActionMoveTo actionWithDuration:8.0 position:ccp(0.9f, 0.9f)],
537+
[CCActionMoveTo actionWithDuration:8.0 position:ccp(0.9f, 0.1f)],
538+
[CCActionMoveTo actionWithDuration:8.0 position:ccp(0.1f, 0.1f)],
539+
[CCActionMoveTo actionWithDuration:8.0 position:ccp(0.1f, 0.9f)],
540+
nil
541+
]]];
542+
}
543+
495544
-(void)setupPerformanceTest
496545
{
497546
self.subTitle = @"Effect Performance Test";
547+
548+
CCSprite *reflectEnvironment = [CCSprite spriteWithImageNamed:@"Images/MountainPanorama.jpg"];
549+
reflectEnvironment.positionType = CCPositionTypeNormalized;
550+
reflectEnvironment.position = ccp(0.5f, 0.5f);
551+
reflectEnvironment.visible = NO;
552+
553+
CCSprite *refractEnvironment = [CCSprite spriteWithImageNamed:@"Images/StoneWall.jpg"];
554+
refractEnvironment.positionType = CCPositionTypeNormalized;
555+
refractEnvironment.position = ccp(0.5f, 0.5f);
556+
refractEnvironment.scale = 0.5;
557+
558+
NSArray *allEffects = @[
559+
[CCEffectGaussianBlur effectWithPixelBlurRadius:7.0],
560+
[CCEffectBloom effectWithPixelBlurRadius:8 intensity:1.0f luminanceThreshold:0.0f],
561+
[CCEffectBrightness effectWithBrightness:0.25f],
562+
[CCEffectContrast effectWithContrast:1.0f],
563+
[CCEffectPixellate effectWithBlockSize:4.0f],
564+
[CCEffectSaturation effectWithSaturation:-1.0f],
565+
[CCEffectHue effectWithHue:90.0f],
566+
[CCEffectGlass effectWithRefraction:0.5f refractionEnvironment:refractEnvironment reflectionEnvironment:reflectEnvironment normalMap:nil],
567+
[CCEffectRefraction effectWithRefraction:0.5f environment:refractEnvironment normalMap:nil],
568+
[CCEffectReflection effectWithFresnelBias:0.1f fresnelPower:4.0f environment:reflectEnvironment normalMap:nil],
569+
];
570+
CCEffect *selectedEffect = allEffects[8];
571+
572+
573+
CCSpriteFrame *normalMap = nil;
574+
if ([selectedEffect.debugName isEqualToString:@"CCEffectGlass"])
575+
{
576+
[self.contentNode addChild:reflectEnvironment];
577+
[self.contentNode addChild:refractEnvironment];
578+
normalMap = [CCSpriteFrame frameWithImageNamed:@"Images/ShinyBallNormals.png"];
579+
}
580+
else if ([selectedEffect.debugName isEqualToString:@"CCEffectRefraction"])
581+
{
582+
[self.contentNode addChild:refractEnvironment];
583+
normalMap = [CCSpriteFrame frameWithImageNamed:@"Images/ShinyBallNormals.png"];
584+
}
585+
else if ([selectedEffect.debugName isEqualToString:@"CCEffectReflection"])
586+
{
587+
[self.contentNode addChild:reflectEnvironment];
588+
normalMap = [CCSpriteFrame frameWithImageNamed:@"Images/ShinyBallNormals.png"];
589+
}
498590

499-
// CCEffect *glow = [CCEffectGlow effectWithBlurStrength:0.02f];
500-
// CCEffect *brightness = [[CCEffectBrightness alloc] initWithBrightness:0.25f];
501-
// CCEffect *contrast = [[CCEffectContrast alloc] initWithContrast:1.0f];
502-
// CCEffect *pixellate = [[CCEffectPixellate alloc] initWithBlockSize:4.0f];
503-
// CCEffect *blur = [CCEffectGaussianBlur effectWithBlurStrength:0.02f direction:GLKVector2Make(1.0, 1.0)];
504-
CCEffect *saturation = [[CCEffectSaturation alloc] initWithSaturation:0.0f];
505-
NSArray *effects = @[saturation];
506591

507592
CGSize containerSize = self.contentNode.contentSizeInPoints;
508593

509-
NSString *spriteImage = @"Images/snow.png";
510594
const float footprintScale = 1.1f;
511-
CCSprite *sprite = [self spriteWithEffects:effects image:spriteImage atPosition:ccp(0, 0)];
595+
596+
NSString *spriteImage = @"Images/r1.png";
597+
CCSprite *sprite = [CCSprite spriteWithImageNamed:spriteImage];
598+
512599
CGSize spriteSize = sprite.contentSizeInPoints;
513600
CGSize spriteFootprint = CGSizeMake(spriteSize.width * footprintScale, spriteSize.height * footprintScale);
514601
CGSize allSpritesBounds = CGSizeMake(((int)(containerSize.width / spriteFootprint.width) * spriteFootprint.width),
@@ -521,10 +608,25 @@ -(void)setupPerformanceTest
521608
{
522609
for (float xPos = origin.x; (xPos + spriteFootprint.width) < containerSize.width; xPos += spriteFootprint.width)
523610
{
524-
sprite = [self spriteWithEffects:effects image:spriteImage atPosition:ccp(xPos, yPos)];
525-
sprite.anchorPoint = ccp(0.0f, 0.0f);
611+
if (normalMap)
612+
{
613+
sprite = [[CCSprite alloc] init];
614+
sprite.normalMapSpriteFrame = normalMap;
615+
sprite.scale = 0.1f;
616+
sprite.colorRGBA = [CCColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f];
617+
}
618+
else
619+
{
620+
sprite = [CCSprite spriteWithImageNamed:spriteImage];
621+
}
622+
526623
sprite.positionType = CCPositionTypePoints;
624+
sprite.position = ccp(xPos, yPos);
625+
sprite.anchorPoint = ccp(0.0f, 0.0f);
626+
sprite.effect = selectedEffect;
627+
527628
[self.contentNode addChild:sprite];
629+
528630
count++;
529631
}
530632
}
@@ -608,5 +710,4 @@ -(void)renderTextureHelper:(CCNode *)stage size:(CGSize)size
608710
[node addChild:sprite];
609711
}
610712
@end
611-
#endif
612713

cocos2d/CCEffect.h

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -12,125 +12,8 @@
1212
#import "ccConfig.h"
1313
#import "ccTypes.h"
1414

15-
#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-
11415
@interface CCEffect : NSObject
11516

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;
12117
@property (nonatomic, copy) NSString *debugName;
12218

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-
13519
@end
136-
#endif

cocos2d/CCEffect.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
#import "CCEffect.h"
1010
#import "CCEffect_Private.h"
11-
#import "CCtexture.h"
11+
#import "CCTexture.h"
1212

13-
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
1413
NSString * const CCShaderUniformPreviousPassTexture = @"cc_PreviousPassTexture";
1514

1615
static NSString* fragBase =
@@ -537,7 +536,7 @@ - (CCEffectPrepareStatus)prepareForRendering
537536
-(CCEffectRenderPass *)renderPassAtIndex:(NSInteger)passIndex
538537
{
539538
NSAssert((passIndex >= 0) && (passIndex < _renderPasses.count), @"Pass index out of range.");
540-
return _renderPasses[passIndex];;
539+
return _renderPasses[passIndex];
541540
}
542541

543542
-(BOOL)stitchSupported:(CCEffectFunctionStitchFlags)stitch
@@ -548,7 +547,6 @@ -(BOOL)stitchSupported:(CCEffectFunctionStitchFlags)stitch
548547

549548

550549
@end
551-
#endif
552550

553551

554552

cocos2d/CCEffectBloom.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import "CCEffect.h"
1010

11-
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
1211
@interface CCEffectBloom : CCEffect
1312

1413
// ranges between 0.0-1.0 - defines which part of the image should be glown via a luminance factor (brightness).
@@ -33,4 +32,3 @@
3332
+(id)effectWithPixelBlurRadius:(NSUInteger)blurRadius intensity:(float)intensity luminanceThreshold:(float)luminanceThreshold;
3433

3534
@end
36-
#endif

0 commit comments

Comments
 (0)