From 7dbe1a4f7274d3731f1ac9b57d14c73378e5863a Mon Sep 17 00:00:00 2001 From: SmallMain Date: Sat, 25 Jun 2022 01:00:46 +0800 Subject: [PATCH] =?UTF-8?q?[cocos2d-x]=20=E4=BF=AE=E5=A4=8D=E7=BA=B9?= =?UTF-8?q?=E7=90=86=E6=8F=92=E6=A7=BD=E8=AE=BE=E4=B8=BA=20null=20?= =?UTF-8?q?=E6=97=B6=E8=AD=A6=E5=91=8A=E4=B8=8E=E6=80=A7=E8=83=BD=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos2d-x/cocos/renderer/renderer/BaseRenderer.cpp | 13 +++++++++---- cocos2d-x/cocos/renderer/renderer/BaseRenderer.h | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cocos2d-x/cocos/renderer/renderer/BaseRenderer.cpp b/cocos2d-x/cocos/renderer/renderer/BaseRenderer.cpp index 7d7889cb..a937c69e 100644 --- a/cocos2d-x/cocos/renderer/renderer/BaseRenderer.cpp +++ b/cocos2d-x/cocos/renderer/renderer/BaseRenderer.cpp @@ -57,6 +57,8 @@ const size_t BaseRenderer::cc_matViewProj = std::hash{}("cc_matView const size_t BaseRenderer::cc_cameraPos = std::hash{}("cc_cameraPos"); const size_t BaseRenderer::cc_time = std::hash{}("cc_time"); +Effect::Property* BaseRenderer::defaultTextureProperty = nullptr; + const size_t BaseRenderer::cc_shadow_map[4] = { std::hash{}("cc_shadow_map_0"), std::hash{}("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; } } diff --git a/cocos2d-x/cocos/renderer/renderer/BaseRenderer.h b/cocos2d-x/cocos/renderer/renderer/BaseRenderer.h index d4e70f5f..1a4bff22 100644 --- a/cocos2d-x/cocos/renderer/renderer/BaseRenderer.h +++ b/cocos2d-x/cocos/renderer/renderer/BaseRenderer.h @@ -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 __tmp_defines__; };