genesis-3d_engine/Engine/graphicsystem/Material/MaterialManager.h
zhongdaohuan 6e8fbca745 genesis-3d engine version 1.3.
match the genesis editor version 1.3.0.653.
2014-05-05 14:50:33 +08:00

102 lines
4.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/****************************************************************************
Copyright (c) 2011-2013,WebJet Business Division,CYOU
http://www.genesis-3d.com.cn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __MaterialManager_H__
#define __MaterialManager_H__
#include "graphicsystem/GraphicSystem.h"
#include "addons/serialization/serialize.h"
namespace Graphic
{
class MaterialInstanceManager: public Core::RefCounted
{
__DeclareClass( MaterialInstanceManager )
public:
typedef Resources::ResourceId MaterialId;
MaterialInstanceManager();
virtual ~MaterialInstanceManager();
public:
// will be deprecated
GPtr<Graphic::MaterialInstance> CreateMaterialInstance( const Resources::ResourceId& shaderID );
GPtr<Graphic::MaterialInstance> NewMaterialInstanceCopyByMatID(const MaterialId& matID);
bool HaveMaterialInstance(const MaterialId& matID);
const GPtr<Graphic::MaterialInstance>& GetMaterialInstance(const MaterialId& matID);
// for serialization.
GPtr<Graphic::MaterialInstance> LoadMaterialInstance(const MaterialId& matID,const Resources::ResourceId& shaderID );
void RemoveMaterialInstance(const MaterialId& matID);
GPtr<Graphic::MaterialInstance> ModifyMaterialInstance(const MaterialId& matID,const Resources::ResourceId& newShaderID);
/*
* change material id.
Note<74><65> temp code.
<09><>Ϊ<EFBFBD><CEAA>ʱ<EFBFBD><CAB1><EFBFBD>룬Ϊ<EBA3AC><CEAA>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>޸<EFBFBD><DEB8>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>fbx<62><78><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD><D8B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void ModifyMaterialInstanceID(const MaterialId& matID,const MaterialId& newMatID);
void SaveMaterial();
void SaveOneMaterialInstance(const Resources::ResourceId& matID);
const IndexT GetMaterialNameIdx()const;
const SizeT GetMaterialCnt()const ;
GPtr<Graphic::MaterialInstance> UpdateShader(const Resources::ResourceId& shaderID);
Util::String GetInitParamValue(const Resources::ResourceId& matID,int paramIndex);
protected:
//
GPtr<Graphic::MaterialInstance> _CreateMaterialInstance( const Resources::ResourceId& shaderID );
GPtr<Graphic::MaterialInstance> _CreateNewMaterialInstance( const Resources::ResourceId& shaderID );
void _SetMaterialID(GPtr<Graphic::MaterialInstance>& matIns);
void _InitMaterialInstance(GPtr<Graphic::MaterialInstance>& matIns, const Resources::ResourceId& shaderID,const GPtr<Graphic::Material>& mat);
private:
typedef Util::Dictionary< Resources::ResourceId, GPtr<Graphic::Material> > GraphicMaterialMap;
typedef Util::Dictionary< MaterialId, GPtr<Graphic::MaterialInstance> > GraphicMaterialInstanceMap;
GraphicMaterialMap m_graphicMaterialMap;
GraphicMaterialInstanceMap m_graphicMaterialInstanceMap;
IndexT m_usedMaterialNameIdx;
friend class MaterialInstanceManagerSerialization;
friend class MaterialInstanceSerialization;
};
inline const IndexT MaterialInstanceManager::GetMaterialNameIdx()const
{
return m_usedMaterialNameIdx;
}
inline const SizeT MaterialInstanceManager::GetMaterialCnt()const
{
return m_graphicMaterialInstanceMap.Size();
}
}
#endif //MATERIALINSTANCE_H_