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;
 41
 42class MaterialManager : public ManagedSingleton<MaterialManager>
 43{
 44public:
 45   MaterialManager();
 46   ~MaterialManager();
 47
 48   // ManagedSingleton
 49   static const char* getSingletonName() { return "MaterialManager"; }
 50
 51   Material * allocateAndRegister(const String &objectName, const String &mapToName = String());
 52   Material * getMaterialDefinitionByName(const String &matName);
 53   SimSet * getMaterialSet();   
 54
 55   // map textures to materials
 56   void mapMaterial(const String & textureName, const String & materialName);
 57   String getMapEntry(const String & textureName) const;
 58
 59   // Return instance of named material caller is responsible for memory
 60   BaseMatInstance * createMatInstance( const String &matName );
 61
 62   // Create a BaseMatInstance with the default feature flags. 
 63   BaseMatInstance * createMatInstance( const String &matName, const GFXVertexFormat *vertexFormat );
 64   BaseMatInstance * createMatInstance( const String &matName, const FeatureSet &features, const GFXVertexFormat *vertexFormat );
 65
 66   /// The default feature set for materials.
 67   const FeatureSet& getDefaultFeatures() const { return mDefaultFeatures; }
 68
 69   /// The feature exclusion list for disabling features.
 70   const FeatureSet& getExclusionFeatures() const { return mExclusionFeatures; }
 71
 72   void recalcFeaturesFromPrefs();
 73
 74   /// Get the default texture anisotropy.
 75   U32 getDefaultAnisotropy() const { return mDefaultAnisotropy; }
 76
 77   /// Allocate and return an instance of special materials.  Caller is responsible for the memory.
 78   BaseMatInstance * createWarningMatInstance();
 79
 80   /// Gets the global warning material instance, callers should not free this copy
 81   BaseMatInstance * getWarningMatInstance();
 82
 83   /// Set the prepass enabled state.
 84   void setPrePassEnabled( bool enabled ) { mUsingPrePass = enabled; }
 85
 86   /// Get the prepass enabled state.
 87   bool getPrePassEnabled() const { return mUsingPrePass; }
 88
 89#ifndef TORQUE_SHIPPING
 90
 91   // Allocate and return an instance of mesh debugging materials.  Caller is responsible for the memory.
 92   BaseMatInstance * createMeshDebugMatInstance(const ColorF &meshColor);
 93
 94   // Gets the global material instance for a given color, callers should not free this copy
 95   BaseMatInstance * getMeshDebugMatInstance(const ColorF &meshColor);
 96
 97#endif
 98
 99   void dumpMaterialInstances( BaseMaterialDefinition *target = NULL ) const;
100
101   void updateTime();
102   F32 getTotalTime() const { return mAccumTime; }
103   F32 getDeltaTime() const { return mDt; }
104   U32 getLastUpdateTime() const { return mLastTime; }
105
106   /// Signal used to notify systems that 
107   /// procedural shaders have been flushed.
108   typedef Signal<void()> FlushSignal;
109
110   /// Returns the signal used to notify systems that the 
111   /// procedural shaders have been flushed.
112   FlushSignal& getFlushSignal() { return mFlushSignal; }
113
114   /// Flushes all the procedural shaders and re-initializes all
115   /// the active materials instances immediately.
116   void flushAndReInitInstances();
117
118   // Flush the instance
119   void flushInstance( BaseMaterialDefinition *target );
120
121   /// Re-initializes the material instances for a specific target material.   
122   void reInitInstance( BaseMaterialDefinition *target );
123
124protected:
125
126   // MatInstance tracks it's instances here
127   friend class MatInstance;
128   void _track(MatInstance*);
129   void _untrack(MatInstance*);
130
131   /// @see LightManager::smActivateSignal
132   void _onLMActivate( const char *lm, bool activate );
133
134   bool _handleGFXEvent(GFXDevice::GFXDeviceEventType event);
135
136   SimSet* mMaterialSet;
137   Vector<BaseMatInstance*> mMatInstanceList;
138
139   /// The default material features.
140   FeatureSet mDefaultFeatures;
141
142   /// The feature exclusion set.
143   FeatureSet mExclusionFeatures;
144
145   /// Signal used to notify systems that 
146   /// procedural shaders have been flushed.
147   FlushSignal mFlushSignal;
148
149   /// If set we flush and reinitialize all materials at the
150   /// start of the next rendered frame.
151   bool mFlushAndReInit;
152
153   // material map
154   typedef Map<String, String> MaterialMap;
155   MaterialMap mMaterialMap;
156
157   bool mUsingPrePass;
158
159   // time tracking
160   F32 mDt;
161   F32 mAccumTime;
162   U32 mLastTime;
163
164   BaseMatInstance* mWarningInst;
165
166   /// The default max anisotropy used in texture filtering.
167   S32 mDefaultAnisotropy;
168
169   /// Called when $pref::Video::defaultAnisotropy is changed.
170   void _updateDefaultAnisotropy();
171
172   /// Called when one of the feature disabling $pref::s are changed.
173   void _onDisableMaterialFeature() { mFlushAndReInit = true; }
174
175#ifndef TORQUE_SHIPPING
176   typedef Map<U32, BaseMatInstance*>  DebugMaterialMap;
177   DebugMaterialMap  mMeshDebugMaterialInsts;
178#endif
179
180};
181
182/// Helper for accessing MaterialManager singleton.
183#define MATMGR MaterialManager::instance()
184
185#endif // _MATERIAL_MGR_H_
186