/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_LightSet.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision: 24950 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_LIGHTSET_H_ #define NW_GFX_LIGHTSET_H_ #include #include #include #include namespace nw { namespace gfx { class AmbientLight; class VertexLight; class FragmentLight; class HemiSphereLight; //! @brief フラグメントライトの配列です。 typedef ut::FixedSizeArray FixedFragmentLightArray; //--------------------------------------------------------------------------- //! @brief ライトセットを表すクラスです。 //--------------------------------------------------------------------------- class LightSet : public GfxObject { private: NW_DISALLOW_COPY_AND_ASSIGN(LightSet); public: NW_UT_RUNTIME_TYPEINFO; enum { DEFAULT_MAX_VERTEX_LIGHTS = 4 }; //! @brief 設定内容です。 struct Description { //! @brief コンストラクタです。 Description() : isFixedSizeMemory(true), maxVertexLights(DEFAULT_MAX_VERTEX_LIGHTS) {} bool isFixedSizeMemory; s32 maxVertexLights; }; //---------------------------------------- //! @name 作成 //@{ //! ライトセットを動的に構築するためのクラスです。 //! //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 class DynamicBuilder { public: //! コンストラクタです。 DynamicBuilder() {} //! デストラクタです。 ~DynamicBuilder() {} //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 //! //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 //! //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory) { m_Description.isFixedSizeMemory = isFixedSizeMemory; return *this; } //! 設定可能な頂点ライトの数を設定します。 DynamicBuilder& MaxVertexLights(s32 maxVertexLights) { m_Description.maxVertexLights = maxVertexLights; return *this; } //! @brief ライトセット生成します。 //! //! @param[in] allocator アロケータです。 //! //! @return 生成した頂点ライトを返します。 //! LightSet* Create(os::IAllocator* allocator); private: LightSet::Description m_Description; }; //! @brief ライトセットを生成します。 //! //! @param[in] resource リソースです。 //! @param[in] allocator アロケータです。 //! //! @return 生成された頂点ライトです。 //! static LightSet* Create( ResLightSet resource, os::IAllocator* allocator); //@} //---------------------------------------- //! @name 取得/設定 //@{ //! @brief アンビエントライトを設定します。 //! //! @param[in] light 設定するアンビエントライトです。 //! void SetAmbientLight(AmbientLight* light) { this->m_AmbientLight = light; } //! @brief アンビエントライトを取得します。 //! //! @return アンビエントライトを返します。 //! AmbientLight* GetAmbientLight() { return this->m_AmbientLight; } //! @brief アンビエントライトを取得します。 //! //! @return アンビエントライトを返します。 //! const AmbientLight* GetAmbientLight() const { return this->m_AmbientLight; } //! @brief 半球ライトを設定します。 //! //! @param[in] light 設定する半球ライトです。 //! void SetHemiSphereLight(HemiSphereLight* light) { this->m_HemiSphereLight = light; } //! @brief 半球ライトを取得します。 //! //! @return 半球ライトを返します。 //! HemiSphereLight* GetHemiSphereLight() { return this->m_HemiSphereLight; } //! @brief 半球ライトを取得します。 //! //! @return 半球ライトを返します。 //! const HemiSphereLight* GetHemiSphereLight() const { return this->m_HemiSphereLight; } //! @brief 頂点ライトを設定します。 //! //! @param[in] light 設定する頂点ライトです。 //! void SetVertexLight(VertexLight* light) { this->m_VertexLights.push_back(light); } //! @brief 頂点ライトの先頭を指すイテレータを取得します。 //! //! @return 頂点ライトの先頭を指すイテレータです。 //! VertexLightArray::iterator GetVertexLightBegin() { return m_VertexLights.begin(); } //! @brief 頂点ライトの先頭を指すイテレータを取得します。 //! //! @return 頂点ライトの先頭を指すイテレータです。 //! VertexLightArray::const_iterator GetVertexLightBegin() const { return m_VertexLights.begin(); } //! @brief 頂点ライトの終端を指すイテレータを取得します。 //! //! @return 頂点ライトの終端を指すイテレータです。 //! VertexLightArray::iterator GetVertexLightEnd() { return m_VertexLights.end(); } //! @brief 頂点ライトの終端を指すイテレータを取得します。 //! //! @return 頂点ライトの終端を指すイテレータです。 //! VertexLightArray::const_iterator GetVertexLightEnd() const { return m_VertexLights.end(); } //! @brief 頂点ライトの数を取得します。 //! //! @return 頂点ライトの数です。 //! s32 GetVertexLightCount() const { return m_VertexLights.size(); } //! @brief フラグメントライトを設定します。 //! //! @param[in] light 設定するフラグメントライトです。 //! void SetFragmentLight(FragmentLight* light) { this->m_FragmentLights.push_back(light); } //! @brief フラグメントライトの先頭を指すイテレータを取得します。 //! //! @return フラグメントライトの先頭を指すイテレータです。 //! FixedFragmentLightArray::iterator GetFragmentLightBegin() { return m_FragmentLights.begin(); } //! @brief フラグメントライトの先頭を指すイテレータを取得します。 //! //! @return フラグメントライトの先頭を指すイテレータです。 //! FixedFragmentLightArray::const_iterator GetFragmentLightBegin() const { return m_FragmentLights.begin(); } //! @brief フラグメントライトの終端を指すイテレータを取得します。 //! //! @return フラグメントライトの終端を指すイテレータです。 //! FixedFragmentLightArray::iterator GetFragmentLightEnd() { return m_FragmentLights.end(); } //! @brief フラグメントライトの終端を指すイテレータを取得します。 //! //! @return フラグメントライトの終端を指すイテレータです。 //! FixedFragmentLightArray::const_iterator GetFragmentLightEnd() const { return m_FragmentLights.end(); } //! @brief フラグメントライトの数を取得します。 //! //! @return フラグメントライトの数です。 //! s32 GetFragmentLightCount() const { return m_FragmentLights.size(); } //! @brief ライトをクリアします。 void ClearAll() { this->m_AmbientLight = NULL; this->m_HemiSphereLight = NULL; this->m_VertexLights.clear(); this->m_FragmentLights.clear(); } //@} protected: //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 LightSet( os::IAllocator* allocator, ResLightSet resObj, const LightSet::Description& description) : GfxObject(allocator), m_Resource(resObj), m_AmbientLight(NULL), m_HemiSphereLight(NULL) { if (description.isFixedSizeMemory && description.maxVertexLights != 0) { void* memory = allocator->Alloc(sizeof(VertexLight*) * description.maxVertexLights); m_VertexLights = VertexLightArray(memory, description.maxVertexLights, allocator); } else { m_VertexLights = VertexLightArray(allocator); } } //! デストラクタです。 virtual ~LightSet() {} //@} private: ResLightSet m_Resource; AmbientLight* m_AmbientLight; HemiSphereLight* m_HemiSphereLight; VertexLightArray m_VertexLights; FixedFragmentLightArray m_FragmentLights; }; } // namespace gfx } // namespace nw #endif // NW_GFX_LIGHTSET_H_