Torque3D Documentation / _generateds / materialManager.h

materialManager.h

Engine/source/materials/materialManager.h

More...

Classes:

Public Defines

define
MATMGR() ()

Helper for accessing MaterialManager singleton.

Detailed Description

Public Defines

MATMGR() ()

Helper for accessing MaterialManager singleton.

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23#ifndef _MATERIAL_MGR_H_
 24#define _MATERIAL_MGR_H_
 25
 26#ifndef _MATERIALDEFINITION_H_
 27#include "materials/materialDefinition.h"
 28#endif
 29#ifndef _FEATURESET_H_
 30#include "shaderGen/featureSet.h"
 31#endif
 32#ifndef _GFXDEVICE_H_
 33#include "gfx/gfxDevice.h"
 34#endif
 35#ifndef _TSINGLETON_H_
 36#include "core/util/tSingleton.h"
 37#endif
 38
 39class SimSet;
 40class MatInstance;
 41class GuiTreeViewCtrl;
 42
 43class MaterialManager : public ManagedSingleton<MaterialManager>
 44{
 45public:
 46   MaterialManager();
 47   ~MaterialManager();
 48
 49   // ManagedSingleton
 50   static const char* getSingletonName() { return "MaterialManager"; }
 51
 52   Material * allocateAndRegister(const String &objectName, const String &mapToName = String());
 53   Material * getMaterialDefinitionByName(const String &matName);
 54   Material* getMaterialDefinitionByMapTo(const String& mapTo);
 55   SimSet * getMaterialSet();   
 56
 57   // map textures to materials
 58   void mapMaterial(const String & textureName, const String & materialName);
 59   String getMapEntry(const String & textureName) const;
 60
 61   // Return instance of named material caller is responsible for memory
 62   BaseMatInstance * createMatInstance( const String &matName );
 63
 64   // Create a BaseMatInstance with the default feature flags. 
 65   BaseMatInstance * createMatInstance( const String &matName, const GFXVertexFormat *vertexFormat );
 66   BaseMatInstance * createMatInstance( const String &matName, const FeatureSet &features, const GFXVertexFormat *vertexFormat );
 67
 68   /// The default feature set for materials.
 69   const FeatureSet& getDefaultFeatures() const { return mDefaultFeatures; }
 70
 71   /// The feature exclusion list for disabling features.
 72   const FeatureSet& getExclusionFeatures() const { return mExclusionFeatures; }
 73
 74   void recalcFeaturesFromPrefs();
 75
 76   /// Get the default texture anisotropy.
 77   U32 getDefaultAnisotropy() const { return mDefaultAnisotropy; }
 78
 79   /// Allocate and return an instance of special materials.  Caller is responsible for the memory.
 80   BaseMatInstance * createWarningMatInstance();
 81
 82   /// Gets the global warning material instance, callers should not free this copy
 83   BaseMatInstance * getWarningMatInstance();
 84
 85   /// Set the deferred enabled state.
 86   void setDeferredEnabled( bool enabled ) { mUsingDeferred = enabled; }
 87
 88   /// Get the deferred enabled state.
 89   bool getDeferredEnabled() const { return mUsingDeferred; }
 90
 91#ifndef TORQUE_SHIPPING
 92
 93   // Allocate and return an instance of mesh debugging materials.  Caller is responsible for the memory.
 94   BaseMatInstance * createMeshDebugMatInstance(const LinearColorF &meshColor);
 95
 96   // Gets the global material instance for a given color, callers should not free this copy
 97   BaseMatInstance * getMeshDebugMatInstance(const LinearColorF &meshColor);
 98
 99#endif
100
101   void dumpMaterialInstances( BaseMaterialDefinition *target = NULL ) const;
102
103   void getMaterialInstances(BaseMaterialDefinition* target, GuiTreeViewCtrl* tree);
104
105   void updateTime();
106   F32 getTotalTime() const { return mAccumTime; }
107   F32 getDeltaTime() const { return mDt; }
108   U32 getLastUpdateTime() const { return mLastTime; }
109
110   /// Signal used to notify systems that 
111   /// procedural shaders have been flushed.
112   typedef Signal<void()> FlushSignal;
113
114   /// Returns the signal used to notify systems that the 
115   /// procedural shaders have been flushed.
116   FlushSignal& getFlushSignal() { return mFlushSignal; }
117
118   /// Flushes all the procedural shaders and re-initializes all
119   /// the active materials instances immediately.
120   void flushAndReInitInstances();
121
122   // Flush the instance
123   void flushInstance( BaseMaterialDefinition *target );
124
125   /// Re-initializes the material instances for a specific target material.   
126   void reInitInstance( BaseMaterialDefinition *target );
127
128protected:
129
130   // MatInstance tracks it's instances here
131   friend class MatInstance;
132   void _track(MatInstance*);
133   void _untrack(MatInstance*);
134
135   /// @see LightManager::smActivateSignal
136   void _onLMActivate( const char *lm, bool activate );
137
138   bool _handleGFXEvent(GFXDevice::GFXDeviceEventType event);
139
140   SimSet* mMaterialSet;
141   Vector<BaseMatInstance*> mMatInstanceList;
142
143   /// The default material features.
144   FeatureSet mDefaultFeatures;
145
146   /// The feature exclusion set.
147   FeatureSet mExclusionFeatures;
148
149   /// Signal used to notify systems that 
150   /// procedural shaders have been flushed.
151   FlushSignal mFlushSignal;
152
153   /// If set we flush and reinitialize all materials at the
154   /// start of the next rendered frame.
155   bool mFlushAndReInit;
156
157   // material map
158   typedef Map<String, String> MaterialMap;
159   MaterialMap mMaterialMap;
160
161   bool mUsingDeferred;
162
163   // time tracking
164   F32 mDt;
165   F32 mAccumTime;
166   U32 mLastTime;
167
168   BaseMatInstance* mWarningInst;
169
170   /// The default max anisotropy used in texture filtering.
171   S32 mDefaultAnisotropy;
172
173   /// Called when $pref::Video::defaultAnisotropy is changed.
174   void _updateDefaultAnisotropy();
175
176   /// Called when one of the feature disabling $pref::s are changed.
177   void _onDisableMaterialFeature() { mFlushAndReInit = true; }
178
179#ifndef TORQUE_SHIPPING
180   typedef Map<U32, BaseMatInstance*>  DebugMaterialMap;
181   DebugMaterialMap  mMeshDebugMaterialInsts;
182#endif
183
184};
185
186/// Helper for accessing MaterialManager singleton.
187#define MATMGR MaterialManager::instance()
188
189#endif // _MATERIAL_MGR_H_
190