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
|
NS_CC_BEGIN
|
||||||
|
|
||||||
Material* Material::_diffuseSkinnedMaterial = nullptr;
|
|
||||||
Material* Material::_diffuseMaterial = nullptr;
|
|
||||||
|
|
||||||
// Helpers declaration
|
// Helpers declaration
|
||||||
static const char* getOptionalString(Properties* properties, const char* key, const char* defaultValue);
|
static const char* getOptionalString(Properties* properties, const char* key, const char* defaultValue);
|
||||||
static bool isValidUniform(const char* name);
|
static bool isValidUniform(const char* name);
|
||||||
|
@ -428,7 +425,6 @@ Material::Material()
|
||||||
: _name("")
|
: _name("")
|
||||||
, _target(nullptr)
|
, _target(nullptr)
|
||||||
, _currentTechnique(nullptr)
|
, _currentTechnique(nullptr)
|
||||||
, _materialType(Material::MaterialType::CUSTOM)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,13 +442,16 @@ Material* Material::clone() const
|
||||||
for (const auto& technique: _techniques)
|
for (const auto& technique: _techniques)
|
||||||
{
|
{
|
||||||
auto t = technique->clone();
|
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);
|
material->_techniques.pushBack(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// current technique
|
// current technique
|
||||||
auto name = _currentTechnique->getName();
|
auto name = _currentTechnique->getName();
|
||||||
material->_currentTechnique = material->getTechniqueByName(name);
|
material->_currentTechnique = material->getTechniqueByName(name);
|
||||||
material->_materialType = _materialType;
|
|
||||||
|
|
||||||
material->autorelease();
|
material->autorelease();
|
||||||
}
|
}
|
||||||
|
@ -502,29 +501,6 @@ ssize_t Material::getTechniqueCount() const
|
||||||
return _techniques.size();
|
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
|
// Helpers implementation
|
||||||
static bool isValidUniform(const char* name)
|
static bool isValidUniform(const char* name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,14 +63,6 @@ class CC_DLL Material : public RenderState
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum class MaterialType
|
|
||||||
{
|
|
||||||
DIFFUSE,
|
|
||||||
NORMAL,
|
|
||||||
LIGHTMAP,
|
|
||||||
CUSTOM,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Material using the data from the Properties object defined at the specified URL,
|
* 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>"
|
* 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);
|
void setTechnique(const std::string& techniqueName);
|
||||||
|
|
||||||
/** returns a clone (deep-copy) of the material */
|
/** returns a clone (deep-copy) of the material */
|
||||||
Material* clone() const;
|
virtual Material* clone() const;
|
||||||
|
|
||||||
/** create default diffuse material */
|
|
||||||
static Material* createDiffuseMaterial(bool skinned);
|
|
||||||
|
|
||||||
MaterialType getMaterialType() const { return _materialType; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Material();
|
Material();
|
||||||
|
@ -151,8 +138,6 @@ protected:
|
||||||
bool parseSampler(GLProgramState* glProgramState, Properties* properties);
|
bool parseSampler(GLProgramState* glProgramState, Properties* properties);
|
||||||
bool parseUniform(GLProgramState* programState, Properties* properties, const char* uniformName);
|
bool parseUniform(GLProgramState* programState, Properties* properties, const char* uniformName);
|
||||||
bool parseRenderState(RenderState* renderState, Properties* properties);
|
bool parseRenderState(RenderState* renderState, Properties* properties);
|
||||||
|
|
||||||
static void loadDefaultMaterial(MaterialType type);
|
|
||||||
|
|
||||||
// material name
|
// material name
|
||||||
std::string _name;
|
std::string _name;
|
||||||
|
@ -166,10 +151,6 @@ protected:
|
||||||
// weak reference
|
// weak reference
|
||||||
Node* _target;
|
Node* _target;
|
||||||
|
|
||||||
MaterialType _materialType;
|
|
||||||
static Material* _diffuseSkinnedMaterial;
|
|
||||||
static Material* _diffuseMaterial;
|
|
||||||
// static Material*
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -84,6 +84,12 @@ public:
|
||||||
* Returns the topmost RenderState in the hierarchy below the given RenderState.
|
* Returns the topmost RenderState in the hierarchy below the given RenderState.
|
||||||
*/
|
*/
|
||||||
RenderState* getTopmost(RenderState* below);
|
RenderState* getTopmost(RenderState* below);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set parent RenderState
|
||||||
|
* @param parent Parent RenderState
|
||||||
|
*/
|
||||||
|
void setParent(RenderState* parent) { _parent = parent; }
|
||||||
|
|
||||||
enum Blend
|
enum Blend
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue