20
20
#import " CCTexture_Private.h"
21
21
22
22
23
- static CCSpriteVertexes padVertices (const CCSpriteVertexes *input, CGSize padding, BOOL padVertices);
24
- static CCVertex padVertex (CCVertex input, GLKVector2 positionOffset, GLKVector2 texCoord1Offset, GLKVector2 texCoord2Offset);
23
+ typedef NS_ENUM (NSUInteger , CCEffectTexCoordTransform)
24
+ {
25
+ CCEffectTexCoordNoChange = 0 ,
26
+ CCEffectTexCoordOverwrite = 1 ,
27
+ CCEffectTexCoordPad = 2 ,
28
+ };
29
+
30
+
31
+ static CCSpriteVertexes padVertices (const CCSpriteVertexes *input, CGSize padding, CCEffectTexCoordTransform texCoordTransform);
32
+ static CCVertex padVertex (CCVertex input, GLKVector2 positionOffset);
33
+ static CCVertex padVertexAndTexCoords (CCVertex input, GLKVector2 positionOffset, GLKVector2 texCoord1Offset, GLKVector2 texCoord2Offset);
34
+ static CCVertex padVertexAndOverwriteTexCoords (CCVertex input, GLKVector2 positionOffset, GLKVector2 texCoord1, GLKVector2 texCoord2);
35
+
25
36
26
37
@interface CCEffectRenderTarget : NSObject
27
38
@@ -229,8 +240,9 @@ -(void)drawSprite:(CCSprite *)sprite withEffect:(CCEffect *)effect uniforms:(NSM
229
240
// - Later pass into FB : Pad vertices but not texture coordiates
230
241
// - Later pass into intermediate RT : Pad vertices but not texture coordinates, add padding to RT, adjust ortho matrix
231
242
//
243
+ CCEffectTexCoordTransform texCoordTransform = (fromIntermediate) ? CCEffectTexCoordOverwrite : CCEffectTexCoordPad;
232
244
233
- renderPass.verts = padVertices (sprite.vertexes , effect.padding , !fromIntermediate );
245
+ renderPass.verts = padVertices (sprite.vertexes , effect.padding , texCoordTransform );
234
246
renderPass.texCoord1Center = GLKVector2Make ((sprite.vertexes ->tr .texCoord1 .s + sprite.vertexes ->bl .texCoord1 .s ) * 0 .5f , (sprite.vertexes ->tr .texCoord1 .t + sprite.vertexes ->bl .texCoord1 .t ) * 0 .5f );
235
247
renderPass.texCoord1Extents = GLKVector2Make ((sprite.vertexes ->tr .texCoord1 .s - sprite.vertexes ->bl .texCoord1 .s ) * 0 .5f , (sprite.vertexes ->tr .texCoord1 .t - sprite.vertexes ->bl .texCoord1 .t ) * 0 .5f );
236
248
renderPass.texCoord2Center = GLKVector2Make ((sprite.vertexes ->tr .texCoord2 .s + sprite.vertexes ->bl .texCoord2 .s ) * 0 .5f , (sprite.vertexes ->tr .texCoord2 .t + sprite.vertexes ->bl .texCoord2 .t ) * 0 .5f );
@@ -364,34 +376,53 @@ - (void)freeAllRenderTargets
364
376
365
377
@end
366
378
367
- CCSpriteVertexes padVertices (const CCSpriteVertexes *input, CGSize padding, BOOL padTexCoords )
379
+ CCSpriteVertexes padVertices (const CCSpriteVertexes *input, CGSize padding, CCEffectTexCoordTransform texCoordTransform )
368
380
{
369
381
CCSpriteVertexes output;
370
- if (CGSizeEqualToSize (CGSizeZero, padding) )
382
+ if (texCoordTransform == CCEffectTexCoordNoChange )
371
383
{
372
- output = *input;
384
+ output.bl = padVertex (input->bl , GLKVector2Make (-padding.width , -padding.height ));
385
+ output.br = padVertex (input->br , GLKVector2Make ( padding.width , -padding.height ));
386
+ output.tr = padVertex (input->tr , GLKVector2Make ( padding.width , padding.height ));
387
+ output.tl = padVertex (input->tl , GLKVector2Make (-padding.width , padding.height ));
373
388
}
374
- else
389
+ else if (texCoordTransform == CCEffectTexCoordOverwrite)
375
390
{
376
- GLKVector2 texCoord1Step = GLKVector2Make (0 .0f , 0 .0f );
377
- GLKVector2 texCoord2Step = GLKVector2Make (0 .0f , 0 .0f );
378
- if (padTexCoords)
379
- {
380
- texCoord1Step = GLKVector2Make (padding.width * (input->br .texCoord1 .s - input->bl .texCoord1 .s ) / (input->br .position .x - input->bl .position .x ),
381
- padding.height * (input->tl .texCoord1 .t - input->bl .texCoord1 .t ) / (input->tl .position .y - input->bl .position .y ));
382
- texCoord2Step = GLKVector2Make (padding.width * (input->br .texCoord2 .s - input->bl .texCoord2 .s ) / (input->br .position .x - input->bl .position .x ),
383
- padding.height * (input->tl .texCoord2 .t - input->bl .texCoord2 .t ) / (input->tl .position .y - input->bl .position .y ));
384
- }
391
+ output.bl = padVertexAndOverwriteTexCoords (input->bl , GLKVector2Make (-padding.width , -padding.height ), GLKVector2Make (0 .0f , 0 .0f ), GLKVector2Make (0 .0f , 0 .0f ));
392
+ output.br = padVertexAndOverwriteTexCoords (input->br , GLKVector2Make ( padding.width , -padding.height ), GLKVector2Make (1 .0f , 0 .0f ), GLKVector2Make (1 .0f , 0 .0f ));
393
+ output.tr = padVertexAndOverwriteTexCoords (input->tr , GLKVector2Make ( padding.width , padding.height ), GLKVector2Make (1 .0f , 1 .0f ), GLKVector2Make (1 .0f , 1 .0f ));
394
+ output.tl = padVertexAndOverwriteTexCoords (input->tl , GLKVector2Make (-padding.width , padding.height ), GLKVector2Make (0 .0f , 1 .0f ), GLKVector2Make (0 .0f , 1 .0f ));
395
+ }
396
+ else if (texCoordTransform == CCEffectTexCoordPad)
397
+ {
398
+ GLKVector2 texCoord1Step = GLKVector2Make (padding.width * (input->br .texCoord1 .s - input->bl .texCoord1 .s ) / (input->br .position .x - input->bl .position .x ),
399
+ padding.height * (input->tl .texCoord1 .t - input->bl .texCoord1 .t ) / (input->tl .position .y - input->bl .position .y ));
400
+ GLKVector2 texCoord2Step = GLKVector2Make (padding.width * (input->br .texCoord2 .s - input->bl .texCoord2 .s ) / (input->br .position .x - input->bl .position .x ),
401
+ padding.height * (input->tl .texCoord2 .t - input->bl .texCoord2 .t ) / (input->tl .position .y - input->bl .position .y ));
385
402
386
- output.bl = padVertex (input->bl , GLKVector2Make (-padding.width , -padding.height ), GLKVector2Make (-texCoord1Step.x , -texCoord1Step.y ), GLKVector2Make (-texCoord2Step.x , -texCoord2Step.y ));
387
- output.br = padVertex (input->br , GLKVector2Make ( padding.width , -padding.height ), GLKVector2Make ( texCoord1Step.x , -texCoord1Step.y ), GLKVector2Make ( texCoord2Step.x , -texCoord2Step.y ));
388
- output.tr = padVertex (input->tr , GLKVector2Make ( padding.width , padding.height ), GLKVector2Make ( texCoord1Step.x , texCoord1Step.y ), GLKVector2Make ( texCoord2Step.x , texCoord2Step.y ));
389
- output.tl = padVertex (input->tl , GLKVector2Make (-padding.width , padding.height ), GLKVector2Make (-texCoord1Step.x , texCoord1Step.y ), GLKVector2Make (-texCoord2Step.x , texCoord2Step.y ));
403
+ output.bl = padVertexAndTexCoords (input->bl , GLKVector2Make (-padding.width , -padding.height ), GLKVector2Make (-texCoord1Step.x , -texCoord1Step.y ), GLKVector2Make (-texCoord2Step.x , -texCoord2Step.y ));
404
+ output.br = padVertexAndTexCoords (input->br , GLKVector2Make ( padding.width , -padding.height ), GLKVector2Make ( texCoord1Step.x , -texCoord1Step.y ), GLKVector2Make ( texCoord2Step.x , -texCoord2Step.y ));
405
+ output.tr = padVertexAndTexCoords (input->tr , GLKVector2Make ( padding.width , padding.height ), GLKVector2Make ( texCoord1Step.x , texCoord1Step.y ), GLKVector2Make ( texCoord2Step.x , texCoord2Step.y ));
406
+ output.tl = padVertexAndTexCoords (input->tl , GLKVector2Make (-padding.width , padding.height ), GLKVector2Make (-texCoord1Step.x , texCoord1Step.y ), GLKVector2Make (-texCoord2Step.x , texCoord2Step.y ));
390
407
}
391
408
return output;
392
409
}
393
410
394
- CCVertex padVertex (CCVertex input, GLKVector2 positionOffset, GLKVector2 texCoord1Offset, GLKVector2 texCoord2Offset)
411
+ CCVertex padVertex (CCVertex input, GLKVector2 positionOffset)
412
+ {
413
+ CCVertex output;
414
+ output.position .x = input.position .x + positionOffset.x ;
415
+ output.position .y = input.position .y + positionOffset.y ;
416
+ output.position .z = input.position .z ;
417
+ output.position .w = input.position .w ;
418
+ output.texCoord1 = input.texCoord1 ;
419
+ output.texCoord2 = input.texCoord2 ;
420
+ output.color = input.color ;
421
+
422
+ return output;
423
+ }
424
+
425
+ CCVertex padVertexAndTexCoords (CCVertex input, GLKVector2 positionOffset, GLKVector2 texCoord1Offset, GLKVector2 texCoord2Offset)
395
426
{
396
427
CCVertex output;
397
428
output.position .x = input.position .x + positionOffset.x ;
@@ -407,3 +438,18 @@ CCVertex padVertex(CCVertex input, GLKVector2 positionOffset, GLKVector2 texCoor
407
438
return output;
408
439
}
409
440
441
+ CCVertex padVertexAndOverwriteTexCoords (CCVertex input, GLKVector2 positionOffset, GLKVector2 texCoord1, GLKVector2 texCoord2)
442
+ {
443
+ CCVertex output;
444
+ output.position .x = input.position .x + positionOffset.x ;
445
+ output.position .y = input.position .y + positionOffset.y ;
446
+ output.position .z = input.position .z ;
447
+ output.position .w = input.position .w ;
448
+ output.texCoord1 = texCoord1;
449
+ output.texCoord2 = texCoord2;
450
+ output.color = input.color ;
451
+
452
+ return output;
453
+ }
454
+
455
+
0 commit comments