materialList.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _MATERIALLIST_H_
  23. #define _MATERIALLIST_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. #ifndef _GFXTEXTUREHANDLE_H_
  28. #include "gfx/gfxTextureHandle.h"
  29. #endif
  30. class Material;
  31. class BaseMatInstance;
  32. class Stream;
  33. class GFXVertexFormat;
  34. class FeatureSet;
  35. class MaterialList
  36. {
  37. public:
  38. MaterialList();
  39. MaterialList(U32 materialCount, const char **materialNames);
  40. virtual ~MaterialList();
  41. /// Note: this is not to be confused with MaterialList(const MaterialList&). Copying
  42. /// a material list in the middle of it's lifetime is not a good thing, so we force
  43. /// it to copy at construction time by restricting the copy syntax to
  44. /// ML* pML = new ML(&copy);
  45. explicit MaterialList(const MaterialList*);
  46. const Vector<String> &getMaterialNameList() const { return mMaterialNames; }
  47. const String &getMaterialName(U32 index) const { return mMaterialNames[index]; }
  48. GFXTextureObject *getDiffuseTexture(U32 index);
  49. void setTextureLookupPath(const String& path) { mLookupPath = path; }
  50. void setMaterialName(U32 index, const String& name);
  51. void set(U32 materialCount, const char **materialNames);
  52. U32 push_back(const String &filename, Material* = 0);
  53. virtual void free();
  54. void clearMatInstList();
  55. bool empty() const { return mMaterialNames.empty(); }
  56. U32 size() const { return (U32)mMaterialNames.size(); }
  57. bool read(Stream &stream);
  58. bool write(Stream &stream);
  59. bool readText(Stream &stream, U8 firstByte);
  60. bool readText(Stream &stream);
  61. bool writeText(Stream &stream);
  62. void mapMaterials();
  63. /// Initialize material instances in material list.
  64. void initMatInstances( const FeatureSet &features,
  65. const GFXVertexFormat *vertexFormat );
  66. /// Return the material instance or NULL if the
  67. /// index is out of bounds.
  68. inline BaseMatInstance* getMaterialInst( U32 index ) const
  69. {
  70. return index < mMatInstList.size() ? mMatInstList[index] : NULL;
  71. }
  72. void setMaterialInst( BaseMatInstance *matInst, U32 index );
  73. // Needs to be accessible if were going to freely edit instances
  74. Vector<BaseMatInstance*> mMatInstList;
  75. protected:
  76. String mLookupPath;
  77. Vector<String> mMaterialNames; //!< Material 'mapTo' targets
  78. virtual void mapMaterial( U32 index );
  79. private:
  80. enum Constants { BINARY_FILE_VERSION = 1 };
  81. };
  82. #endif // _MATERIALLIST_H_