[cocos2d-x] 修复纹理插槽设为 null 时警告与性能问题

This commit is contained in:
SmallMain 2022-06-25 01:00:46 +08:00
parent adb32f5c23
commit 7dbe1a4f72
2 changed files with 12 additions and 5 deletions

View File

@ -57,6 +57,8 @@ const size_t BaseRenderer::cc_matViewProj = std::hash<std::string>{}("cc_matView
const size_t BaseRenderer::cc_cameraPos = std::hash<std::string>{}("cc_cameraPos");
const size_t BaseRenderer::cc_time = std::hash<std::string>{}("cc_time");
Effect::Property* BaseRenderer::defaultTextureProperty = nullptr;
const size_t BaseRenderer::cc_shadow_map[4] = {
std::hash<std::string>{}("cc_shadow_map_0"),
std::hash<std::string>{}("cc_shadow_map_1"),
@ -212,11 +214,14 @@ void BaseRenderer::setProperty (const Effect::Property* prop)
if (nullptr == prop->getValue())
{
Effect::Property tmp(propName, propType);
prop = &tmp;
if (Effect::Property::Type::TEXTURE_2D == propType)
if (Effect::Property::Type::TEXTURE_2D == propType)
{
tmp.setTexture(_defaultTexture);
if (defaultTextureProperty == nullptr)
{
defaultTextureProperty = new Effect::Property(propName, propType);
defaultTextureProperty->setTexture(_defaultTexture);
}
prop = defaultTextureProperty;
}
}

View File

@ -152,7 +152,9 @@ protected:
static const size_t cc_matViewProj;
static const size_t cc_cameraPos;
static const size_t cc_time;
static Effect::Property* defaultTextureProperty;
static std::vector<const OrderedValueMap*> __tmp_defines__;
};