mirror of
https://github.com/u0u0/Cocos2d-Lua-Community.git
synced 2026-05-31 21:20:56 +08:00
Sprite use custom shader with u_texture1 but not set, metal will assert fail, set a default texture for it. Mac glslopt_optimize show error log.
This commit is contained in:
@@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2021 cocos2d-lua.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
@@ -472,9 +473,14 @@ void Sprite::updateProgramStateTexture()
|
||||
auto programState = _trianglesCommand.getPipelineDescriptor().programState;
|
||||
programState->setTexture(_textureLocation, 0, _texture->getBackendTexture());
|
||||
auto alphaTexture = _texture->getAlphaTexture();
|
||||
if(alphaTexture && alphaTexture->getBackendTexture())
|
||||
{
|
||||
programState->setTexture(_alphaTextureLocation, 1, alphaTexture->getBackendTexture());
|
||||
// may ETC1 or user defined shader used u_texture1.
|
||||
if (_alphaTextureLocation.location[0] != -1 || _alphaTextureLocation.location[1] != -1) {
|
||||
if(alphaTexture && alphaTexture->getBackendTexture()) {
|
||||
programState->setTexture(_alphaTextureLocation, 1, alphaTexture->getBackendTexture());
|
||||
} else {
|
||||
// set a default texture into location to make metal render happy.
|
||||
programState->setTexture(_alphaTextureLocation, 1, _texture->getBackendTexture());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2021 cocos2d-lua.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
@@ -37,22 +38,16 @@ ShaderModuleMTL::ShaderModuleMTL(id<MTLDevice> mtlDevice, ShaderStage stage, con
|
||||
glslopt_ctx* ctx = glslopt_initialize(kGlslTargetMetal);
|
||||
glslopt_shader_type shaderType = stage == ShaderStage::VERTEX ? kGlslOptShaderVertex : kGlslOptShaderFragment;
|
||||
glslopt_shader* glslShader = glslopt_optimize(ctx, shaderType, source.c_str(), 0);
|
||||
if (!glslShader)
|
||||
{
|
||||
NSLog(@"Can not translate GLSL shader to metal shader:");
|
||||
NSLog(@"%s", source.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
const char* metalShader = glslopt_get_output(glslShader);
|
||||
if (!metalShader)
|
||||
{
|
||||
if (!glslopt_get_status(glslShader)) {
|
||||
NSLog(@"Can not get metal shader:");
|
||||
NSLog(@"%s", source.c_str());
|
||||
NSLog(@"%s", glslopt_get_log(glslShader));
|
||||
glslopt_shader_delete(glslShader);
|
||||
glslopt_cleanup(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
const char* metalShader = glslopt_get_output(glslShader);
|
||||
// NSLog(@"%s", metalShader);
|
||||
|
||||
parseAttibute(mtlDevice, glslShader);
|
||||
@@ -66,8 +61,7 @@ ShaderModuleMTL::ShaderModuleMTL(id<MTLDevice> mtlDevice, ShaderStage stage, con
|
||||
id<MTLLibrary> library = [mtlDevice newLibraryWithSource:shader
|
||||
options:nil
|
||||
error:&error];
|
||||
if (!library)
|
||||
{
|
||||
if (!library) {
|
||||
NSLog(@"Can not compile metal shader: %@", error);
|
||||
NSLog(@"%s", metalShader);
|
||||
glslopt_shader_delete(glslShader);
|
||||
@@ -79,8 +73,7 @@ ShaderModuleMTL::ShaderModuleMTL(id<MTLDevice> mtlDevice, ShaderStage stage, con
|
||||
_mtlFunction = [library newFunctionWithName:@"xlatMtlMain1"];
|
||||
else
|
||||
_mtlFunction = [library newFunctionWithName:@"xlatMtlMain2"];
|
||||
if (!_mtlFunction)
|
||||
{
|
||||
if (!_mtlFunction) {
|
||||
NSLog(@"metal shader is ---------------");
|
||||
NSLog(@"%s", metalShader);
|
||||
assert(false);
|
||||
|
||||
Reference in New Issue
Block a user