Skip to content

Commit 3e133b9

Browse files
committed
Hardcoding builtin shaders support for now.
1 parent 92fdc15 commit 3e133b9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

cocos2d/Platforms/iOS/CCMetalSupport.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#if __CC_METAL_SUPPORTED_AND_ENABLED
2828

2929
#import "CCTexture_Private.h"
30+
#import "CCShader_Private.h"
3031

3132
@implementation CCMetalContext
3233

@@ -215,7 +216,15 @@ -(void)prepare
215216
id<MTLLibrary> library = context.library;
216217
#warning TEMP Hard coded shaders.
217218
pipelineStateDescriptor.vertexFunction = [library newFunctionWithName:@"CCVertexFunctionDefault"];
218-
pipelineStateDescriptor.fragmentFunction = [library newFunctionWithName:@"CCFragmentFunctionDefaultTextureColor"];
219+
if(_shader == [CCShader positionColorShader]){
220+
pipelineStateDescriptor.fragmentFunction = [library newFunctionWithName:@"CCFragmentFunctionDefaultColor"];
221+
} else if(_shader == [CCShader positionTextureColorShader]){
222+
pipelineStateDescriptor.fragmentFunction = [library newFunctionWithName:@"CCFragmentFunctionDefaultTextureColor"];
223+
} else if(_shader == [CCShader positionTextureA8ColorShader]){
224+
pipelineStateDescriptor.fragmentFunction = [library newFunctionWithName:@"CCFragmentFunctionDefaultTextureA8Color"];
225+
} else {
226+
pipelineStateDescriptor.fragmentFunction = [library newFunctionWithName:@"TempUnsupported"];
227+
}
219228

220229
NSDictionary *blendOptions = _blendMode.options;
221230
MTLRenderPipelineColorAttachmentDescriptor *colorDescriptor = [MTLRenderPipelineColorAttachmentDescriptor new];

cocos2d/Platforms/iOS/CCShaders.metal

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,13 @@ CCFragmentFunctionDefaultTextureA8Color(
5656
return in.color*mainTexture.sample(mainTextureSampler, in.texCoord1).a;
5757
}
5858

59+
fragment half4
60+
TempUnsupported(
61+
CCFragData in [[stage_in]],
62+
texture2d<half> mainTexture [[texture(0)]],
63+
sampler mainTextureSampler [[sampler(0)]]
64+
){
65+
return half4(1, 0, 1, 1);
66+
}
67+
5968
// TODO "alpha test" shader

0 commit comments

Comments
 (0)