BVB Source Codes

CRYENGINE Show MatMan.h Source code

Return Download CRYENGINE: download MatMan.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   MatMan.h
  5. //  Version:     v1.00
  6. //  Created:     23/8/2004 by Timur.
  7. //  Compilers:   Visual Studio.NET 2003
  8. //  Description:
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. #ifndef __MatMan_h__
  15. #define __MatMan_h__
  16. #pragma once
  17.  
  18. #include "Cry3DEngineBase.h"
  19. #include "SurfaceTypeManager.h"
  20. #include <CryThreading/CryThreadSafeRendererContainer.h>
  21. #include "MaterialHelpers.h"
  22.  
  23. #define MATERIAL_DELETION_DELAY 3 // Number of frames delay + 1
  24.  
  25. // forward declarations.
  26. struct IMaterial;
  27. struct ISurfaceType;
  28. struct ISurfaceTypeManager;
  29. class CMatInfo;
  30.  
  31. //////////////////////////////////////////////////////////////////////////
  32. //
  33. // CMatMan is a material manager class.
  34. //
  35. //////////////////////////////////////////////////////////////////////////
  36. class CMatMan : public IMaterialManager, public Cry3DEngineBase
  37. {
  38. public:
  39.         CMatMan();
  40.         virtual ~CMatMan();
  41.  
  42.         void ShutDown();
  43.  
  44.         // interface IMaterialManager --------------------------------------------------------
  45.  
  46.         virtual IMaterial* CreateMaterial(const char* sMtlName, int nMtlFlags = 0);
  47.         virtual IMaterial* FindMaterial(const char* sMtlName) const;
  48.         virtual IMaterial* LoadMaterial(const char* sMtlName, bool bMakeIfNotFound = true, bool bNonremovable = false, unsigned long nLoadingFlags = 0);
  49.         virtual IMaterial* LoadMaterialFromXml(const char* sMtlName, XmlNodeRef mtlNode);
  50.         virtual void       SetListener(IMaterialManagerListener* pListener) { m_pListener = pListener; };
  51.         virtual IMaterial* GetDefaultMaterial();
  52.         virtual IMaterial* GetDefaultTerrainLayerMaterial()
  53.         {
  54.                 if (!m_bInitialized)
  55.                 {
  56.                         InitDefaults();
  57.                 }
  58.                 return m_pDefaultTerrainLayersMtl;
  59.         }
  60.         virtual IMaterial*    GetDefaultLayersMaterial();
  61.         virtual IMaterial*    GetDefaultHelperMaterial();
  62.         virtual ISurfaceType* GetSurfaceTypeByName(const char* sSurfaceTypeName, const char* sWhy = NULL);
  63.         virtual int           GetSurfaceTypeIdByName(const char* sSurfaceTypeName, const char* sWhy = NULL);
  64.         virtual ISurfaceType* GetSurfaceType(int nSurfaceTypeId, const char* sWhy = NULL)
  65.         {
  66.                 return m_pSurfaceTypeManager->GetSurfaceTypeFast(nSurfaceTypeId, sWhy);
  67.         }
  68.         virtual ISurfaceTypeManager* GetSurfaceTypeManager() { return m_pSurfaceTypeManager; }
  69.         virtual IMaterial*           LoadCGFMaterial(const char* szMaterialName, const char* szCgfFilename, unsigned long nLoadingFlags = 0);
  70.         virtual IMaterial*           CloneMaterial(IMaterial* pMtl, int nSubMtl = -1);
  71.         virtual IMaterial*           CloneMultiMaterial(IMaterial* pMtl, const char* sSubMtlName = 0);
  72.         virtual void                 GetLoadedMaterials(IMaterial** pData, uint32& nObjCount) const;
  73.         virtual void                 SetAltMaterialSuffix(const char* pSuffix);
  74.  
  75.         virtual void                 CopyMaterial(IMaterial* pMtlSrc, IMaterial* pMtlDest, EMaterialCopyFlags flags);
  76.  
  77.         virtual void                 RenameMaterial(IMaterial* pMtl, const char* sNewName);
  78.         virtual void                 RefreshMaterialRuntime();
  79.         // ------------------------------------------------------------------------------------
  80.  
  81.         void InitDefaults();
  82.  
  83.         void PreloadLevelMaterials();
  84.         void DoLoadSurfaceTypesInInit(bool doLoadSurfaceTypesInInit);
  85.  
  86.         void UpdateShaderItems();
  87.         void RefreshShaderResourceConstants();
  88.  
  89.         // Load all known game decal materials.
  90.         void PreloadDecalMaterials();
  91.  
  92.         void SetSketchMode(int mode);
  93.         int  GetSketchMode()        { return e_sketch_mode; }
  94.         void SetTexelDensityDebug(int mode);
  95.         int  GetTexelDensityDebug() { return e_texeldensity; }
  96.  
  97.         //////////////////////////////////////////////////////////////////////////
  98.         ISurfaceType* GetSurfaceTypeFast(int nSurfaceTypeId, const char* sWhy = NULL) { return m_pSurfaceTypeManager->GetSurfaceTypeFast(nSurfaceTypeId, sWhy); }
  99.  
  100.         virtual void  GetMemoryUsage(ICrySizer* pSizer) const;
  101.  
  102.         void          DelayedMaterialDeletion();
  103.  
  104. private: // -----------------------------------------------------------------------------
  105.         friend class CMatInfo;
  106.         void        Unregister(CMatInfo* pMat);
  107.  
  108.         void        DelayedDelete(CMatInfo* pMat);
  109.         void        ForceDelayedMaterialDeletion();
  110.  
  111.         bool        LoadMaterialShader(IMaterial* pMtl, IMaterial* pParentMtl, const char* sShader, uint64 nShaderGenMask, SInputShaderResources& sr, XmlNodeRef& publicsNode, unsigned long nLoadingFlags = 0);
  112.         bool        LoadMaterialLayerSlot(uint32 nSlot, IMaterial* pMtl, const char* szShaderName, SInputShaderResources& pBaseResources, XmlNodeRef& pPublicsNode, uint8 nLayerFlags);
  113.  
  114.         void        ParsePublicParams(SInputShaderResources& sr, XmlNodeRef paramsNode);
  115.         const char* UnifyName(const char* sMtlName) const;
  116.         // Can be called after material creation and initialization, to inform editor that new material in engine exist.
  117.         // Only used internally.
  118.         void       NotifyCreateMaterial(IMaterial* pMtl);
  119.         // Make a valid material from the XML node.
  120.         IMaterial* MakeMaterialFromXml(const char* sMtlName, const char* sMtlFilename, XmlNodeRef node, bool bForcePureChild, uint16 sortPrio = 0, IMaterial* pExistingMtl = 0, unsigned long nLoadingFlags = 0, IMaterial* pParentMtl = 0);
  121.  
  122.         void       FreeAllMaterials();
  123.  
  124. private:
  125.         typedef std::map<string, IMaterial*> MtlNameMap;
  126.  
  127.         CryCriticalSection                m_DelayedDeletionMtlsLock;
  128.  
  129.         MtlNameMap                        m_mtlNameMap;                   //
  130.  
  131.         IMaterialManagerListener*         m_pListener;                    //
  132.         _smart_ptr<CMatInfo>              m_pDefaultMtl;                  //
  133.         _smart_ptr<IMaterial>             m_pDefaultLayersMtl;            //
  134.         _smart_ptr<CMatInfo>              m_pDefaultTerrainLayersMtl;     //
  135.         _smart_ptr<CMatInfo>              m_pNoDrawMtl;                   //
  136.         _smart_ptr<CMatInfo>              m_pDefaultHelperMtl;
  137.  
  138.         std::vector<_smart_ptr<CMatInfo>> m_nonRemovables;                //
  139.  
  140.         std::vector<_smart_ptr<CMatInfo>> m_DelayedDeletionMtls[MATERIAL_DELETION_DELAY];
  141.  
  142.         CSurfaceTypeManager*              m_pSurfaceTypeManager;          //
  143.  
  144.         string                            m_altSuffix;
  145.  
  146.         //////////////////////////////////////////////////////////////////////////
  147.         // Cached XML parser.
  148.         _smart_ptr<IXmlParser> m_pXmlParser;
  149.  
  150.         bool                   m_bInitialized;
  151.         bool                   m_bLoadSurfaceTypesInInit;
  152.         uint8                  m_nDelayedDeleteID;
  153.  
  154. public:
  155.         // Global namespace "instance", not a class "instance", no member-variables, only const functions;
  156.         // Used to encapsulate the material-definition/io into Cry3DEngine (and make it plugable that way).
  157.         static MaterialHelpers s_materialHelpers;
  158.  
  159.         static int             e_sketch_mode;
  160.         static int             e_lowspec_mode;
  161.         static int             e_pre_sketch_spec;
  162.         static int             e_texeldensity;
  163. };
  164.  
  165. #endif // __MatMan_h__
  166.  
downloadMatMan.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top