mirror of https://github.com/axmolengine/axmol.git
fix material clone
This commit is contained in:
parent
d17c04cf0e
commit
137d180dc9
|
@ -45,9 +45,6 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Material* Material::_diffuseSkinnedMaterial = nullptr;
|
||||
Material* Material::_diffuseMaterial = nullptr;
|
||||
|
||||
// Helpers declaration
|
||||
static const char* getOptionalString(Properties* properties, const char* key, const char* defaultValue);
|
||||
static bool isValidUniform(const char* name);
|
||||
|
@ -428,7 +425,6 @@ Material::Material()
|
|||
: _name("")
|
||||
, _target(nullptr)
|
||||
, _currentTechnique(nullptr)
|
||||
, _materialType(Material::MaterialType::CUSTOM)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -446,13 +442,16 @@ Material* Material::clone() const
|
|||
for (const auto& technique: _techniques)
|
||||
{
|
||||
auto t = technique->clone();
|
||||
t->setParent(material);
|
||||
for (ssize_t i = 0; i < t->getPassCount(); i++) {
|
||||
t->getPassByIndex(i)->setParent(t);
|
||||
}
|
||||
material->_techniques.pushBack(t);
|
||||
}
|
||||
|
||||
// current technique
|
||||
auto name = _currentTechnique->getName();
|
||||
material->_currentTechnique = material->getTechniqueByName(name);
|
||||
material->_materialType = _materialType;
|
||||
|
||||
material->autorelease();
|
||||
}
|
||||
|
@ -502,29 +501,6 @@ ssize_t Material::getTechniqueCount() const
|
|||
return _techniques.size();
|
||||
}
|
||||
|
||||
Material* Material::createDiffuseMaterial(bool skinned)
|
||||
{
|
||||
if (skinned)
|
||||
{
|
||||
return _diffuseSkinnedMaterial->clone();
|
||||
}
|
||||
|
||||
return _diffuseMaterial->clone();
|
||||
}
|
||||
|
||||
void Material::loadDefaultMaterial(Material::MaterialType type)
|
||||
{
|
||||
if (_diffuseMaterial == nullptr)
|
||||
{
|
||||
auto glProgramState = GLProgramState::create(<#cocos2d::GLProgram *glprogram#>)
|
||||
_diffuseMaterial = Material::createWithGLStateProgram();
|
||||
}
|
||||
if (_diffuseSkinnedMaterial == nullptr)
|
||||
{
|
||||
_diffuseSkinnedMaterial = Material::createWithGLStateProgram();
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers implementation
|
||||
static bool isValidUniform(const char* name)
|
||||
{
|
||||
|
|
|
@ -63,14 +63,6 @@ class CC_DLL Material : public RenderState
|
|||
|
||||
public:
|
||||
|
||||
enum class MaterialType
|
||||
{
|
||||
DIFFUSE,
|
||||
NORMAL,
|
||||
LIGHTMAP,
|
||||
CUSTOM,
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a Material using the data from the Properties object defined at the specified URL,
|
||||
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
|
||||
|
@ -128,12 +120,7 @@ public:
|
|||
void setTechnique(const std::string& techniqueName);
|
||||
|
||||
/** returns a clone (deep-copy) of the material */
|
||||
Material* clone() const;
|
||||
|
||||
/** create default diffuse material */
|
||||
static Material* createDiffuseMaterial(bool skinned);
|
||||
|
||||
MaterialType getMaterialType() const { return _materialType; }
|
||||
virtual Material* clone() const;
|
||||
|
||||
protected:
|
||||
Material();
|
||||
|
@ -151,8 +138,6 @@ protected:
|
|||
bool parseSampler(GLProgramState* glProgramState, Properties* properties);
|
||||
bool parseUniform(GLProgramState* programState, Properties* properties, const char* uniformName);
|
||||
bool parseRenderState(RenderState* renderState, Properties* properties);
|
||||
|
||||
static void loadDefaultMaterial(MaterialType type);
|
||||
|
||||
// material name
|
||||
std::string _name;
|
||||
|
@ -166,10 +151,6 @@ protected:
|
|||
// weak reference
|
||||
Node* _target;
|
||||
|
||||
MaterialType _materialType;
|
||||
static Material* _diffuseSkinnedMaterial;
|
||||
static Material* _diffuseMaterial;
|
||||
// static Material*
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -84,6 +84,12 @@ public:
|
|||
* Returns the topmost RenderState in the hierarchy below the given RenderState.
|
||||
*/
|
||||
RenderState* getTopmost(RenderState* below);
|
||||
|
||||
/**
|
||||
* Set parent RenderState
|
||||
* @param parent Parent RenderState
|
||||
*/
|
||||
void setParent(RenderState* parent) { _parent = parent; }
|
||||
|
||||
enum Blend
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue