1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_SimpleMaterialActivator.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: 25986 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_SIMPLEMATERIALACTIVATOR_H_
17 #define NW_GFX_SIMPLEMATERIALACTIVATOR_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 //!               バッファを用いる場合に MaterialActivator が選択されます。
39 //!               バッファを用いない場合は SimpleMaterialActivator が選択されます。
40 //---------------------------------------------------------------------------
41 class SimpleMaterialActivator : public IMaterialActivator
42 {
43 private:
44     NW_DISALLOW_COPY_AND_ASSIGN(SimpleMaterialActivator);
45 
46 public:
47     NW_UT_RUNTIME_TYPEINFO;
48 
49     //---------------------------------------------------------------------------
50     //! @brief        マテリアルアクティベータを生成します。
51     //!
52     //! @param[in]    allocator アロケータです。
53     //!
54     //! @return       生成したマテリアルアクティベータを返します。
55     //---------------------------------------------------------------------------
56     static IMaterialActivator* Create(os::IAllocator* allocator);
57 
58     //---------------------------------------------------------------------------
59     //! @brief        生成時に必要なメモリサイズを取得します。
60     //---------------------------------------------------------------------------
61     static size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT)
62     {
63         os::MemorySizeCalculator size(alignment);
64 
65         GetMemorySizeInternal(&size);
66 
67         return size.GetSizeWithPadding(alignment);
68     }
69 
70     //! @details :private
GetMemorySizeInternal(os::MemorySizeCalculator * pSize)71     static void GetMemorySizeInternal(os::MemorySizeCalculator* pSize)
72     {
73         os::MemorySizeCalculator& size = *pSize;
74 
75         size += sizeof(SimpleMaterialActivator);
76     }
77 
78     //---------------------------------------------------------------------------
79     //! @brief        マテリアルを有効化します。
80     //!
81     //! @param[in]    renderContext レンダーコンテキストです。
82     //! @param[in]    material 有効化するマテリアルです。
83     //---------------------------------------------------------------------------
84     virtual void Activate(RenderContext* renderContext, const Material* material);
85 
86 private:
87 
88     //---------------------------------------------------------------------------
89     //! @brief        指定したクラスが持つハッシュが同値であるかどうか調べます。
90     //!
91     //! @tparam       lhs    チェックを行うリソースです。
92     //! @tparam       rhs    チェックを行うリソースです。
93     //---------------------------------------------------------------------------
94     template<typename TRes, typename URes>
95     NW_INLINE bool
EqualHash(const TRes lhs,const URes rhs)96     EqualHash(const TRes lhs, const URes rhs)
97     {
98         return (lhs.GetHash() == rhs.GetHash());
99     }
100 
101     //! コンストラクタです。
102     SimpleMaterialActivator(os::IAllocator* allocator);
103 
104     //! デストラクタです。
105     virtual ~SimpleMaterialActivator();
106 };
107 
108 } // namespace gfx
109 } // namespace nw
110 
111 #endif // NW_GFX_SIMPLEMATERIALACTIVATOR_H_
112