/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_AmbientLight.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_AMBIENTLIGHT_H_ #define NW_GFX_AMBIENTLIGHT_H_ #include #include #include #include namespace nw { namespace gfx { //--------------------------------------------------------------------------- //! @brief アンビエントライトを表すクラスです。 //--------------------------------------------------------------------------- class AmbientLight : public Light { private: NW_DISALLOW_COPY_AND_ASSIGN(AmbientLight); public: NW_UT_RUNTIME_TYPEINFO; //! @brief 設定内容です。 struct Description : public Light::Description { //! @brief コンストラクタです。 Description(){} }; //---------------------------------------- //! @name 作成/破棄 //@{ //! @brief アンビエントライトを動的に構築するためのクラスです。 //! //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 class DynamicBuilder { public: //! コンストラクタです。 DynamicBuilder() {} //! デストラクタです。 ~DynamicBuilder() {} //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 //! //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 //! //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory) { m_Description.isFixedSizeMemory = isFixedSizeMemory; return *this; } //! 子の最大数を設定します。 DynamicBuilder& MaxChildren(int maxChildren) { m_Description.maxChildren = maxChildren; return *this; } //! 管理できるコールバックの最大数を設定します。 DynamicBuilder& MaxCallbacks(int maxCallbacks) { m_Description.maxCallbacks = maxCallbacks; return *this; } //! @brief アンビエントライトを生成します。 //! //! @param[in] allocator アロケータです。 //! //! @return 生成したアンビエントライトを返します。 //! AmbientLight* Create(os::IAllocator* allocator); //! @brief 生成時に必要なメモリサイズを取得します。 //! //! メモリサイズは Builder の設定によって変化します。 //! すべての設定が終わった後にこの関数を呼び出してください。 //! //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT) const; private: AmbientLight::Description m_Description; }; //! @brief アンビエントライトを生成します。 //! //! @param[in] parent 親のノードです。 //! @param[in] resource リソースです。 //! @param[in] description 設定内容です。 //! @param[in] allocator アロケータです。 //! //! @return 生成されたアンビエントライトです。 //! static AmbientLight* Create( SceneNode* parent, ResSceneObject resource, const AmbientLight::Description& description, os::IAllocator* allocator); //! @brief 生成時に必要なメモリサイズを取得します。 //! //! @param[in] resource リソースです。 //! @param[in] description 設定内容です。 //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 static size_t GetMemorySize( ResAmbientLight resource, Description description, size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT ) { os::MemorySizeCalculator size(alignment); GetMemorySizeInternal(&size, resource, description); return size.GetSizeWithPadding(alignment); } //! @details :private static void GetMemorySizeInternal( os::MemorySizeCalculator* pSize, ResAmbientLight resource, Description description); //@} //---------------------------------------- //! @name シーンツリー //@{ //! @brief ビジターを受け付けます。 //! //! @param[in] visitor ビジターです。 //! virtual void Accept(ISceneVisitor* visitor); //@} //---------------------------------------- //! @name リソース //@{ //! アンビエントライトのリソースを取得します。 ResAmbientLight GetResAmbientLight() { return ResStaticCast(this->GetResSceneObject()); } //! アンビエントライトのリソースを取得します。 const ResAmbientLight GetResAmbientLight() const { return ResStaticCast(this->GetResSceneObject()); } //@} protected: struct ResAmbientLightDataDestroyer : public std::unary_function { ResAmbientLightDataDestroyer(os::IAllocator* allocator = 0) : m_Allocator(allocator) {} result_type operator()(argument_type data) { DestroyResAmbientLight(m_Allocator, data); } os::IAllocator* m_Allocator; }; //! 動的生成したライトリソースを破棄するための MovePtr の定義です。 typedef ut::MovePtr ResPtr; //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 AmbientLight( os::IAllocator* allocator, ResAmbientLight resObj, const AmbientLight::Description& description) : Light( allocator, resObj, description) {} //! コンストラクタです。 AmbientLight( os::IAllocator* allocator, ResPtr resource, const AmbientLight::Description& description) : Light( allocator, ResAmbientLight(resource.Get()), description), m_Resource(resource) {} //! デストラクタです。 virtual ~AmbientLight() { DestroyOriginalValue(); } //@} private: virtual Result Initialize(os::IAllocator* allocator); //--------------------------------------------------------------------------- //! @brief ResAmbientLightData のリソースを生成します。 //! //! @param[in] allocator リソース用のメモリを確保するアロケータです。 //! @param[in] name リソースにつける名前へのポインタです。名前が必要ない場合には NULL を指定してください。 //! //! @return ResAmbientLightData へのポインタです。 //--------------------------------------------------------------------------- static ResAmbientLightData* CreateResAmbientLight(os::IAllocator* allocator, const char* name = NULL); //--------------------------------------------------------------------------- //! @brief ResAmbientLightData のリソースを破棄します。 //! //! @param[in] resAmbientLight ResAmbientLightData へのポインタです。 //! @param[in] allocator リソース用のメモリを開放するアロケータです。 //--------------------------------------------------------------------------- static void DestroyResAmbientLight(os::IAllocator* allocator, ResAmbientLightData* resAmbientLight); //! :private virtual u32 GetLightType() const { return anim::ResLightAnimData::LIGHT_TYPE_AMBIENT; } //! :private virtual u32 GetLightKind() const { // ambientでは光源の種類は考慮しない return ResLight::KIND_UNUSED; } //! アニメーションを初期状態に戻すため、初期化時の状態を保存します。 Result CreateOriginalValue(os::IAllocator* allocator); ResPtr m_Resource; }; } // namespace gfx } // namespace nw #endif // NW_GFX_AMBIENTLIGHT_H_