/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_SortingMaterialIdGenerator.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 24209 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_SORTINGMATERIALIDGENERATOR_H_ #define NW_GFX_SORTINGMATERIALIDGENERATOR_H_ #include namespace nw { namespace gfx { namespace internal { //--------------------------------------------------------------------------- //! @brief マテリアルのソート用のキーと値です。 //--------------------------------------------------------------------------- struct MaterialKeyValue { u32 uniqueId; u32 key; u32 subKey; Material* material; }; } //--------------------------------------------------------------------------- //! @brief ソートを行った結果からマテリアルIDの生成を行うクラスです。 //! //! @details マテリアルIDの生成は以下の優先度で行われます。 //! バイナリ比較 > シェーダー比較 > 参照テーブル比較 //--------------------------------------------------------------------------- class SortingMaterialIdGenerator : public IMaterialIdGenerator { private: NW_DISALLOW_COPY_AND_ASSIGN(SortingMaterialIdGenerator); typedef ut::MoveArray MaterialKeyValueArray; public: NW_UT_RUNTIME_TYPEINFO; //! @brief 設定内容です。 struct Description { bool isFixedSizeMemory; //!< 最初に固定サイズのメモリを確保するフラグです。 int maxMaterials; //!< マテリアルの最大数です。 //! @brief コンストラクタです。 Description() : isFixedSizeMemory(true), maxMaterials(128) {} }; //---------------------------------------- //! @name 生成 //@{ //! @brief ResMaterialのバイナリリソースのポインタからマテリアルIDの生成を行うクラスを構築するためのクラスです。 //! //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 class Builder { public: //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 //! //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 //! //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 Builder& IsFixedSizeMemory(bool isFixedSizeMemory) { m_Description.isFixedSizeMemory = isFixedSizeMemory; return *this; } //! マテリアルの最大数を設定します。 Builder& MaxMaterials(int maxMaterials) { m_Description.maxMaterials = maxMaterials; return *this; } //! @brief マテリアルIDの生成クラスを生成します。 //! //! @param[in] allocator アロケータです。 //! //! @return 生成したマテリアルIDの生成クラスを返します。 //! IMaterialIdGenerator* Create(os::IAllocator* allocator); private: Description m_Description; }; //! @brief マテリアルを受け取ります。 //! ここではマテリアルを配列に追加します。 //! //! @param[in] material マテリアルです。 //! virtual void Accept(Material* material); //! @brief マテリアルIDを生成します。 virtual void Generate(); //@} private: //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 SortingMaterialIdGenerator( os::IAllocator* allocator, MaterialKeyValueArray materials, MaterialKeyValueArray materialsWorkSpace) : IMaterialIdGenerator(allocator), m_Materials(materials), m_MaterialsWorkSpace(materialsWorkSpace) {} //@} MaterialKeyValueArray m_Materials; MaterialKeyValueArray m_MaterialsWorkSpace; }; } // namespace gfx } // namespace nw #endif // NW_GFX_SORTINGMATERIALIDGENERATOR_H_