1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_LightSet.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: 27868 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_GFX_LIGHTSET_H_ 17 #define NW_GFX_LIGHTSET_H_ 18 19 #include <nw/gfx/gfx_Common.h> 20 #include <nw/ut/ut_MoveArray.h> 21 #include <nw/gfx/res/gfx_ResSceneEnvironmentSetting.h> 22 #include <nw/gfx/gfx_SceneContext.h> 23 24 namespace nw 25 { 26 namespace gfx 27 { 28 29 class AmbientLight; 30 class VertexLight; 31 class FragmentLight; 32 class HemiSphereLight; 33 34 //! @brief フラグメントライトの配列です。 35 typedef ut::FixedSizeArray<FragmentLight*, LIGHT_COUNT> FixedFragmentLightArray; 36 37 //--------------------------------------------------------------------------- 38 //! @brief ライトセットを表すクラスです。 39 //--------------------------------------------------------------------------- 40 class LightSet : public GfxObject 41 { 42 private: 43 NW_DISALLOW_COPY_AND_ASSIGN(LightSet); 44 45 public: 46 NW_UT_RUNTIME_TYPEINFO; 47 48 enum 49 { 50 DEFAULT_MAX_VERTEX_LIGHTS = 4 51 }; 52 53 //! @brief 設定内容です。 54 struct Description 55 { 56 //! @brief コンストラクタです。 DescriptionDescription57 Description() 58 : isFixedSizeMemory(true), 59 maxVertexLights(DEFAULT_MAX_VERTEX_LIGHTS) 60 {} 61 62 bool isFixedSizeMemory; 63 s32 maxVertexLights; 64 }; 65 66 //---------------------------------------- 67 //! @name 作成 68 //@{ 69 70 //! ライトセットを動的に構築するためのクラスです。 71 //! 72 //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 73 class DynamicBuilder 74 { 75 public: 76 //! コンストラクタです。 DynamicBuilder()77 DynamicBuilder() {} 78 79 //! デストラクタです。 ~DynamicBuilder()80 ~DynamicBuilder() {} 81 82 //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 83 //! 84 //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 85 //! 86 //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 IsFixedSizeMemory(bool isFixedSizeMemory)87 DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory) 88 { 89 m_Description.isFixedSizeMemory = isFixedSizeMemory; 90 return *this; 91 } 92 93 //! 設定可能な頂点ライトの数を設定します。 MaxVertexLights(s32 maxVertexLights)94 DynamicBuilder& MaxVertexLights(s32 maxVertexLights) 95 { 96 m_Description.maxVertexLights = maxVertexLights; 97 return *this; 98 } 99 100 //! @brief ライトセット生成します。 101 //! 102 //! @param[in] allocator アロケータです。 103 //! 104 //! @return 生成した頂点ライトを返します。 105 //! 106 LightSet* Create(os::IAllocator* allocator); 107 108 private: 109 LightSet::Description m_Description; 110 }; 111 112 //! @brief ライトセットを生成します。 113 //! 114 //! @param[in] resource リソースです。 115 //! @param[in] allocator アロケータです。 116 //! 117 //! @return 生成された頂点ライトです。 118 //! 119 static LightSet* Create( 120 ResLightSet resource, 121 os::IAllocator* allocator); 122 123 //! @details :private GetMemorySizeInternal(os::MemorySizeCalculator * pSize,ResLightSet resource)124 static void GetMemorySizeInternal( 125 os::MemorySizeCalculator* pSize, 126 ResLightSet resource) 127 { 128 os::MemorySizeCalculator& size = *pSize; 129 130 // LightSet::Create 131 size += sizeof(LightSet); 132 133 // CreateEnvironmentArray 134 size += sizeof(VertexLight*) * resource.GetLightsCount(); 135 } 136 137 //@} 138 139 //---------------------------------------- 140 //! @name 取得/設定 141 //@{ 142 143 //! @brief アンビエントライトを設定します。 144 //! 145 //! @param[in] light 設定するアンビエントライトです。 146 //! SetAmbientLight(AmbientLight * light)147 void SetAmbientLight(AmbientLight* light) 148 { 149 this->m_AmbientLight = light; 150 } 151 152 //! @brief アンビエントライトを取得します。 153 //! 154 //! @return アンビエントライトを返します。 155 //! GetAmbientLight()156 AmbientLight* GetAmbientLight() 157 { 158 return this->m_AmbientLight; 159 } 160 161 //! @brief アンビエントライトを取得します。 162 //! 163 //! @return アンビエントライトを返します。 164 //! GetAmbientLight()165 const AmbientLight* GetAmbientLight() const 166 { 167 return this->m_AmbientLight; 168 } 169 170 //! @brief 半球ライトを設定します。 171 //! 172 //! @param[in] light 設定する半球ライトです。 173 //! SetHemiSphereLight(HemiSphereLight * light)174 void SetHemiSphereLight(HemiSphereLight* light) 175 { 176 this->m_HemiSphereLight = light; 177 } 178 179 //! @brief 半球ライトを取得します。 180 //! 181 //! @return 半球ライトを返します。 182 //! GetHemiSphereLight()183 HemiSphereLight* GetHemiSphereLight() 184 { 185 return this->m_HemiSphereLight; 186 } 187 188 //! @brief 半球ライトを取得します。 189 //! 190 //! @return 半球ライトを返します。 191 //! GetHemiSphereLight()192 const HemiSphereLight* GetHemiSphereLight() const 193 { 194 return this->m_HemiSphereLight; 195 } 196 197 //! @brief 頂点ライトを設定します。 198 //! 199 //! @param[in] light 設定する頂点ライトです。 200 //! SetVertexLight(VertexLight * light)201 void SetVertexLight(VertexLight* light) 202 { 203 this->m_VertexLights.push_back(light); 204 } 205 206 //! @brief 頂点ライトの先頭を指すイテレータを取得します。 207 //! 208 //! @return 頂点ライトの先頭を指すイテレータです。 209 //! GetVertexLightBegin()210 VertexLightArray::iterator GetVertexLightBegin() 211 { 212 return m_VertexLights.begin(); 213 } 214 215 //! @brief 頂点ライトの先頭を指すイテレータを取得します。 216 //! 217 //! @return 頂点ライトの先頭を指すイテレータです。 218 //! GetVertexLightBegin()219 VertexLightArray::const_iterator GetVertexLightBegin() const 220 { 221 return m_VertexLights.begin(); 222 } 223 224 //! @brief 頂点ライトの終端を指すイテレータを取得します。 225 //! 226 //! @return 頂点ライトの終端を指すイテレータです。 227 //! GetVertexLightEnd()228 VertexLightArray::iterator GetVertexLightEnd() 229 { 230 return m_VertexLights.end(); 231 } 232 233 //! @brief 頂点ライトの終端を指すイテレータを取得します。 234 //! 235 //! @return 頂点ライトの終端を指すイテレータです。 236 //! GetVertexLightEnd()237 VertexLightArray::const_iterator GetVertexLightEnd() const 238 { 239 return m_VertexLights.end(); 240 } 241 242 //! @brief 頂点ライトの数を取得します。 243 //! 244 //! @return 頂点ライトの数です。 245 //! GetVertexLightCount()246 s32 GetVertexLightCount() const 247 { 248 return m_VertexLights.size(); 249 } 250 251 //! @brief フラグメントライトを設定します。 252 //! 253 //! @param[in] light 設定するフラグメントライトです。 254 //! SetFragmentLight(FragmentLight * light)255 void SetFragmentLight(FragmentLight* light) 256 { 257 this->m_FragmentLights.push_back(light); 258 } 259 260 //! @brief フラグメントライトの先頭を指すイテレータを取得します。 261 //! 262 //! @return フラグメントライトの先頭を指すイテレータです。 263 //! GetFragmentLightBegin()264 FixedFragmentLightArray::iterator GetFragmentLightBegin() 265 { 266 return m_FragmentLights.begin(); 267 } 268 269 //! @brief フラグメントライトの先頭を指すイテレータを取得します。 270 //! 271 //! @return フラグメントライトの先頭を指すイテレータです。 272 //! GetFragmentLightBegin()273 FixedFragmentLightArray::const_iterator GetFragmentLightBegin() const 274 { 275 return m_FragmentLights.begin(); 276 } 277 278 //! @brief フラグメントライトの終端を指すイテレータを取得します。 279 //! 280 //! @return フラグメントライトの終端を指すイテレータです。 281 //! GetFragmentLightEnd()282 FixedFragmentLightArray::iterator GetFragmentLightEnd() 283 { 284 return m_FragmentLights.end(); 285 } 286 287 //! @brief フラグメントライトの終端を指すイテレータを取得します。 288 //! 289 //! @return フラグメントライトの終端を指すイテレータです。 290 //! GetFragmentLightEnd()291 FixedFragmentLightArray::const_iterator GetFragmentLightEnd() const 292 { 293 return m_FragmentLights.end(); 294 } 295 296 //! @brief フラグメントライトの数を取得します。 297 //! 298 //! @return フラグメントライトの数です。 299 //! GetFragmentLightCount()300 s32 GetFragmentLightCount() const 301 { 302 return m_FragmentLights.size(); 303 } 304 305 //! @brief ライトをクリアします。 ClearAll()306 void ClearAll() 307 { 308 this->m_AmbientLight = NULL; 309 this->m_HemiSphereLight = NULL; 310 this->m_VertexLights.clear(); 311 this->m_FragmentLights.clear(); 312 } 313 314 //@} 315 316 protected: 317 318 //---------------------------------------- 319 //! @name コンストラクタ/デストラクタ 320 //@{ 321 322 //! コンストラクタです。 LightSet(os::IAllocator * allocator,ResLightSet resObj,const LightSet::Description & description)323 LightSet( 324 os::IAllocator* allocator, 325 ResLightSet resObj, 326 const LightSet::Description& description) 327 : GfxObject(allocator), 328 m_Resource(resObj), 329 m_AmbientLight(NULL), 330 m_HemiSphereLight(NULL) 331 { 332 NW_UNUSED_VARIABLE(description); 333 } 334 335 //! デストラクタです。 ~LightSet()336 virtual ~LightSet() {} 337 338 //@} 339 340 private: 341 ResLightSet m_Resource; 342 343 AmbientLight* m_AmbientLight; 344 HemiSphereLight* m_HemiSphereLight; 345 VertexLightArray m_VertexLights; 346 FixedFragmentLightArray m_FragmentLights; 347 }; 348 349 } // namespace gfx 350 } // namespace nw 351 352 #endif // NW_GFX_LIGHTSET_H_ 353