Torque3D Documentation / _generateds / baseMatInstance.h

baseMatInstance.h

Engine/source/materials/baseMatInstance.h

More...

Classes:

Detailed Description

  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 _BASEMATINSTANCE_H_
 24#define _BASEMATINSTANCE_H_
 25
 26#ifndef _TSIGNAL_H_
 27#include "core/util/tSignal.h"
 28#endif
 29#ifndef _BASEMATERIALDEFINITION_H_
 30#include "materials/baseMaterialDefinition.h"
 31#endif
 32#ifndef _MATERIALPARAMETERS_H_
 33#include "materials/materialParameters.h"
 34#endif
 35#ifndef _MMATRIX_H_
 36#include "math/mMatrix.h"
 37#endif
 38#ifndef _GFXENUMS_H_
 39#include "gfx/gfxEnums.h"
 40#endif
 41#ifndef _GFXSHADER_H_
 42#include "gfx/gfxShader.h"
 43#endif
 44#ifndef _MATERIALFEATUREDATA_H_
 45#include "materials/materialFeatureData.h"
 46#endif
 47#ifndef _MATINSTANCEHOOK_H_
 48#include "materials/matInstanceHook.h"
 49#endif
 50#ifndef _MATSTATEHINT_H_
 51#include "materials/matStateHint.h"
 52#endif
 53#ifndef _GFXDEVICE_H_
 54#include "gfx/gfxDevice.h"
 55#endif
 56
 57#ifndef CUSTOMSHADERBINDINGDATA_H
 58#include "materials/customShaderBindingData.h"
 59#endif
 60
 61struct RenderPassData;
 62class GFXVertexBufferHandleBase;
 63class GFXPrimitiveBufferHandle;
 64struct SceneData;
 65class SceneRenderState;
 66struct GFXStateBlockDesc;
 67class GFXVertexFormat;
 68class MatrixSet;
 69class ProcessedMaterial;
 70class GuiTreeViewCtrl;
 71
 72///
 73class BaseMatInstance
 74{
 75protected:
 76
 77   /// The array of active material hooks indexed 
 78   /// by a MatInstanceHookType.
 79   Vector<MatInstanceHook*> mHooks;
 80
 81   ///
 82   MatFeaturesDelegate mFeaturesDelegate;
 83
 84   /// Should be true if init has been called and it succeeded.
 85   /// It is up to the derived class to set this variable appropriately.
 86   bool mIsValid;
 87
 88   /// This is set by initialization and used by the deferred.
 89   bool mHasNormalMaps;
 90
 91   /// This material makes use of bone transforms
 92   bool mUsesHardwareSkinning;
 93
 94public:
 95
 96   virtual ~BaseMatInstance();
 97
 98   /// @param features The features you want to allow for this material.  
 99   ///
100   /// @param vertexFormat The vertex format on which this material will be rendered.
101   ///
102   /// @see GFXVertexFormat
103   /// @see FeatureSet
104   virtual bool init(   const FeatureSet &features, 
105                        const GFXVertexFormat *vertexFormat ) = 0;
106
107   /// Reinitializes the material using the previous
108   /// initialization parameters.
109   /// @see init
110   virtual bool reInit() = 0;
111
112   /// Returns true if init has been successfully called.
113   /// It is up to the derived class to set this value properly.
114   bool isValid() { return mIsValid; }
115
116   /// Adds this stateblock to the base state block 
117   /// used during initialization.
118   /// @see init
119   virtual void addStateBlockDesc(const GFXStateBlockDesc& desc) = 0;
120
121   /// Updates the state blocks for this material.
122   virtual void updateStateBlocks() = 0;
123
124   /// Adds a shader macro which will be passed to the shader
125   /// during initialization.
126   /// @see init
127   virtual void addShaderMacro( const String &name, const String &value ) = 0;
128
129   /// Get a MaterialParameters block for this BaseMatInstance, 
130   /// caller is responsible for freeing it.
131   virtual MaterialParameters* allocMaterialParameters() = 0;
132
133   /// Set the current parameters for this BaseMatInstance
134   virtual void setMaterialParameters(MaterialParameters* param) = 0;
135
136   /// Get the current parameters for this BaseMatInstance (BaseMatInstances are created with a default active
137   /// MaterialParameters which is managed by BaseMatInstance.
138   virtual MaterialParameters* getMaterialParameters() = 0;
139
140   /// Returns a MaterialParameterHandle for name.
141   virtual MaterialParameterHandle* getMaterialParameterHandle(const String& name) = 0;
142
143   /// Sets up the next rendering pass for this material.  It is
144   /// typically called like so...
145   ///
146   ///@code
147   ///   while( mat->setupPass( state, sgData ) )
148   ///   {
149   ///      mat->setTransforms(...);
150   ///      mat->setSceneInfo(...);
151   ///      ...
152   ///      GFX->drawPrimitive();
153   ///   }
154   ///@endcode
155   ///
156   virtual bool setupPass( SceneRenderState *state, const SceneData &sgData ) = 0;
157   
158   /// This initializes the material transforms and should be 
159   /// called after setupPass() within the pass loop.
160   /// @see setupPass
161   virtual void setTransforms( const MatrixSet &matrixSet, SceneRenderState *state ) = 0;
162
163   /// Sets node transforms for the current stage. Used for hardware skinning.
164   virtual void setNodeTransforms( const MatrixF *address, const U32 numTransforms ) = 0;
165
166   /// Sets custom shader data
167   virtual void setCustomShaderData(Vector<CustomShaderBindingData> &shaderData) = 0;
168
169   /// This initializes various material scene state settings and
170   /// should be called after setupPass() within the pass loop.
171   /// @see setupPass
172   virtual void setSceneInfo( SceneRenderState *state, const SceneData &sgData ) = 0;
173
174   /// This is normally called from within setupPass() automatically, so its
175   /// unnecessary to do so manually unless a texture stage has changed.  If
176   /// so it should be called after setupPass() within the pass loop.
177   /// @see setupPass
178   virtual void setTextureStages(SceneRenderState *, const SceneData &sgData ) = 0;
179
180   /// Sets the vertex and primitive buffers as well as the instancing 
181   /// stream buffer for the current material if the material is instanced.
182   virtual void setBuffers( GFXVertexBufferHandleBase *vertBuffer, GFXPrimitiveBufferHandle *primBuffer ) = 0;
183
184   /// Returns true if this material is instanced.
185   virtual bool isInstanced() const = 0;
186
187   /// Used to increment the instance buffer for this material.
188   virtual bool stepInstance() = 0;
189
190   /// Returns true if the material is forward lit and requires
191   /// a list of lights which affect it when rendering.
192   virtual bool isForwardLit() const = 0;
193
194   /// Sets a SimObject which will passed into ShaderFeature::createConstHandles.
195   /// Normal features do not make use of this, it is for special class specific
196   /// or user designed features.
197   virtual void setUserObject( SimObject *userObject ) = 0;
198   virtual SimObject* getUserObject() const = 0;
199
200   /// Returns the material this instance is based on.
201   virtual BaseMaterialDefinition* getMaterial() = 0;
202
203   // BTRTODO: This stuff below should probably not be in BaseMatInstance
204   virtual bool hasGlow() = 0;
205   virtual bool hasAccumulation() = 0;
206   
207   virtual U32 getCurPass() = 0;
208
209   virtual U32 getCurStageNum() = 0;
210
211   virtual RenderPassData *getPass(U32 pass) = 0;
212
213   /// Returns the state hint which can be used for 
214   /// sorting and fast comparisions of the equality 
215   /// of a material instance.
216   virtual const MatStateHint& getStateHint() const = 0;
217
218   /// Returns the active features in use by this material.
219   /// @see getRequestedFeatures
220   virtual const FeatureSet& getFeatures() const = 0;
221
222   /// Returns the features that were requested at material
223   /// creation time which may differ from the active features.
224   /// @see getFeatures
225   virtual const FeatureSet& getRequestedFeatures() const = 0;
226
227   virtual const GFXVertexFormat* getVertexFormat() const = 0;
228
229   virtual void dumpShaderInfo() const = 0;
230   virtual void getShaderInfo(GuiTreeViewCtrl* tree, U32 item) const = 0;
231
232   /// Fast test for use of normal maps in this material.
233   bool hasNormalMap() const { return mHasNormalMaps; }
234
235   bool usesHardwareSkinning() const { return mUsesHardwareSkinning; }
236
237   ///
238   MatFeaturesDelegate& getFeaturesDelegate() { return mFeaturesDelegate; }
239
240   /// Returns true if this MatInstance is built from a CustomMaterial.
241   virtual bool isCustomMaterial() const = 0;
242
243   /// @name Material Hook functions
244   /// @{
245
246   ///
247   void addHook( MatInstanceHook *hook );
248
249   /// Helper function for getting a hook.
250   /// @see getHook
251   template <class HOOK>
252   inline HOOK* getHook() { return (HOOK*)getHook( HOOK::Type ); }
253
254   ///
255   MatInstanceHook* getHook( const MatInstanceHookType &type ) const;
256
257   ///
258   void deleteHook( const MatInstanceHookType &type );
259
260   ///
261   U32 deleteAllHooks();
262
263   /// @}
264
265   virtual const GFXStateBlockDesc &getUserStateBlock() const = 0;
266
267protected:
268   bool needsHighlighting;
269public:
270   bool needsSelectionHighlighting() { return needsHighlighting; };
271   void setSelectionHighlighting(bool flag) { needsHighlighting = flag; };
272};
273
274#endif /// _BASEMATINSTANCE_H_
275
276
277
278
279
280
281