Skip to content

Commit ff9f4aa

Browse files
committed
Merge branch 'develop' of github:cocos2d/cocos2d-iphone into develop
Conflicts: cocos2d/CCSprite.m
2 parents d1856f6 + 120f188 commit ff9f4aa

File tree

17 files changed

+487
-107
lines changed

17 files changed

+487
-107
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ -(id)init
1515
// Otherwise the scene will not exist yet.
1616
[self scheduleBlock:^(CCTimer *timer){self.scene.color = [CCColor lightGrayColor];} delay:0];
1717

18-
// Alternatively, set up some rotating colors.
19-
// float delay = 1.0f;
20-
// [self scheduleBlock:^(CCTimer *timer) {
21-
// GLKMatrix4 colorMatrix = GLKMatrix4MakeRotation(timer.invokeTime*1e0, 1, 1, 1);
22-
// GLKVector4 color = GLKMatrix4MultiplyVector4(colorMatrix, GLKVector4Make(1, 0, 0, 1));
23-
// self.scene.color = [CCColor colorWithGLKVector4:color];
24-
//
25-
// [timer repeatOnceWithInterval:delay];
26-
// } delay:delay];
18+
// Alternatively, set up some rotating colors.
19+
// float delay = 1.0f;
20+
// [self scheduleBlock:^(CCTimer *timer) {
21+
// GLKMatrix4 colorMatrix = GLKMatrix4MakeRotation(timer.invokeTime*1e0, 1, 1, 1);
22+
// GLKVector4 color = GLKMatrix4MultiplyVector4(colorMatrix, GLKVector4Make(1, 0, 0, 1));
23+
// self.scene.color = [CCColor colorWithGLKVector4:color];
24+
//
25+
// [timer repeatOnceWithInterval:delay];
26+
// } delay:delay];
2727
}
2828

2929
return self;
3030
}
3131

