materialList.h

Engine/source/materials/materialList.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
 24#ifndef _MATERIALLIST_H_
 25#define _MATERIALLIST_H_
 26
 27#ifndef _TVECTOR_H_
 28#include "core/util/tVector.h"
 29#endif
 30#ifndef _GFXTEXTUREHANDLE_H_
 31#include "gfx/gfxTextureHandle.h"
 32#endif
 33
 34
 35class Material;
 36class BaseMatInstance;
 37class Stream;
 38class GFXVertexFormat;
 39class FeatureSet;
 40
 41
 42class MaterialList
 43{
 44public:
 45   MaterialList();
 46   MaterialList(U32 materialCount, const char **materialNames);
 47   virtual ~MaterialList();
 48
 49   /// Note: this is not to be confused with MaterialList(const MaterialList&).  Copying
 50   ///  a material list in the middle of it's lifetime is not a good thing, so we force
 51   ///  it to copy at construction time by restricting the copy syntax to
 52   ///  ML* pML = new ML(&copy);
 53   explicit MaterialList(const MaterialList*);
 54
 55   const Vector<String> &getMaterialNameList() const { return mMaterialNames; }
 56   const String &getMaterialName(U32 index) const { return mMaterialNames[index]; }
 57   GFXTextureObject *getDiffuseTexture(U32 index);
 58
 59   void setTextureLookupPath(const String& path) { mLookupPath = path; }
 60   void setMaterialName(U32 index, const String& name);
 61
 62   void set(U32 materialCount, const char **materialNames);
 63   U32  push_back(const String &filename, Material* = 0);
 64
 65   virtual void free();
 66   void clearMatInstList();
 67
 68   bool empty() const { return mMaterialNames.empty();   }
 69   U32  size() const { return (U32)mMaterialNames.size(); }
 70
 71   bool read(Stream &stream);
 72   bool write(Stream &stream);
 73
 74   bool readText(Stream &stream, U8 firstByte);
 75   bool readText(Stream &stream);
 76   bool writeText(Stream &stream);
 77
 78   void mapMaterials();
 79
 80   /// Initialize material instances in material list.
 81   void initMatInstances(  const FeatureSet &features, 
 82                           const GFXVertexFormat *vertexFormat );
 83
 84   /// Return the material instance or NULL if the 
 85   /// index is out of bounds.
 86   inline BaseMatInstance* getMaterialInst( U32 index ) const
 87   {
 88      return index < mMatInstList.size() ? mMatInstList[index] : NULL;
 89   }
 90
 91   void setMaterialInst( BaseMatInstance *matInst, U32 index );
 92
 93   // Needs to be accessible if were going to freely edit instances
 94   Vector<BaseMatInstance*> mMatInstList;
 95
 96protected:
 97
 98   String               mLookupPath;
 99   Vector<String>       mMaterialNames;            //!< Material 'mapTo' targets
100
101   virtual void mapMaterial( U32 index );
102
103private:
104   enum Constants { BINARY_FILE_VERSION = 1 };
105};
106
107#endif // _MATERIALLIST_H_
108