|
32 | 32 | #import "Support/CGPointExtension.h"
|
33 | 33 | #import "CCNode_Private.h"
|
34 | 34 | #import "CCColor.h"
|
| 35 | +#import "CCConfiguration.h" |
| 36 | +#import "CCMetalSupport_Private.h" |
35 | 37 |
|
36 | 38 | #ifdef ANDROID // Many Android devices do NOT support GL_OES_standard_derivatives correctly
|
37 | 39 | static NSString *CCDrawNodeShaderSource =
|
@@ -59,12 +61,25 @@ @implementation CCDrawNode {
|
59 | 61 |
|
60 | 62 | + (CCShader *)fragmentShader
|
61 | 63 | {
|
62 |
| - static CCShader *shader = nil; |
63 |
| - static dispatch_once_t once = 0L; |
64 |
| - dispatch_once(&once, ^{ |
65 |
| - shader = [[CCShader alloc] initWithFragmentShaderSource:CCDrawNodeShaderSource]; |
66 |
| - }); |
67 |
| - return shader; |
| 64 | + static CCShader *shader = nil; |
| 65 | + static dispatch_once_t once = 0L; |
| 66 | + dispatch_once(&once, ^{ |
| 67 | +#if __CC_METAL_SUPPORTED_AND_ENABLED |
| 68 | + if([CCConfiguration sharedConfiguration].graphicsAPI == CCGraphicsAPIMetal){ |
| 69 | + id<MTLLibrary> library = [CCMetalContext currentContext].library; |
| 70 | + NSAssert(library, @"Metal shader library not found."); |
| 71 | + |
| 72 | + id<MTLFunction> vertexFunc = [library newFunctionWithName:@"CCVertexFunctionDefault"]; |
| 73 | + |
| 74 | + shader = [[CCShader alloc] initWithMetalVertexFunction:vertexFunc fragmentFunction:[library newFunctionWithName:@"CCFragmentFunctionDefaultDrawNode"]]; |
| 75 | + shader.debugName = @"CCFragmentFunctionDefaultDrawNode"; |
| 76 | + } else |
| 77 | +#endif |
| 78 | + { |
| 79 | + shader = [[CCShader alloc] initWithFragmentShaderSource:CCDrawNodeShaderSource]; |
| 80 | + } |
| 81 | + }); |
| 82 | + return shader; |
68 | 83 | }
|
69 | 84 |
|
70 | 85 | #pragma mark memory
|
|
0 commit comments