1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_DirectMaterialActivator.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_DIRECTMATERIALACTIVATOR_H_
19 #define NW_GFX_DIRECTMATERIALACTIVATOR_H_
20 
21 #include <nw/gfx/gfx_GfxObject.h>
22 #include <nw/gfx/gfx_IMaterialActivator.h>
23 
24 namespace nw
25 {
26 namespace os
27 {
28 class IAllocator;
29 } // namesapce os
30 
31 namespace gfx
32 {
33 
34 class RenderContext;
35 class Material;
36 
37 //---------------------------------------------------------------------------
38 //! @brief      指定されたオプションに応じてマテリアルを更新するためのクラスです。
39 //!
40 //! @details    各種フラグやハッシュを用いずに更新を行います。
41 //!             設定したフラグによって設定されるマテリアルの項目が変わります。
42 //---------------------------------------------------------------------------
43 class DirectMaterialActivator : public IMaterialActivator
44 {
45 private:
46     NW_DISALLOW_COPY_AND_ASSIGN(DirectMaterialActivator);
47 
48 public:
49     NW_UT_RUNTIME_TYPEINFO;
50 
51     //---------------------------------------------------------------------------
52     //! @brief        マテリアルアクティベータを生成します。
53     //!
54     //! @param[in]    allocator アロケータです。
55     //!
56     //! @return       生成したマテリアルアクティベータを返します。
57     //---------------------------------------------------------------------------
58     static DirectMaterialActivator* Create(os::IAllocator* allocator);
59 
60     //---------------------------------------------------------------------------
61     //! @brief        生成時に必要なメモリサイズを取得します。
62     //!
63     //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。
64     //---------------------------------------------------------------------------
65     static size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT)
66     {
67         os::MemorySizeCalculator size(alignment);
68 
69         GetMemorySizeInternal(&size);
70 
71         return size.GetSizeWithPadding(alignment);
72     }
73 
74 
75     //! @details :private
GetMemorySizeInternal(os::MemorySizeCalculator * pSize)76     static void GetMemorySizeInternal(
77         os::MemorySizeCalculator* pSize)
78     {
79         os::MemorySizeCalculator& size = *pSize;
80 
81         size += sizeof(DirectMaterialActivator);
82     }
83 
84     //---------------------------------------------------------------------------
85     //! @brief        マテリアルを有効化します。
86     //!
87     //! @param[in]    renderContext レンダーコンテキストです。
88     //! @param[in]    material 有効化するマテリアルです。
89     //---------------------------------------------------------------------------
90     virtual void Activate(RenderContext* renderContext, const Material* material);
91 
92     //---------------------------------------------------------------------------
93     //! @brief        有効化フラグを取得します。
94     //!               フラグは Model::BufferOption となります。
95     //!
96     //! @return       取得した有効化フラグです。
97     //---------------------------------------------------------------------------
GetActivateFlags()98     u32 GetActivateFlags() const
99     {
100         return this->m_ActivateFlags;
101     }
102 
103     //---------------------------------------------------------------------------
104     //! @brief        有効化フラグを設定します。
105     //!               フラグは Model::BufferOption となります。
106     //!
107     //! @param[in] flags 設定するフラグです。
108     //---------------------------------------------------------------------------
SetActivateFlags(u32 flags)109     void SetActivateFlags(u32 flags)
110     {
111         this->m_ActivateFlags = flags;
112     }
113 
114 private:
115     //! コンストラクタです。
116     DirectMaterialActivator(os::IAllocator* allocator);
117 
118     //! デストラクタです。
119     virtual ~DirectMaterialActivator();
120 
121     u32 m_ActivateFlags;
122 };
123 
124 } // namespace gfx
125 } // namespace nw
126 
127 #endif // NW_GFX_DIRECTMATERIALACTIVATOR_H_
128