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