32-
#define WORKING_GLOW
32+
//#define GLOW_WITHOUT_AUTO_DRAW
3333
-(void)setupGlowEffectNodeTest
3434
{
3535
// CCSprite *testSprite = [CCSprite spriteWithImageNamed:@"sample_hollow_circle.png"];
@@ -53,11 +53,12 @@ -(void)setupGlowEffectNodeTest
5353
glowEffectNode.positionType = CCPositionTypeNormalized;
5454
glowEffectNode.position = ccp(0.1, 0.5);
5555
[glowEffectNode addChild:sampleSprite];
56-
CCEffectGlow* glowEffect = [[CCEffectGlow alloc] init];
56+
CCEffectGlow* glowEffect = [CCEffectGlow effectWithRadius:0.01f];
5757
glowEffectNode.effect = glowEffect;
5858

59-
#ifdef WORKING_GLOW
59+
#ifdef GLOW_WITHOUT_AUTO_DRAW
6060
[glowEffectNode visit];
61+
6162
CCSprite* testSrpite = [CCSprite spriteWithTexture:glowEffectNode.texture];
6263
testSrpite.positionType = CCPositionTypeNormalized;
6364
testSrpite.position = ccp(0.6, 0.5);
@@ -70,6 +71,15 @@ -(void)setupGlowEffectNodeTest
7071
[self.contentNode addChild:defaultSprite];
7172

7273
#else
74+
75+
CGSize size = CGSizeMake(1.0, 1.0);
76+
[glowEffectNode runAction:[CCActionRepeatForever actionWithAction:[CCActionSequence actions:
77+
[CCActionMoveTo actionWithDuration:4.0 position:ccp(0, 0.5)],
78+
[CCActionMoveTo actionWithDuration:4.0 position:ccp(size.width, 0.5)],
79+
nil
80+
]]];
81+
82+
7383
[self.contentNode addChild:glowEffectNode];
7484
#endif
7585

@@ -96,31 +106,38 @@ -(void)setupBrightnessAndContrastEffectNodeTest
96106
{
97107
self.subTitle = @"Brightness and Contrast Effect Test";
98108

99-
// Create a sprite
100-
CCSprite *effectSprite = [CCSprite spriteWithImageNamed:@"f1.png"];
101-
effectSprite.anchorPoint = ccp(0.5, 0.5);
102-
effectSprite.position = ccp(40, 40);
109+
CCSprite *sprite = nil;
103110

111+
// Add a couple sprites directly to the scene
112+
sprite = [CCSprite spriteWithImageNamed:@"f1.png"];
113+
sprite.anchorPoint = ccp(0.5, 0.5);
114+
sprite.positionType = CCPositionTypeNormalized;
115+
sprite.position = ccp(0.4, 0.5);
116+
[self.contentNode addChild:sprite];
117+
118+
sprite = [CCSprite spriteWithImageNamed:@"f1.png"];
119+
sprite.anchorPoint = ccp(0.5, 0.5);
120+
sprite.positionType = CCPositionTypeNormalized;
121+
sprite.position = ccp(0.5, 0.6);
122+
[self.contentNode addChild:sprite];
123+
124+
// Create third sprite for use with the effect. It does
125+
// not get added to the scene directly.
126+
sprite = [CCSprite spriteWithImageNamed:@"f1.png"];
127+
sprite.anchorPoint = ccp(0.5, 0.5);
128+
sprite.positionType = CCPositionTypeNormalized;
129+
sprite.position = ccp(0.5, 0.5);
130+
104131
// Brightness and contrast test
105-
CCEffectNode* effectNode = [[CCEffectNode alloc] initWithWidth:80 height:80];
132+
float effectDim = MAX(sprite.contentSize.width, sprite.contentSize.width);
133+
CCEffectNode* effectNode = [[CCEffectNode alloc] initWithWidth:effectDim height:effectDim];
134+
effectNode.anchorPoint = ccp(0.5, 0.5);
106135
effectNode.positionType = CCPositionTypeNormalized;
107-
effectNode.position = ccp(0.1, 0.5);
108-
[effectNode addChild:effectSprite];
109-
CCEffectBrightnessAndContrast* effect = [[CCEffectBrightnessAndContrast alloc] initWithBrightness:0.5f contrast:4.0f];
110-
111-
effectNode.effect = effect;
112-
[effectNode visit];
113-
114-
CCSprite* testSprite = [CCSprite spriteWithTexture:effectNode.texture];
115-
testSprite.positionType = CCPositionTypeNormalized;
116-
testSprite.position = ccp(0.5, 0.5);
117-
[self.contentNode addChild:testSprite];
118-
119-
CCSprite *defaultSprite = [CCSprite spriteWithImageNamed:@"f1.png"];
120-
defaultSprite.anchorPoint = ccp(0.5, 0.5);
121-
defaultSprite.positionType = CCPositionTypeNormalized;
122-
defaultSprite.position = ccp(0.1, 0.5);
123-
[self.contentNode addChild:defaultSprite];
136+
effectNode.position = ccp(0.5, 0.4);
137+
effectNode.effect = [[CCEffectBrightnessAndContrast alloc] initWithBrightness:0.25f contrast:2.0f];
138+
[effectNode addChild:sprite];
139+
140+
[self.contentNode addChild:effectNode];
124141
}
125142

126143
-(void)renderTextureHelper:(CCNode *)stage size:(CGSize)size

cocos2d-ui-tests/tests/CCRendererTest.m

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "TestBase.h"
22
#import "CCTextureCache.h"
3+
#import "CCNodeColor.h"
34
//#import "CCNode_Private.h"
45

56
@interface CustomSprite : CCNode<CCShaderProtocol, CCTextureProtocol> @end
@@ -329,6 +330,12 @@ - (void)setupMotionStreakNodeTest
329330
}
330331
}
331332

333+
static float
334+
ProgressPercent(CCTime t)
335+
{
336+
return 100.0*fmod(t, 1.0);
337+
}
338+
332339
- (void)setupProgressNodeTest
333340
{
334341
self.subTitle = @"Testing various CCProgressNode setups.";
@@ -352,7 +359,7 @@ - (void)setupProgressNodeTest
352359
[self.contentNode addChild:progress];
353360

354361
[self scheduleBlock:^(CCTimer *timer) {
355-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
362+
progress.percentage = ProgressPercent(timer.invokeTime);
356363
[timer repeatOnceWithInterval:interval];
357364
} delay:interval];
358365
}
@@ -377,7 +384,7 @@ - (void)setupProgressNodeTest
377384

