Torque3D Documentation / _generateds / materialParameters.h

materialParameters.h

Engine/source/materials/materialParameters.h

More...

Classes:

class

Similar class to GFXShaderConsts, but this is to describe generic material parameters.

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 _MATERIALPARAMETERS_H_
 24#define _MATERIALPARAMETERS_H_
 25
 26#ifndef _GFXSHADER_H_
 27#include "gfx/gfxShader.h"
 28#endif
 29
 30///
 31/// Similar class to GFXShaderConsts, but this is to describe generic material parameters.  
 32/// 
 33class MaterialParameterHandle
 34{
 35public:
 36   virtual ~MaterialParameterHandle() {}
 37   virtual const String& getName() const = 0;
 38   // This is similar to GFXShaderConstHandle, but a Material will always return a handle when
 39   // asked for one.  Even if it doesn't have that material parameter.  This is because after a
 40   // reInitMaterials call, the constants can change underneath the MatInstance.
 41   // Note: GFXShaderConstHandle actually works this way too, now.
 42   virtual bool isValid() const = 0;
 43   /// Returns -1 if this handle does not point to a Sampler.
 44   virtual S32 getSamplerRegister( U32 pass ) const = 0;
 45};
 46
 47class MaterialParameters
 48{
 49public:
 50   MaterialParameters()
 51   {
 52      VECTOR_SET_ASSOCIATION( mShaderConstDesc );
 53   }
 54   virtual ~MaterialParameters() {}
 55
 56   /// Returns our list of shader constants, the material can get this and just set the constants it knows about
 57   virtual const Vector<GFXShaderConstDesc>& getShaderConstDesc() const { return mShaderConstDesc; }
 58
 59   /// An inline helper which ensures the handle is valid
 60   /// before the virtual set method is called.
 61   template< typename VALUE >
 62   inline void setSafe( MaterialParameterHandle *handle, const VALUE& v )
 63   {
 64      if ( handle->isValid() )
 65         set( handle, v );
 66   }
 67
 68   /// @name Set shader constant values
 69   /// @{
 70   /// Actually set shader constant values
 71   /// @param name Name of the constant, this should be a name contained in the array returned in getShaderConstDesc,
 72   /// if an invalid name is used, it is ignored.
 73   virtual void set(MaterialParameterHandle* handle, const F32 f) {}
 74   virtual void set(MaterialParameterHandle* handle, const Point2F& fv) {}
 75   virtual void set(MaterialParameterHandle* handle, const Point3F& fv) {}
 76   virtual void set(MaterialParameterHandle* handle, const Point4F& fv) {}
 77   virtual void set(MaterialParameterHandle* handle, const LinearColorF& fv) {}
 78   virtual void set(MaterialParameterHandle* handle, const S32 f) {}
 79   virtual void set(MaterialParameterHandle* handle, const Point2I& fv) {}
 80   virtual void set(MaterialParameterHandle* handle, const Point3I& fv) {}
 81   virtual void set(MaterialParameterHandle* handle, const Point4I& fv) {}
 82   virtual void set(MaterialParameterHandle* handle, const AlignedArray<F32>& fv) {}
 83   virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point2F>& fv) {}
 84   virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point3F>& fv) {}
 85   virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point4F>& fv) {}
 86   virtual void set(MaterialParameterHandle* handle, const AlignedArray<S32>& fv) {}
 87   virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point2I>& fv) {}
 88   virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point3I>& fv) {}
 89   virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point4I>& fv) {}
 90   virtual void set(MaterialParameterHandle* handle, const MatrixF& mat, const GFXShaderConstType matrixType = GFXSCT_Float4x4) {}
 91   virtual void set(MaterialParameterHandle* handle, const MatrixF* mat, const U32 arraySize, const GFXShaderConstType matrixType = GFXSCT_Float4x4) {}
 92
 93   /// Returns the alignment value for the constType in bytes.
 94   virtual U32 getAlignmentValue(const GFXShaderConstType constType) { return 0; }
 95
 96protected:   
 97   Vector<GFXShaderConstDesc> mShaderConstDesc;
 98};
 99
100#endif
101