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: 28406 $
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 負荷メーターの内容を取得します。
GetLoadMeter()459     const LoadMeterDescription& GetLoadMeter() { return m_LoadMeterDescription; }
460 
461     //! @brief 積算負荷を取得します。
GetCumulativeLoadMeter()462     const LoadMeterDescription& GetCumulativeLoadMeter() { return m_CumulativeLoadMeterDescription; }
463 
464     //! @brief ロードメーターで表示する描画コマンドのサイズを追加します。
AddLoadMeterCommandSize(s32 commandSize)465     void AddLoadMeterCommandSize(s32 commandSize) { m_LoadMeterDescription.drawCommandBufferSize += commandSize; }
466 
467     //! @brief 描画と転送の間に呼び出されるシグナルを取得します。
468     //!        立体視を行う場合は 左目の描画後に呼び出されます。
469     //!
470     //! @return シグナルを取得します。
471     //!
GetPostRenderCallback()472     ut::Signal1<void, const gfx::Camera*>* GetPostRenderCallback() const
473     {
474         return this->m_PostRenderCallback;
475     }
476 
477     //! @brief 右目の描画と転送の間に呼び出されるシグナルを取得します。
478     //!
479     //! @return シグナルを取得します。
480     //!
GetPostRightRenderCallback()481     ut::Signal1<void, const gfx::Camera*>* GetPostRightRenderCallback() const
482     {
483         return this->m_PostRightRenderCallback;
484     }
485     //@}
486 
487 private:
488     //! @brief コンストラクタです。
RenderSystem()489     RenderSystem()
490     : m_Allocator(NULL),
491       m_RenderContext(NULL),
492       m_PriorMaterialRenderKeyFactory(NULL),
493       m_RenderQueue(NULL),
494       m_MeshRenderer(NULL),
495       m_RenderSortMode(gfx::ISceneUpdater::ALL_MESH_BASE_SORT),
496       m_UpperSwapper(NULL),
497       m_LowerSwapper(NULL),
498       m_ExtensionSwapper(NULL),
499       m_CommandListSwapper(NULL),
500       m_StereoCamera(NULL),
501       m_SkyModel(NULL),
502       m_PostRenderCallback(NULL),
503       m_PostRightRenderCallback(NULL)
504     {
505     }
506 
507     os::IAllocator* m_Allocator;
508     gfx::RenderContext* m_RenderContext;
509     gfx::RenderKeyFactory* m_PriorMaterialRenderKeyFactory;
510     gfx::RenderKeyFactory* m_PriorDepthRenderKeyFactory;
511     gfx::RenderQueue* m_RenderQueue;
512     gfx::MeshRenderer* m_MeshRenderer;
513     gfx::ISceneUpdater::RenderSortMode m_RenderSortMode;
514 
515     DisplayBufferSwapper* m_UpperSwapper;
516     DisplayBufferSwapper* m_LowerSwapper;
517     DisplayBufferSwapper* m_ExtensionSwapper;
518 
519     CommandListSwapper* m_CommandListSwapper;
520 
521     LoadMeterDescription m_LoadMeterDescription;
522     LoadMeterDescription m_CumulativeLoadMeterDescription;
523 
524     nn::ulcd::CTR::StereoCamera* m_StereoCamera;
525     ResourceArray m_Resources;
526     gfx::Model* m_SkyModel;
527 
528     ut::Signal1<void, const gfx::Camera*>* m_PostRenderCallback;
529     ut::Signal1<void, const gfx::Camera*>* m_PostRightRenderCallback;
530 };
531 
532 
533 //---------------------------------------------------------------------------
534 //! @brief        シーン更新機能をまとめるためのクラスです。
535 //---------------------------------------------------------------------------
536 class SceneSystem
537 {
538 public:
539     //---------------------------------------------------------------------------
540     //! @brief        シーンシステムの設定内容です。
541     //---------------------------------------------------------------------------
542     struct Description
543     {
544         s32 maxSceneNodes; //!< シーンノードの上限数を表します。
545         s32 maxModels; //!< モデルの上限数を表します。
546         s32 maxSkeletalModels; //!< スケルタルモデルの上限数を表します。
547         s32 maxCameras; //!< カメラの上限数を表します。
548         s32 maxLights; //!< ライトの上限数を表します。
549         s32 maxFragmentLights; //!< フラグメントライトの上限数を表します。
550         s32 maxVertexLights; //!< 頂点ライトの上限数を表します。
551         s32 maxHemiSphereLights; //!< 半球ライトの上限数を表します。
552         s32 maxAmbientLights; //!< アンビエントライトの上限数を表します。
553         s32 maxFogs; //!< フォグの上限数を表します。
554         s32 maxParticleSets; //!< パーティクルセットの上限数を表します。
555         s32 maxParticleEmitters; //!< パーティクルエミッタの上限数を表します。
556         s32 maxParticleModels; //!< パーティクルモデルの上限数を表します。
557         s32 maxBones; //!< スケルトンに含まれるボーンの上限数を表します。
558         s32 maxMaterials; //!< マテリアルの最大数です。
559         bool isFixedSizeMemory; //!< 生成時以外にもメモリを確保するかどうかのフラグを設定します。
560 
561         //! @brief コンストラクタです。
DescriptionDescription562         Description()
563         : maxSceneNodes(gfx::SceneContext::DEFAULT_MAX_SCENE_NODES),
564           maxModels(gfx::SceneContext::DEFAULT_MAX_MODELS),
565           maxSkeletalModels(gfx::SceneContext::DEFAULT_MAX_SKELETAL_MODELS),
566           maxCameras(gfx::SceneContext::DEFAULT_MAX_CAMERAS),
567           maxLights(gfx::SceneContext::DEFAULT_MAX_LIGHTS),
568           maxFragmentLights(gfx::SceneContext::DEFAULT_MAX_FRAGMENT_LIGHTS),
569           maxVertexLights(gfx::SceneContext::DEFAULT_MAX_VERTEX_LIGHTS),
570           maxHemiSphereLights(gfx::SceneContext::DEFAULT_MAX_HEMISPHERE_LIGHTS),
571           maxAmbientLights(gfx::SceneContext::DEFAULT_MAX_AMBIENT_LIGHTS),
572           maxFogs(gfx::SceneContext::DEFAULT_MAX_FOGS),
573           maxParticleSets(gfx::SceneContext::DEFAULT_MAX_PARTICLESETS),
574           maxParticleEmitters(gfx::SceneContext::DEFAULT_MAX_PARTICLEEMITTERS),
575           maxParticleModels(gfx::SceneContext::DEFAULT_MAX_PARTICLEMODELS),
576           maxBones(128),
577           maxMaterials(32),
578           isFixedSizeMemory(true)
579         {}
580     };
581 
582     //----------------------------------------
583     //! @name 生成/破棄
584     //@{
585 
586     //---------------------------------------------------------------------------
587     //! @brief        シーン更新関連のクラスを生成します。
588     //!
589     //! @param[in]    allocator   アロケータです。
590     //! @param[in]    description 生成するシーンシステムの設定です。
591     //!
592     //! @return       生成したシーンシステムです。
593     //---------------------------------------------------------------------------
594     static SceneSystem* Create(
595         os::IAllocator* allocator,
596         const Description& description
597     );
598 
599     //---------------------------------------------------------------------------
600     //! @brief        シーンシステムを破棄します。
601     //---------------------------------------------------------------------------
602     void Destroy();
603     //@}
604 
605     //---------------------------------------------------------------------------
606     //! @brief        シーンを初期化します。
607     //!
608     //! @param[in]    sceneRoot   初期化するシーンのルートノードです。
609     //---------------------------------------------------------------------------
610     void InitializeScene(gfx::SceneNode* sceneRoot);
611 
612     //---------------------------------------------------------------------------
613     //! @brief        ルートノードのトラバースを行います。
614     //!
615     //! @param[in]    sceneRoot   対象のルートノードです。
616     //---------------------------------------------------------------------------
617     void TraverseScene(gfx::SceneNode* sceneRoot);
618 
619     //---------------------------------------------------------------------------
620     //! @brief        シーンを更新します。
621     //---------------------------------------------------------------------------
622     void UpdateScene();
623 
624     //! シーンコンテキストを取得します。
GetSceneContext()625     gfx::SceneContext*   GetSceneContext() { return m_SceneContext; }
626 
627     //! シーンアップデータを取得します。
GetSceneUpdater()628     gfx::ISceneUpdater* GetSceneUpdater() { return m_SceneUpdater; }
629 
630     //! カメラ制御クラスを取得します。
GetCameraController()631     nw::demo::CameraController* GetCameraController() { return m_CameraController; }
632 
633 private:
SceneSystem()634     SceneSystem()
635     : m_Allocator(NULL),
636       m_SceneContext(NULL),
637       m_SceneTraverser(NULL),
638       m_SceneUpdater(NULL),
639       m_SceneInitializer(NULL),
640       m_CameraController(NULL)
641     {}
642 
643     os::IAllocator*      m_Allocator;
644     gfx::SceneContext*   m_SceneContext;
645     gfx::SceneTraverser* m_SceneTraverser;
646     gfx::SceneUpdater*   m_SceneUpdater;
647     gfx::SceneInitializer* m_SceneInitializer;
648     CameraController*    m_CameraController;
649 };
650 
651 //---------------------------------------------------------------------------
652 //! @brief        グラフィックスシステムに必要な各種初期化を行います。
653 //!
654 //! @param[in] deviceAllocator デバイスメモリ用のアロケータです。
655 //---------------------------------------------------------------------------
656 void InitializeGraphicsSystem(nw::demo::DemoAllocator* deviceAllocator);
657 
658 //---------------------------------------------------------------------------
659 //! @brief        グラフィックスシステムの終了処理を行います。
660 //---------------------------------------------------------------------------
661 void FinalizeGraphicsSystem();
662 
663 //---------------------------------------------------------------------------
664 //! @brief リソースの後始末をします。
665 //---------------------------------------------------------------------------
666 template <typename TArray>
667 NW_INLINE void
SafeCleanupResources(TArray & resources)668 SafeCleanupResources(TArray& resources)
669 {
670     typename TArray::iterator end = resources.end();
671     for (typename TArray::iterator it = resources.begin();
672         it != end;
673         ++it)
674     {
675         nw::ut::SafeCleanup(it->resource);
676     }
677 }
678 
679 
680 //---------------------------------------------------------------------------
681 //! @brief        GL や VRAM 用のアロケート関数です。
682 //!
683 //! @param[in]    area    対象エリア情報です。
684 //! @param[in]    aim     メモリを要求している対象です。
685 //! @param[in]    id      メモリ要求対象の GL オブジェクトIDです。
686 //! @param[in]    size    メモリサイズです。
687 //---------------------------------------------------------------------------
688 void* AllocateGraphicsMemory(GLenum area, GLenum aim, GLuint id, GLsizei size);
689 
690 
691 //---------------------------------------------------------------------------
692 //! @brief        GL や VRAM 用のでアロケート関数です。
693 //!
694 //! @param[in]    area    対象エリア情報です。
695 //! @param[in]    aim     メモリを要求している対象です。
696 //! @param[in]    id      メモリ要求対象の GL オブジェクトIDです。
697 //! @param[in]    size    メモリサイズです。
698 //---------------------------------------------------------------------------
699 void DeallocateGraphicsMemory(GLenum area, GLenum aim, GLuint id, void* addr);
700 
701 } // namespace demo
702 } // namespace nw
703 
704 #endif // NW_DEMO_GRAPHICSSYSTEM_H_
705