378385
[self scheduleBlock:^(CCTimer *timer) {
379386
progress.midpoint = ccpAdd(ccp(0.5, 0.5), ccpMult(ccpForAngle(timer.invokeTime), 0.25));
380-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
387+
progress.percentage = ProgressPercent(timer.invokeTime);
381388

382389
[timer repeatOnceWithInterval:interval];
383390
} delay:interval];
@@ -403,7 +410,7 @@ - (void)setupProgressNodeTest
403410
[self.contentNode addChild:progress];
404411

405412
[self scheduleBlock:^(CCTimer *timer) {
406-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
413+
progress.percentage = ProgressPercent(timer.invokeTime);
407414

408415
[timer repeatOnceWithInterval:interval];
409416
} delay:interval];
@@ -429,7 +436,7 @@ - (void)setupProgressNodeTest
429436
[self.contentNode addChild:progress];
430437

431438
[self scheduleBlock:^(CCTimer *timer) {
432-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
439+
progress.percentage = ProgressPercent(timer.invokeTime);
433440

434441
[timer repeatOnceWithInterval:interval];
435442
} delay:interval];
@@ -455,7 +462,7 @@ - (void)setupProgressNodeTest
455462
[self.contentNode addChild:progress];
456463

457464
[self scheduleBlock:^(CCTimer *timer) {
458-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
465+
progress.percentage = ProgressPercent(timer.invokeTime);
459466

460467
[timer repeatOnceWithInterval:interval];
461468
} delay:interval];
@@ -481,7 +488,7 @@ - (void)setupProgressNodeTest
481488
[self.contentNode addChild:progress];
482489

483490
[self scheduleBlock:^(CCTimer *timer) {
484-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
491+
progress.percentage = ProgressPercent(timer.invokeTime);
485492

486493
[timer repeatOnceWithInterval:interval];
487494
} delay:interval];
@@ -507,7 +514,7 @@ - (void)setupProgressNodeTest
507514
[self.contentNode addChild:progress];
508515

509516
[self scheduleBlock:^(CCTimer *timer) {
510-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
517+
progress.percentage = ProgressPercent(timer.invokeTime);
511518

512519
[timer repeatOnceWithInterval:interval];
513520
} delay:interval];
@@ -533,7 +540,7 @@ - (void)setupProgressNodeTest
533540
[self.contentNode addChild:progress];
534541

535542
[self scheduleBlock:^(CCTimer *timer) {
536-
progress.percentage = 100.0*(0.5 + 0.5*sin(timer.invokeTime*M_PI));
543+
progress.percentage = ProgressPercent(timer.invokeTime);
537544

538545
[timer repeatOnceWithInterval:interval];
539546
} delay:interval];
@@ -547,6 +554,10 @@ - (void)setupDrawNodeTest
547554
CCDrawNode *draw = [CCDrawNode node];
548555

549556
[draw drawDot:ccp(100, 100) radius:50 color:[CCColor colorWithRed:0.5 green:0.0 blue:0.0 alpha:0.75]];
557+
558+
// This yellow dot should not be visible.
559+
[draw drawDot:ccp(150, 150) radius:50 color:[CCColor colorWithRed:0.5 green:0.5 blue:0.0 alpha:0.0]];
560+
550561
[draw drawSegmentFrom:ccp(100, 200) to:ccp(200, 200) radius:25 color:[CCColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.75]];
551562

