Skip to content

Commit 1d6ce21

Browse files
committed
Giving [CCTexture +none] an actual texture and sampler to make the validation happy.
1 parent 74b8dff commit 1d6ce21

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cocos2d/CCTexture.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ +(void)initialize
186186
CCTextureNone->_name = 0;
187187
CCTextureNone->_format = CCTexturePixelFormat_RGBA8888;
188188
CCTextureNone->_contentScale = 1.0;
189+
190+
#if __CC_METAL_SUPPORTED_AND_ENABLED
191+
if([CCConfiguration sharedConfiguration].graphicsAPI == CCGraphicsAPIMetal){
192+
CCMetalContext *context = [CCMetalContext currentContext];
193+
NSAssert(context, @"Metal context is nil.");
194+
195+
CCTextureNone->_metalSampler = [context.device newSamplerStateWithDescriptor:[MTLSamplerDescriptor new]];
196+
197+
MTLTextureDescriptor *textureDesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:1 height:1 mipmapped:NO];
198+
CCTextureNone->_metalTexture = [context.device newTextureWithDescriptor:textureDesc];
199+
}
200+
#endif
189201
}
190202

191203
+(instancetype)none

cocos2d/Platforms/iOS/CCMetalSupport.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ -(void)prepare
238238

239239
CCTexture *texture = _shaderUniforms[CCShaderUniformMainTexture] ?: [CCTexture none];
240240
_textureRange = NSMakeRange(0, 1);
241-
_samplers[0] = texture.metalSampler ?: [context.device newSamplerStateWithDescriptor:[MTLSamplerDescriptor new]];
241+
_samplers[0] = texture.metalSampler;
242242
_textures[0] = texture.metalTexture;
243243
}
244244
}

0 commit comments

Comments
 (0)