|
15 | 15 | #import "ccUtils.h" |
16 | 16 |
|
17 | 17 | #import "CCEffect_Private.h" |
| 18 | +#import "CCRenderer_Private.h" |
18 | 19 | #import "CCSprite_Private.h" |
19 | 20 | #import "CCTexture_Private.h" |
20 | 21 |
|
@@ -194,15 +195,33 @@ -(void)drawSprite:(CCSprite *)sprite withEffect:(CCEffect *)effect uniforms:(NSM |
194 | 195 | if (directRendering) |
195 | 196 | { |
196 | 197 | renderPass.transform = *transform; |
| 198 | + |
| 199 | + GLKMatrix4 ndcToWorldMat; |
| 200 | + [renderer.globalShaderUniforms[CCShaderUniformProjectionInv] getValue:&ndcToWorldMat]; |
| 201 | + renderPass.ndcToWorld = ndcToWorldMat; |
197 | 202 |
|
198 | 203 | [renderPass begin:previousPassTexture]; |
199 | 204 | [renderPass update]; |
200 | 205 | [renderPass end]; |
201 | 206 | } |
202 | 207 | else |
203 | 208 | { |
204 | | - renderPass.transform = GLKMatrix4MakeOrtho(0.0f, _contentSize.width, 0.0f, _contentSize.height, -1024.0f, 1024.0f); |
| 209 | + BOOL inverted; |
| 210 | + |
| 211 | + GLKMatrix4 renderTargetProjection = GLKMatrix4MakeOrtho(0.0f, _contentSize.width, 0.0f, _contentSize.height, -1024.0f, 1024.0f); |
| 212 | + GLKMatrix4 invRenderTargetProjection = GLKMatrix4Invert(renderTargetProjection, &inverted); |
| 213 | + NSAssert(inverted, @"Unable to invert matrix."); |
| 214 | + |
| 215 | + GLKMatrix4 invGlobalProjection; |
| 216 | + [renderer.globalShaderUniforms[CCShaderUniformProjectionInv] getValue:&invGlobalProjection]; |
| 217 | + |
| 218 | + GLKMatrix4 ndcToNodeMat = invRenderTargetProjection; |
| 219 | + GLKMatrix4 nodeToWorldMat = GLKMatrix4Multiply(invGlobalProjection, *transform); |
| 220 | + GLKMatrix4 ndcToWorldMat = GLKMatrix4Multiply(nodeToWorldMat, ndcToNodeMat); |
205 | 221 |
|
| 222 | + renderPass.transform = renderTargetProjection; |
| 223 | + renderPass.ndcToWorld = ndcToWorldMat; |
| 224 | + |
206 | 225 | CGSize rtSize = CGSizeMake(_contentSize.width * _contentScale, _contentSize.height * _contentScale); |
207 | 226 | rtSize.width = (rtSize.width <= 1.0f) ? 1.0f : rtSize.width; |
208 | 227 | rtSize.height = (rtSize.height <= 1.0f) ? 1.0f : rtSize.height; |
|
0 commit comments