1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_AmbientLight.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_AMBIENTLIGHT_H_ 19 #define NW_GFX_AMBIENTLIGHT_H_ 20 21 #include <nw/gfx/gfx_Light.h> 22 #include <nw/gfx/res/gfx_ResLight.h> 23 24 #include <nw/ut/ut_MovePtr.h> 25 #include <functional> 26 27 namespace nw 28 { 29 namespace gfx 30 { 31 32 //--------------------------------------------------------------------------- 33 //! @brief アンビエントライトを表すクラスです。 34 //--------------------------------------------------------------------------- 35 class AmbientLight : public Light 36 { 37 private: 38 NW_DISALLOW_COPY_AND_ASSIGN(AmbientLight); 39 40 public: 41 NW_UT_RUNTIME_TYPEINFO; 42 43 //! @brief 設定内容です。 44 struct Description : public Light::Description 45 { 46 //! @brief コンストラクタです。 DescriptionDescription47 Description(){} 48 }; 49 50 //---------------------------------------- 51 //! @name 作成/破棄 52 //@{ 53 54 //! @brief アンビエントライトを動的に構築するためのクラスです。 55 //! 56 //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 57 class DynamicBuilder 58 { 59 public: 60 //! コンストラクタです。 DynamicBuilder()61 DynamicBuilder() {} 62 //! デストラクタです。 ~DynamicBuilder()63 ~DynamicBuilder() {} 64 65 //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 66 //! 67 //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 68 //! 69 //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 IsFixedSizeMemory(bool isFixedSizeMemory)70 DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory) 71 { 72 m_Description.isFixedSizeMemory = isFixedSizeMemory; 73 return *this; 74 } 75 76 //! 子の最大数を設定します。 MaxChildren(int maxChildren)77 DynamicBuilder& MaxChildren(int maxChildren) 78 { 79 m_Description.maxChildren = maxChildren; 80 return *this; 81 } 82 83 //! 管理できるコールバックの最大数を設定します。 MaxCallbacks(int maxCallbacks)84 DynamicBuilder& MaxCallbacks(int maxCallbacks) 85 { 86 m_Description.maxCallbacks = maxCallbacks; 87 return *this; 88 } 89 90 //! @brief アンビエントライトを生成します。 91 //! 92 //! @param[in] allocator アロケータです。 93 //! 94 //! @return 生成したアンビエントライトを返します。 95 //! 96 AmbientLight* Create(os::IAllocator* allocator); 97 98 //! @brief 生成時に必要なメモリサイズを取得します。 99 //! 100 //! メモリサイズは Builder の設定によって変化します。 101 //! すべての設定が終わった後にこの関数を呼び出してください。 102 //! 103 //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 104 size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT) const; 105 106 private: 107 AmbientLight::Description m_Description; 108 }; 109 110 //! @brief アンビエントライトを生成します。 111 //! 112 //! @param[in] parent 親のノードです。 113 //! @param[in] resource リソースです。 114 //! @param[in] description 設定内容です。 115 //! @param[in] allocator アロケータです。 116 //! 117 //! @return 生成されたアンビエントライトです。 118 //! 119 static AmbientLight* Create( 120 SceneNode* parent, 121 ResSceneObject resource, 122 const AmbientLight::Description& description, 123 os::IAllocator* allocator); 124 125 //! @brief 生成時に必要なメモリサイズを取得します。 126 //! 127 //! @param[in] resource リソースです。 128 //! @param[in] description 設定内容です。 129 //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 130 static size_t GetMemorySize( 131 ResAmbientLight resource, 132 Description description, 133 size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT 134 ) 135 { 136 os::MemorySizeCalculator size(alignment); 137 138 GetMemorySizeInternal(&size, resource, description); 139 140 return size.GetSizeWithPadding(alignment); 141 } 142 143 //! @details :private 144 static void GetMemorySizeInternal( 145 os::MemorySizeCalculator* pSize, 146 ResAmbientLight resource, 147 Description description); 148 149 //@} 150 151 //---------------------------------------- 152 //! @name シーンツリー 153 //@{ 154 155 //! @brief ビジターを受け付けます。 156 //! 157 //! @param[in] visitor ビジターです。 158 //! 159 virtual void Accept(ISceneVisitor* visitor); 160 161 //@} 162 163 //---------------------------------------- 164 //! @name リソース 165 //@{ 166 167 //! アンビエントライトのリソースを取得します。 GetResAmbientLight()168 ResAmbientLight GetResAmbientLight() 169 { 170 return ResStaticCast<ResAmbientLight>(this->GetResSceneObject()); 171 } 172 173 //! アンビエントライトのリソースを取得します。 GetResAmbientLight()174 const ResAmbientLight GetResAmbientLight() const 175 { 176 return ResStaticCast<ResAmbientLight>(this->GetResSceneObject()); 177 } 178 179 //@} 180 181 protected: 182 struct ResAmbientLightDataDestroyer : public std::unary_function<ResAmbientLightData*, void> 183 { m_AllocatorResAmbientLightDataDestroyer184 ResAmbientLightDataDestroyer(os::IAllocator* allocator = 0) : m_Allocator(allocator) 185 {} operatorResAmbientLightDataDestroyer186 result_type operator()(argument_type data) 187 { 188 DestroyResAmbientLight(m_Allocator, data); 189 } 190 191 os::IAllocator* m_Allocator; 192 }; 193 194 //! 動的生成したライトリソースを破棄するための MovePtr の定義です。 195 typedef ut::MovePtr<ResAmbientLightData, ResAmbientLightDataDestroyer> ResPtr; 196 197 //---------------------------------------- 198 //! @name コンストラクタ/デストラクタ 199 //@{ 200 201 //! コンストラクタです。 AmbientLight(os::IAllocator * allocator,ResAmbientLight resObj,const AmbientLight::Description & description)202 AmbientLight( 203 os::IAllocator* allocator, 204 ResAmbientLight resObj, 205 const AmbientLight::Description& description) 206 : Light( 207 allocator, 208 resObj, 209 description) 210 {} 211 212 //! コンストラクタです。 AmbientLight(os::IAllocator * allocator,ResPtr resource,const AmbientLight::Description & description)213 AmbientLight( 214 os::IAllocator* allocator, 215 ResPtr resource, 216 const AmbientLight::Description& description) 217 : Light( 218 allocator, 219 ResAmbientLight(resource.Get()), 220 description), 221 m_Resource(resource) 222 {} 223 224 //! デストラクタです。 ~AmbientLight()225 virtual ~AmbientLight() 226 { 227 DestroyOriginalValue(); 228 } 229 230 //@} 231 232 private: 233 234 virtual Result Initialize(os::IAllocator* allocator); 235 236 //--------------------------------------------------------------------------- 237 //! @brief ResAmbientLightData のリソースを生成します。 238 //! 239 //! @param[in] allocator リソース用のメモリを確保するアロケータです。 240 //! @param[in] name リソースにつける名前へのポインタです。名前が必要ない場合には NULL を指定してください。 241 //! 242 //! @return ResAmbientLightData へのポインタです。 243 //--------------------------------------------------------------------------- 244 static ResAmbientLightData* CreateResAmbientLight(os::IAllocator* allocator, const char* name = NULL); 245 246 //--------------------------------------------------------------------------- 247 //! @brief ResAmbientLightData のリソースを破棄します。 248 //! 249 //! @param[in] resAmbientLight ResAmbientLightData へのポインタです。 250 //! @param[in] allocator リソース用のメモリを開放するアロケータです。 251 //--------------------------------------------------------------------------- 252 static void DestroyResAmbientLight(os::IAllocator* allocator, ResAmbientLightData* resAmbientLight); 253 254 //! :private GetLightType()255 virtual u32 GetLightType() const 256 { 257 return anim::ResLightAnimData::LIGHT_TYPE_AMBIENT; 258 } 259 260 //! :private GetLightKind()261 virtual u32 GetLightKind() const 262 { 263 // ambientでは光源の種類は考慮しない 264 return ResLight::KIND_UNUSED; 265 } 266 267 //! アニメーションを初期状態に戻すため、初期化時の状態を保存します。 268 Result CreateOriginalValue(os::IAllocator* allocator); 269 270 ResPtr m_Resource; 271 }; 272 273 } // namespace gfx 274 } // namespace nw 275 276 #endif // NW_GFX_AMBIENTLIGHT_H_ 277