1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_SortingMaterialIdGenerator.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_GFX_SORTINGMATERIALIDGENERATOR_H_ 19 #define NW_GFX_SORTINGMATERIALIDGENERATOR_H_ 20 21 #include <nw/gfx/gfx_IMaterialIdGenerator.h> 22 23 namespace nw 24 { 25 namespace gfx 26 { 27 28 namespace internal 29 { 30 //--------------------------------------------------------------------------- 31 //! @brief マテリアルのソート用のキーと値です。 32 //--------------------------------------------------------------------------- 33 struct MaterialKeyValue 34 { 35 u32 uniqueId; 36 u32 key; 37 u32 subKey; 38 Material* material; 39 40 }; 41 } 42 43 //--------------------------------------------------------------------------- 44 //! @brief ソートを行った結果からマテリアルIDの生成を行うクラスです。 45 //! 46 //! @details マテリアルIDの生成は以下の優先度で行われます。 47 //! バイナリ比較 > シェーダー比較 > 参照テーブル比較 48 //--------------------------------------------------------------------------- 49 class SortingMaterialIdGenerator : public IMaterialIdGenerator 50 { 51 private: 52 NW_DISALLOW_COPY_AND_ASSIGN(SortingMaterialIdGenerator); 53 54 typedef ut::MoveArray<internal::MaterialKeyValue> MaterialKeyValueArray; 55 public: 56 NW_UT_RUNTIME_TYPEINFO; 57 58 //! @brief 設定内容です。 59 struct Description 60 { 61 bool isFixedSizeMemory; //!< 最初に固定サイズのメモリを確保するフラグです。 62 int maxMaterials; //!< マテリアルの最大数です。 63 64 //! @brief コンストラクタです。 DescriptionDescription65 Description() 66 : isFixedSizeMemory(true), 67 maxMaterials(128) 68 {} 69 }; 70 71 //---------------------------------------- 72 //! @name 生成 73 //@{ 74 75 76 //! @brief ResMaterialのバイナリリソースのポインタからマテリアルIDの生成を行うクラスを構築するためのクラスです。 77 //! 78 //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 79 class Builder 80 { 81 public: 82 //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 83 //! 84 //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 85 //! 86 //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 IsFixedSizeMemory(bool isFixedSizeMemory)87 Builder& IsFixedSizeMemory(bool isFixedSizeMemory) 88 { 89 m_Description.isFixedSizeMemory = isFixedSizeMemory; 90 return *this; 91 } 92 93 //! マテリアルの最大数を設定します。 MaxMaterials(int maxMaterials)94 Builder& MaxMaterials(int maxMaterials) 95 { 96 m_Description.maxMaterials = maxMaterials; 97 return *this; 98 } 99 100 //! @brief マテリアルIDの生成クラスを生成します。 101 //! 102 //! @param[in] allocator アロケータです。 103 //! 104 //! @return 生成したマテリアルIDの生成クラスを返します。 105 //! 106 IMaterialIdGenerator* Create(os::IAllocator* allocator); 107 108 private: 109 Description m_Description; 110 }; 111 112 //! @brief マテリアルを受け取ります。 113 //! ここではマテリアルを配列に追加します。 114 //! 115 //! @param[in] material マテリアルです。 116 //! 117 virtual void Accept(Material* material); 118 119 //! @brief マテリアルIDを生成します。 120 virtual void Generate(); 121 122 //@} 123 124 private: 125 126 //---------------------------------------- 127 //! @name コンストラクタ/デストラクタ 128 //@{ 129 130 //! コンストラクタです。 SortingMaterialIdGenerator(os::IAllocator * allocator,MaterialKeyValueArray materials,MaterialKeyValueArray materialsWorkSpace)131 SortingMaterialIdGenerator( 132 os::IAllocator* allocator, 133 MaterialKeyValueArray materials, 134 MaterialKeyValueArray materialsWorkSpace) 135 : IMaterialIdGenerator(allocator), 136 m_Materials(materials), 137 m_MaterialsWorkSpace(materialsWorkSpace) 138 {} 139 140 //@} 141 142 MaterialKeyValueArray m_Materials; 143 MaterialKeyValueArray m_MaterialsWorkSpace; 144 }; 145 146 } // namespace gfx 147 } // namespace nw 148 149 #endif // NW_GFX_SORTINGMATERIALIDGENERATOR_H_ 150