1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: demo_GraphicsSystem.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_DEMO_GRAPHICSSYSTEM_H_
19 #define NW_DEMO_GRAPHICSSYSTEM_H_
20
21 #include <nw/demo/demo_DisplayBufferSwapper.h>
22 #include <nw/demo/demo_CameraController.h>
23 #include <nw/demo/demo_CommandListSwapper.h>
24
25 #include <nw/gfx/gfx_IRenderTarget.h>
26 #include <nw/gfx/gfx_RenderQueue.h>
27 #include <nw/gfx/gfx_SceneUpdater.h>
28
29 #include <nw/ut/ut_MoveArray.h>
30 #include <nw/ut/ut_ResUtil.h>
31 #include <nw/math.h>
32
33 #include <nn/gx.h>
34 #include <nn/ulcd/CTR/ulcd_StereoCamera.h>
35
36 namespace nw {
37 namespace gfx {
38
39 class RenderContext;
40 class MeshRenderer;
41 enum RenderColorFormat;
42 class Shader;
43
44 class SceneNode;
45 class SceneContext;
46 class SceneTraverser;
47 class SceneInitializer;
48 class Camera;
49 } // namespace gfx
50
51 namespace os {
52
53 class IAllocator;
54
55 } // namespace os
56
57 namespace ut {
58
59 struct FloatColor;
60
61 } // namespace ut
62
63 namespace demo {
64
65 class RenderSystem;
66 class SceneSystem;
67 class GraphicsDrawing;
68 class DemoAllocator;
69
70 //---------------------------------------------------------------------------
71 //! @brief 上画面の表示モードを表す定義です。
72 //! nngxExtensionMode で指定する引数となります。
73 //---------------------------------------------------------------------------
74 enum UpperScreenMode
75 {
76 UPPER_SCREEN_MODE_NORMAL = NN_GX_DISPLAYMODE_NORMAL, //!< 通常モードを表します。
77 UPPER_SCREEN_MODE_STEREO = NN_GX_DISPLAYMODE_STEREO //!< 3Dモードを表します。
78 };
79
80 //! @brief リソースのセットを表す構造体です。
81 struct ResourceSet
82 {
83 nw::ut::MoveArray<u8> buffer;
84 nw::gfx::ResGraphicsFile resource;
85 };
86
87 const int MAX_RESOURCES_COUNT = 128;
88 typedef nw::ut::FixedSizeArray<ResourceSet, MAX_RESOURCES_COUNT> ResourceArray;
89
90 //---------------------------------------------------------------------------
91 //! @brief 描画機能をまとめるためのクラスです。
92 //---------------------------------------------------------------------------
93 class RenderSystem
94 {
95 public:
96
97 //---------------------------------------------------------------------------
98 //! @brief 描画システムの設定内容です。
99 //---------------------------------------------------------------------------
100 struct Description
101 {
102 //! @brief 描画を行うスクリーンサイズを表します。
103 struct ScreenSize
104 {
105 s32 width; //!< スクリーンの横幅を表します。
106 s32 height; //!< スクリーンの縦幅を表します。
107 //! @brief コンストラクタです。
ScreenSizeDescription::ScreenSize108 ScreenSize(s32 w, s32 h) : width(w), height(h) {}
109 };
110
111 //! @brief スクリーンオフセットを表します。
112 struct ScreenOffset
113 {
114 s32 x; //!< オフセットのX座標を表します。
115 s32 y; //!< オフセットのY座標を表します。
116 //! @brief コンストラクタです。
ScreenOffsetDescription::ScreenOffset117 ScreenOffset(s32 x, s32 y) : x(x), y(y) {}
118 };
119 //! @brief 上画面のディスプレイバッファスワッパの設定内容です。
120 DisplayBufferSwapper::Description upperScreenDescription;
121
122 //! @brief 下画面のディスプレイバッファスワッパの設定内容です。
123 DisplayBufferSwapper::Description lowerScreenDescription;
124
125 gfx::RenderColorFormat renderColorFormat; //!< スクリーンのカラーフォーマットを表します。
126 size_t commandBufferSize; //!< コマンドバッファのサイズを現します。
127 size_t commandRequestCount; //!< コマンドリクエストの上限数を表します。
128 size_t reusableCommandBufferSize; //!< 再利用コマンドリストのコマンドバッファのサイズを現します。
129 size_t reusableCommandRequestCount; //!< 再利用コマンドリストのコマンドリクエストの上限数を表します。
130 UpperScreenMode upperScreenMode; //!< 上画面のモードです。
131
132 size_t commandListCount; //!< 生成するコマンドリストの数です。
133 size_t displayBufferCount; //!< 生成するディスプレイバッファの数です。
134
135 size_t maxGpuProfilingEntryCount; //!< コマンドリストの GPU プロファイラエントリの上限数を表します。
136
137 //! @brief コンストラクタです。
138 //! 立体視表示をしない場合のデフォルト値がセットされます。
DescriptionDescription139 Description()
140 : renderColorFormat(nw::gfx::RENDER_COLOR_FORMAT_RGBA8),
141 commandBufferSize(0x100000),
142 commandRequestCount(512),
143 reusableCommandBufferSize(0),
144 reusableCommandRequestCount(0),
145 upperScreenMode(UPPER_SCREEN_MODE_NORMAL),
146 commandListCount(2),
147 displayBufferCount(2),
148 maxGpuProfilingEntryCount(8)
149 {
150 upperScreenDescription.screenKind = nw::demo::UPPER_SCREEN;
151 upperScreenDescription.width = NN_GX_DISPLAY0_HEIGHT;
152 upperScreenDescription.height = NN_GX_DISPLAY0_WIDTH;
153
154 lowerScreenDescription.screenKind = nw::demo::LOWER_SCREEN;
155 lowerScreenDescription.width = NN_GX_DISPLAY1_HEIGHT;
156 lowerScreenDescription.height = NN_GX_DISPLAY1_WIDTH;
157 }
158 };
159
160 //---------------------------------------------------------------------------
161 //! @brief 負荷メーターの内容です。
162 //---------------------------------------------------------------------------
163 struct LoadMeterDescription
164 {
165 //! @brief コンストラクタです。
LoadMeterDescriptionLoadMeterDescription166 LoadMeterDescription()
167 : startTick(0),
168 loadTime(0.0f),
169 loadGpuTime(0.0f),
170 waitTime(0.0f),
171 transferTime(0.0f),
172 gpuOtherTime(0.0f),
173 cumulativeTime(0.0f),
174 cumulativeGpuTime(0.0f),
175 cumulativeWaitTime(0.0f),
176 drawCommandBufferSize(0),
177 callCount(0)
178 {}
179
180 s64 startTick; //!< 開始チックです。
181 float loadTime; //!< 負荷時間です。
182 float loadGpuTime; //!< GPU負荷時間です。
183 float waitTime; //!< コマンドリストの終了待ち時間です。
184 float transferTime; //!< レンダーターゲットからの転送時間です。
185 float gpuOtherTime; //!< 他のGPU処理の時間です。
186 float cumulativeTime; //!< 累積時間です。
187 float cumulativeGpuTime; //!< GPU累積時間です。
188 float cumulativeWaitTime; //!< 累積コマンドリスト終了待ち時間です。
189
190 int drawCommandBufferSize; //!< 描画コマンドのサイズです。
191
192 s32 callCount; //!< 呼び出し回数です。
193
194 static const float NANO_TO_MILLI;
195 static const float MILLI_TO_RATE;
196 };
197
198 //----------------------------------------
199 //! @name 生成/破棄
200 //@{
201
202
203 //! @brief 描画関連のクラスを生成します。
204 //!
205 //! @param[in] allocator アロケータです。
206 //! @param[in] description 生成するレンダーシステムの設定です。
207 //!
208 //! @return 生成したレンダーシステムを返します。
209 //!
210 static RenderSystem* Create(
211 os::IAllocator* allocator,
212 const Description& description
213 );
214
215 //! @brief 最遠景に配置するモデルの構築をします。
216 //!
217 //! 最遠景のモデルは半径1の球を指定します。
218 //!
219 void LoadSkyModel(const wchar_t* fileName);
220
221 //! @brief レンダーシステムを破棄します。
222 void Destroy();
223
224 //@}
225
226 //----------------------------------------
227 //! @name 取得/設定
228 //@{
229
230 //! @brief 描画を行うターゲットを設定します。
231 //!
232 //! @param[in] renderTarget 描画を行うターゲットです。
233 //!
234 void SetRenderTarget(gfx::IRenderTarget* renderTarget);
235
236 //! @brief レンダーコンテキストを取得します。
237 //!
238 //! @return レンダーコンテキストです。
239 //!
GetRenderContext()240 gfx::RenderContext* GetRenderContext() { return this->m_RenderContext; }
241
242 //! @brief シーン環境を取得します。
243 //!
244 //! @return シーン環境です。
245 //!
GetSceneEnvironment()246 gfx::SceneEnvironment& GetSceneEnvironment()
247 {
248 NW_NULL_ASSERT(this->m_RenderContext);
249 return this->m_RenderContext->GetSceneEnvironment();
250 }
251
252 //! @brief 描画ソートモードを設定します。
253 //!
254 //! @param[in] renderSortMode 描画ソートモードです。
255 //!
256 void SetRenderSortMode(gfx::ISceneUpdater::RenderSortMode renderSortMode);
257
258 //! @brief 描画ソートモードを取得します。
259 //!
260 //! @return 描画ソートモードです。
261 //!
GetRenderSortMode()262 gfx::ISceneUpdater::RenderSortMode GetRenderSortMode() const
263 {
264 return this->m_RenderSortMode;
265 }
266
267 //! @brief レンダーキューを取得します。
268 //!
269 //! @return レンダーキューです。
270 //!
GetRenderQueue()271 gfx::RenderQueue* GetRenderQueue() const
272 {
273 return this->m_RenderQueue;
274 }
275
276 //! @brief メッシュレンダラーを取得します。
277 //!
278 //! @return メッシュレンダラーです。
279 //!
GetMeshRenderer()280 gfx::MeshRenderer* GetMeshRenderer() const
281 {
282 return this->m_MeshRenderer;
283 }
284
285 //! @brief コマンドリストスワッパーを取得します。
GetCommandListSwapper()286 CommandListSwapper* GetCommandListSwapper() const
287 {
288 return this->m_CommandListSwapper;
289 }
290
291 //! @brief レンダーキューに描画コマンド要素を積みます。
292 //!
293 //! @param[in] renderCommand コマンドです。
294 //! @param[in] translucencyKind 透明性の種類です。
295 //! @param[in] priority メッシュの描画優先度です。
296 //! @param[in] layerId 描画要素のソート時に最優先に区分される ID です。レイヤーやビューポートの描画を制御するのに用います。
297 //!
EnqueueRenderCommand(gfx::RenderCommand * renderCommand,gfx::ResMaterial::TranslucencyKind translucencyKind,u8 priority,u8 layerId)298 void EnqueueRenderCommand(
299 gfx::RenderCommand* renderCommand,
300 gfx::ResMaterial::TranslucencyKind translucencyKind,
301 u8 priority,
302 u8 layerId)
303 {
304 this->m_RenderQueue->EnqueueCommand(
305 renderCommand,
306 translucencyKind,
307 priority,
308 layerId);
309 }
310
311 //@}
312
313 //----------------------------------------
314 //! @name 描画
315 //@{
316
317 //! @brief シーン環境をレンダーコンテキストに設定します。
318 //!
319 //! @param[in] sceneSystem 描画するシーンコンテンツを含むシーンシステムです。
320 //! @param[in] sceneEnvironmentSettings 設定するシーン環境です。
321 //!
322 void SetSceneEnvironmentSettings(
323 SceneSystem* sceneSystem,
324 ut::MoveArray<gfx::SceneEnvironmentSetting*>* sceneEnvironmentSettings);
325
326 //! @brief シーンコンテキストの環境をレンダーコンテキストに設定します。
327 //! SceneEnvironmentSetting を用いずにライトやフォグを設定するために呼び出します。
328 //!
329 //! @param[in] sceneSystem 描画するシーンコンテンツを含むシーンシステムです。
330 //!
331 void SetEnvironment(
332 SceneSystem* sceneSystem);
333
334 //! @brief レンダーキューにレンダーエレメントを追加します。
335 //!
336 //! @param[in] sceneSystem 描画するシーンコンテンツを含むシーンシステムです。
337 //!
338 void SubmitView(
339 SceneSystem* sceneSystem);
340
341 //! @brief シーンを描画します。
342 //!
343 //! @param[in] camera このシーンを描画するカメラです。
344 //! @param[in] screenKind 転送するスクリーンの種類です。
345 //! @param[in] isCommandCacheDump コマンドキャッシュをログ出力します。
346 //!
347 void RenderScene(
348 gfx::Camera* camera,
349 s32 screenKind,
350 bool isCommandCacheDump = false);
351
352 //! @brief ステレオディスプレイに対応したシーンの描画を行います。
353 //!
354 //! UPPER_SCREEN のみ対応しています。
355 //!
356 //! @param[in] leftCamera 左目用のカメラです。
357 //! @param[in] rightCamera 右目用のカメラです。
358 //! @param[in] isCommandCacheDump コマンドキャッシュをログ出力します。
359 //!
360 void RenderStereoScene(
361 gfx::Camera* leftCamera,
362 gfx::Camera* rightCamera,
363 bool isCommandCacheDump = false);
364
365 //! @brief バッファを消去します。
366 //!
367 //! @param[in] clearColor 設定するクリアカラーです。
368 //!
369 void ClearBuffer(ut::FloatColor clearColor);
370
371 //! @brief カメラのパラメータによって最遠景モデルの Translate と Scale の調整を行い描画します。
372 //!
373 //! @param[in] camera モデルの中心となるカメラです。
374 //!
375 void ClearBySkyModel(const gfx::Camera* camera);
376
377 //! @brief バッファを転送します。
378 //!
379 //! @param[in] screenKind 転送するスクリーンの種類です。
380 //!
381 void TransferBuffer(s32 screenKind);
382
383 //! @brief 実行しているコマンドリストの終了待ちを行います。
384 void WaitCommandList();
385
386 //! @brief バインドされているコマンドリストを実行します。
387 void RunCommandList();
388
389 //! @brief コマンドリストをバッファとスワップします。
390 void SwapCommandList();
391
392 //! @brief VSync 待ちを行います。
393 //!
394 //! @param[in] screenKind VSync待ちを行うスクリーンの種類です。
395 //!
396 void WaitVSync(s32 screenKind);
397
398 //! @brief バッファのスワップを予約します。
399 //!
400 //! @param[in] screenKind スワップを行うスクリーンの種類です。
401 //!
402 void SwapBuffer(s32 screenKind);
403
404 //! @brief VSync 待ちとディスプレイバッファの表示、コマンドリストの実行を行います。
405 //!
406 //! コマンドリストが多重化されている場合は、この関数は次の順序で処理を行います。 @n
407 //! 1. 実行中のコマンドリストの終了待ち @n
408 //! 2. ディスプレイバッファのスワップ予約 @n
409 //! 3. VSync 待ち @n
410 //! 4. 蓄積済みのコマンドリスト非同期実行 @n
411 //! 5. コマンドリストのスワップ
412 //!
413 //! コマンドリストが多重化されていない場合は次の処理を行います。 @n
414 //! 1. 蓄積済みのコマンドリスト同期実行 @n
415 //! 2. ディスプレイバッファのスワップ予約 @n
416 //! 3. VSync 待ち
417 //!
418 //! @param[in] screenKind VSync 待ちとスワップを行うスクリーンの種類です。
419 void PresentBuffer(s32 screenKind);
420
421 //! @brief ステレオカメラを計算します。
422 //!
423 //! @param[out] leftCamera 左目用のカメラです。
424 //! @param[out] rightCamera 右目用のカメラです。
425 //! @param[in] baseCamera ベースとなるカメラです。
426 //! @param[in] depthLevel ベースカメラから基準面までの距離です。
427 //! @param[in] depthRange 視差の補正値です。
428 //!
429 void CalcStereoCamera(
430 gfx::Camera* leftCamera,
431 gfx::Camera* rightCamera,
432 gfx::Camera* baseCamera,
433 f32 depthLevel = 1.0f,
434 f32 depthRange = 1.0f);
435
436 //@}
437
438 //----------------------------------------
439 //! @name 負荷メーター
440 //@{
441
442 //! @brief 負荷計測を開始します。
443 void BeginLoadMeter();
444
445 //! @brief 負荷計測を終了します。
446 void EndLoadMeter();
447
448 //! @brief 負荷計測結果を計算します。
449 void CalcLoadMeter();
450
451 //! @brief 負荷計測を一時停止します。
452 void SuspendLoadMeter();
453
454 //! @brief 負荷計測を再開します。
455 void ResumeLoadMeter();
456
457 //! @brief 積算負荷をリセットします。
458 void ResetCumulativeLoadMeter();
459
460 //! @brief 負荷メーターの内容を取得します。
GetLoadMeter()461 const LoadMeterDescription& GetLoadMeter() { return m_LoadMeterDescription; }
462
463 //! @brief 積算負荷を取得します。
GetCumulativeLoadMeter()464 const LoadMeterDescription& GetCumulativeLoadMeter() { return m_CumulativeLoadMeterDescription; }
465
466 //! @brief ロードメーターで表示する描画コマンドのサイズを追加します。
AddLoadMeterCommandSize(s32 commandSize)467 void AddLoadMeterCommandSize(s32 commandSize) { m_LoadMeterDescription.drawCommandBufferSize += commandSize; }
468
469 //! @brief 描画と転送の間に呼び出されるシグナルを取得します。
470 //! 立体視を行う場合は 左目の描画後に呼び出されます。
471 //!
472 //! @return シグナルを取得します。
473 //!
GetPostRenderCallback()474 ut::Signal1<void, const gfx::Camera*>* GetPostRenderCallback() const
475 {
476 return this->m_PostRenderCallback;
477 }
478
479 //! @brief 右目の描画と転送の間に呼び出されるシグナルを取得します。
480 //!
481 //! @return シグナルを取得します。
482 //!
GetPostRightRenderCallback()483 ut::Signal1<void, const gfx::Camera*>* GetPostRightRenderCallback() const
484 {
485 return this->m_PostRightRenderCallback;
486 }
487 //@}
488
489 private:
490 //! @brief コンストラクタです。
RenderSystem()491 RenderSystem()
492 : m_Allocator(NULL),
493 m_RenderContext(NULL),
494 m_PriorMaterialRenderKeyFactory(NULL),
495 m_RenderQueue(NULL),
496 m_MeshRenderer(NULL),
497 m_RenderSortMode(gfx::ISceneUpdater::ALL_MESH_BASE_SORT),
498 m_UpperSwapper(NULL),
499 m_LowerSwapper(NULL),
500 m_ExtensionSwapper(NULL),
501 m_CommandListSwapper(NULL),
502 m_StereoCamera(NULL),
503 m_SkyModel(NULL),
504 m_PostRenderCallback(NULL),
505 m_PostRightRenderCallback(NULL)
506 {
507 }
508
509 os::IAllocator* m_Allocator;
510 gfx::RenderContext* m_RenderContext;
511 gfx::RenderKeyFactory* m_PriorMaterialRenderKeyFactory;
512 gfx::RenderKeyFactory* m_PriorDepthRenderKeyFactory;
513 gfx::RenderQueue* m_RenderQueue;
514 gfx::MeshRenderer* m_MeshRenderer;
515 gfx::ISceneUpdater::RenderSortMode m_RenderSortMode;
516
517 DisplayBufferSwapper* m_UpperSwapper;
518 DisplayBufferSwapper* m_LowerSwapper;
519 DisplayBufferSwapper* m_ExtensionSwapper;
520
521 CommandListSwapper* m_CommandListSwapper;
522
523 LoadMeterDescription m_LoadMeterDescription;
524 LoadMeterDescription m_CumulativeLoadMeterDescription;
525
526 nn::ulcd::CTR::StereoCamera* m_StereoCamera;
527 ResourceArray m_Resources;
528 gfx::Model* m_SkyModel;
529
530 ut::Signal1<void, const gfx::Camera*>* m_PostRenderCallback;
531 ut::Signal1<void, const gfx::Camera*>* m_PostRightRenderCallback;
532 };
533
534
535 //---------------------------------------------------------------------------
536 //! @brief シーン更新機能をまとめるためのクラスです。
537 //---------------------------------------------------------------------------
538 class SceneSystem
539 {
540 public:
541 //---------------------------------------------------------------------------
542 //! @brief シーンシステムの設定内容です。
543 //---------------------------------------------------------------------------
544 struct Description
545 {
546 s32 maxSceneNodes; //!< シーンノードの上限数を表します。
547 s32 maxModels; //!< モデルの上限数を表します。
548 s32 maxSkeletalModels; //!< スケルタルモデルの上限数を表します。
549 s32 maxCameras; //!< カメラの上限数を表します。
550 s32 maxLights; //!< ライトの上限数を表します。
551 s32 maxFragmentLights; //!< フラグメントライトの上限数を表します。
552 s32 maxVertexLights; //!< 頂点ライトの上限数を表します。
553 s32 maxHemiSphereLights; //!< 半球ライトの上限数を表します。
554 s32 maxAmbientLights; //!< アンビエントライトの上限数を表します。
555 s32 maxFogs; //!< フォグの上限数を表します。
556 s32 maxParticleSets; //!< パーティクルセットの上限数を表します。
557 s32 maxParticleEmitters; //!< パーティクルエミッタの上限数を表します。
558 s32 maxParticleModels; //!< パーティクルモデルの上限数を表します。
559 s32 maxBones; //!< スケルトンに含まれるボーンの上限数を表します。
560 s32 maxMaterials; //!< マテリアルの最大数です。
561 s32 maxUserRenderNodes; //!< ユーザ定義の描画ノードの最大数です。
562 bool isFixedSizeMemory; //!< 生成時以外にもメモリを確保するかどうかのフラグを設定します。
563
564 //! @brief コンストラクタです。
DescriptionDescription565 Description()
566 : maxSceneNodes(gfx::SceneContext::DEFAULT_MAX_SCENE_NODES),
567 maxModels(gfx::SceneContext::DEFAULT_MAX_MODELS),
568 maxSkeletalModels(gfx::SceneContext::DEFAULT_MAX_SKELETAL_MODELS),
569 maxCameras(gfx::SceneContext::DEFAULT_MAX_CAMERAS),
570 maxLights(gfx::SceneContext::DEFAULT_MAX_LIGHTS),
571 maxFragmentLights(gfx::SceneContext::DEFAULT_MAX_FRAGMENT_LIGHTS),
572 maxVertexLights(gfx::SceneContext::DEFAULT_MAX_VERTEX_LIGHTS),
573 maxHemiSphereLights(gfx::SceneContext::DEFAULT_MAX_HEMISPHERE_LIGHTS),
574 maxAmbientLights(gfx::SceneContext::DEFAULT_MAX_AMBIENT_LIGHTS),
575 maxFogs(gfx::SceneContext::DEFAULT_MAX_FOGS),
576 maxParticleSets(gfx::SceneContext::DEFAULT_MAX_PARTICLESETS),
577 maxParticleEmitters(gfx::SceneContext::DEFAULT_MAX_PARTICLEEMITTERS),
578 maxParticleModels(gfx::SceneContext::DEFAULT_MAX_PARTICLEMODELS),
579 maxBones(128),
580 maxMaterials(32),
581 maxUserRenderNodes(gfx::SceneContext::DEFAULT_MAX_USER_RENDER_NODES),
582 isFixedSizeMemory(true)
583 {}
584 };
585
586 //----------------------------------------
587 //! @name 生成/破棄
588 //@{
589
590 //---------------------------------------------------------------------------
591 //! @brief シーン更新関連のクラスを生成します。
592 //!
593 //! @param[in] allocator アロケータです。
594 //! @param[in] description 生成するシーンシステムの設定です。
595 //!
596 //! @return 生成したシーンシステムです。
597 //---------------------------------------------------------------------------
598 static SceneSystem* Create(
599 os::IAllocator* allocator,
600 const Description& description
601 );
602
603 //---------------------------------------------------------------------------
604 //! @brief シーンシステムを破棄します。
605 //---------------------------------------------------------------------------
606 void Destroy();
607 //@}
608
609 //---------------------------------------------------------------------------
610 //! @brief シーンを初期化します。
611 //!
612 //! @param[in] sceneRoot 初期化するシーンのルートノードです。
613 //---------------------------------------------------------------------------
614 void InitializeScene(gfx::SceneNode* sceneRoot);
615
616 //---------------------------------------------------------------------------
617 //! @brief ルートノードのトラバースを行います。
618 //!
619 //! @param[in] sceneRoot 対象のルートノードです。
620 //---------------------------------------------------------------------------
621 void TraverseScene(gfx::SceneNode* sceneRoot);
622
623 //---------------------------------------------------------------------------
624 //! @brief シーンを更新します。
625 //---------------------------------------------------------------------------
626 void UpdateScene();
627
628 //! シーンコンテキストを取得します。
GetSceneContext()629 gfx::SceneContext* GetSceneContext() { return m_SceneContext; }
630
631 //! シーンアップデータを取得します。
GetSceneUpdater()632 gfx::ISceneUpdater* GetSceneUpdater() { return m_SceneUpdater; }
633
634 //! カメラ制御クラスを取得します。
GetCameraController()635 nw::demo::CameraController* GetCameraController() { return m_CameraController; }
636
637 private:
SceneSystem()638 SceneSystem()
639 : m_Allocator(NULL),
640 m_SceneContext(NULL),
641 m_SceneTraverser(NULL),
642 m_SceneUpdater(NULL),
643 m_SceneInitializer(NULL),
644 m_CameraController(NULL)
645 {}
646
647 os::IAllocator* m_Allocator;
648 gfx::SceneContext* m_SceneContext;
649 gfx::SceneTraverser* m_SceneTraverser;
650 gfx::SceneUpdater* m_SceneUpdater;
651 gfx::SceneInitializer* m_SceneInitializer;
652 CameraController* m_CameraController;
653 };
654
655 //---------------------------------------------------------------------------
656 //! @brief グラフィックスシステムに必要な各種初期化を行います。
657 //!
658 //! @param[in] deviceAllocator デバイスメモリ用のアロケータです。
659 //---------------------------------------------------------------------------
660 void InitializeGraphicsSystem(nw::demo::DemoAllocator* deviceAllocator);
661
662 //---------------------------------------------------------------------------
663 //! @brief グラフィックスシステムの終了処理を行います。
664 //---------------------------------------------------------------------------
665 void FinalizeGraphicsSystem();
666
667 //---------------------------------------------------------------------------
668 //! @brief リソースの後始末をします。
669 //---------------------------------------------------------------------------
670 template <typename TArray>
671 NW_INLINE void
SafeCleanupResources(TArray & resources)672 SafeCleanupResources(TArray& resources)
673 {
674 typename TArray::iterator end = resources.end();
675 for (typename TArray::iterator it = resources.begin();
676 it != end;
677 ++it)
678 {
679 nw::ut::SafeCleanup(it->resource);
680 }
681 }
682
683
684 //---------------------------------------------------------------------------
685 //! @brief GL や VRAM 用のアロケート関数です。
686 //!
687 //! @param[in] area 対象エリア情報です。
688 //! @param[in] aim メモリを要求している対象です。
689 //! @param[in] id メモリ要求対象の GL オブジェクトIDです。
690 //! @param[in] size メモリサイズです。
691 //---------------------------------------------------------------------------
692 void* AllocateGraphicsMemory(GLenum area, GLenum aim, GLuint id, GLsizei size);
693
694
695 //---------------------------------------------------------------------------
696 //! @brief GL や VRAM 用のでアロケート関数です。
697 //!
698 //! @param[in] area 対象エリア情報です。
699 //! @param[in] aim メモリを要求している対象です。
700 //! @param[in] id メモリ要求対象の GL オブジェクトIDです。
701 //! @param[in] size メモリサイズです。
702 //---------------------------------------------------------------------------
703 void DeallocateGraphicsMemory(GLenum area, GLenum aim, GLuint id, void* addr);
704
705 } // namespace demo
706 } // namespace nw
707
708 #endif // NW_DEMO_GRAPHICSSYSTEM_H_
709