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