552563
CGPoint points1[] = {

cocos2d/CCDrawNode.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,16 @@ -(void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
134134

135135
#pragma mark Immediate Mode
136136

137+
static inline GLKVector4
138+
Premultiply(GLKVector4 c)
139+
{
140+
return GLKVector4Make(c.r*c.a, c.g*c.a, c.b*c.a, c.a);
141+
}
142+
137143
-(void)drawDot:(CGPoint)pos radius:(CGFloat)radius color:(CCColor *)color;
138144
{
139-
GLKVector4 color4 = color.glkVector4;
145+
GLKVector4 color4 = Premultiply(color.glkVector4);
146+
140147
GLKVector2 zero2 = GLKVector2Make(0, 0);
141148

142149
CCRenderBuffer buffer = [self bufferVertexes:4 andTriangleCount:2];
@@ -159,7 +166,7 @@ -(void)drawDot:(CGPoint)pos radius:(CGFloat)radius color:(CCColor *)color;
159166

160167
-(void)drawSegmentFrom:(CGPoint)_a to:(CGPoint)_b radius:(CGFloat)radius color:(CCColor*)color;
161168
{
162-
GLKVector4 color4 = color.glkVector4;
169+
GLKVector4 color4 = Premultiply(color.glkVector4);
163170
GLKVector2 a = GLKVector2Make(_a.x, _a.y);
164171
GLKVector2 b = GLKVector2Make(_b.x, _b.y);
165172

@@ -189,8 +196,8 @@ -(void)drawSegmentFrom:(CGPoint)_a to:(CGPoint)_b radius:(CGFloat)radius color:(
189196

190197
-(void)drawPolyWithVerts:(const CGPoint *)_verts count:(NSUInteger)count fillColor:(CCColor*)fill borderWidth:(CGFloat)width borderColor:(CCColor*)line;
191198
{
192-
GLKVector4 fill4 = fill.glkVector4;
193-
GLKVector4 line4 = line.glkVector4;
199+
GLKVector4 fill4 = Premultiply(fill.glkVector4);
200+
GLKVector4 line4 = Premultiply(line.glkVector4);
194201

195202
GLKVector2 verts[count];
196203
for(int i=0; i<count; i++) verts[i] = GLKVector2Make(_verts[i].x, _verts[i].y);

cocos2d/CCEffect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "CCSprite.h"
1111
#import "CCShader.h"
1212
#import "ccConfig.h"
13-
#import <ccTypes.h>
13+
#import "ccTypes.h"
1414

1515
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
1616
@interface CCEffectFunction : NSObject

cocos2d/CCEffectBrightnessAndContrast.m

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ -(id)initWithBrightness:(float)brightness contrast:(float)contrast
3333
-(void)buildFragmentFunctions
3434
{
3535
NSString* effectBody = CC_GLSL(
36-
vec4 pixelValue = texture2D(cc_MainTexture, cc_FragTexCoord1);
37-
if (u_brightness < 0.0)
38-
{
39-
pixelValue = pixelValue * (1.0 + u_brightness);
40-
}
41-
else
42-
{
43-
pixelValue = pixelValue + ((1.0 - pixelValue) * u_brightness);
44-
}
45-
return (pixelValue - 0.5) * u_contrast + 0.5;
36+
vec4 inputValue = texture2D(cc_MainTexture, cc_FragTexCoord1);
37+
38+
vec3 brightnessAdjusted = inputValue.rgb + vec3(u_brightness);
39+
vec3 contrastAdjusted = (brightnessAdjusted - vec3(0.5)) * vec3(u_contrast) + vec3(0.5);
40+
41+
return vec4(contrastAdjusted, inputValue.a);
4642
);
4743

4844
CCEffectFunction* fragmentFunction = [[CCEffectFunction alloc] initWithName:@"brightnessAndContrastEffect" body:effectBody returnType:@"vec4"];
@@ -90,8 +86,11 @@ -(void)renderPassEnd:(CCEffectRenderPass*)renderPass defaultBlock:(void (^)())de
9086
if (renderPass.renderPassId == 1)
9187
{
9288
GLKMatrix4 transform = renderPass.transform;
89+
90+
renderPass.sprite.anchorPoint = ccp(0.5, 0.5);
9391
renderPass.sprite.texture = renderPass.textures[1];
9492
renderPass.sprite.shader = [CCShader positionTextureColorShader];
93+
renderPass.sprite.blendMode = [CCBlendMode alphaMode];
9594
[renderPass.sprite visit:renderPass.renderer parentTransform:&transform];
9695
}
9796
}

cocos2d/CCEffectGlow.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
1212
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
1313
@interface CCEffectGlow : CCEffect
1414

15+
@property (nonatomic) float blurRadius;
16+
17+
-(id)initWithBlurRadius:(float)blurRadius;
18+
+(id)effectWithRadius:(float)blurRadius;
19+
1520
@end
1621
#endif

0 commit comments

Comments
 (0)