1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_DirectMaterialActivator.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 28677 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_DIRECTMATERIALACTIVATOR_H_
17 #define NW_GFX_DIRECTMATERIALACTIVATOR_H_
18 
19 #include <nw/gfx/gfx_GfxObject.h>
20 #include <nw/gfx/gfx_IMaterialActivator.h>
21 
22 namespace nw
23 {
24 namespace os
25 {
26 class IAllocator;
27 } // namesapce os
28 
29 namespace gfx
30 {
31 
32 class RenderContext;
33 class Material;
34 
35 //---------------------------------------------------------------------------
36 //! @brief      指定されたオプションに応じてマテリアルを更新するためのクラスです。
37 //!
38 //! @details    各種フラグやハッシュを用いずに更新を行います。
39 //!             設定したフラグによって設定されるマテリアルの項目が変わります。
40 //---------------------------------------------------------------------------
41 class DirectMaterialActivator : public IMaterialActivator
42 {
43 private:
44     NW_DISALLOW_COPY_AND_ASSIGN(DirectMaterialActivator);
45 
46 public:
47     NW_UT_RUNTIME_TYPEINFO;
48 
49     //---------------------------------------------------------------------------
50     //! @brief        マテリアルアクティベータを生成します。
51     //!
52     //! @param[in]    allocator アロケータです。
53     //!
54     //! @return       生成したマテリアルアクティベータを返します。
55     //---------------------------------------------------------------------------
56     static DirectMaterialActivator* Create(os::IAllocator* allocator);
57 
58     //---------------------------------------------------------------------------
59     //! @brief        生成時に必要なメモリサイズを取得します。
60     //!
61     //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。
62     //---------------------------------------------------------------------------
63     static size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT)
64     {
65         os::MemorySizeCalculator size(alignment);
66 
67         GetMemorySizeInternal(&size);
68 
69         return size.GetSizeWithPadding(alignment);
70     }
71 
72 
73     //! @details :private
GetMemorySizeInternal(os::MemorySizeCalculator * pSize)74     static void GetMemorySizeInternal(
75         os::MemorySizeCalculator* pSize)
76     {
77         os::MemorySizeCalculator& size = *pSize;
78 
79         size += sizeof(DirectMaterialActivator);
80     }
81 
82     //---------------------------------------------------------------------------
83     //! @brief        マテリアルを有効化します。
84     //!
85     //! @param[in]    renderContext レンダーコンテキストです。
86     //! @param[in]    material 有効化するマテリアルです。
87     //---------------------------------------------------------------------------
88     virtual void Activate(RenderContext* renderContext, const Material* material);
89 
90     //---------------------------------------------------------------------------
91     //! @brief        有効化フラグを取得します。
92     //!               フラグは Model::BufferOption となります。
93     //!
94     //! @return       取得した有効化フラグです。
95     //---------------------------------------------------------------------------
GetActivateFlags()96     u32 GetActivateFlags() const
97     {
98         return this->m_ActivateFlags;
99     }
100 
101     //---------------------------------------------------------------------------
102     //! @brief        有効化フラグを設定します。
103     //!               フラグは Model::BufferOption となります。
104     //!
105     //! @param[in] flags 設定するフラグです。
106     //---------------------------------------------------------------------------
SetActivateFlags(u32 flags)107     void SetActivateFlags(u32 flags)
108     {
109         this->m_ActivateFlags = flags;
110     }
111 
112 private:
113     //! コンストラクタです。
114     DirectMaterialActivator(os::IAllocator* allocator);
115 
116     //! デストラクタです。
117     virtual ~DirectMaterialActivator();
118 
119     u32 m_ActivateFlags;
120 };
121 
122 } // namespace gfx
123 } // namespace nw
124 
125 #endif // NW_GFX_DIRECTMATERIALACTIVATOR_H_
126