1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     SmRenderSystem.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: 18422 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef SM_RENDER_SYSTEM_H_
17 #define SM_RENDER_SYSTEM_H_
18 
19 #include "../include/SmBase.h"
20 #include <nw/demo/demo_DisplayBufferSwapper.h>
21 #include <nw/gfx/gfx_IRenderTarget.h>
22 #include <nw/gfx/gfx_RenderQueue.h>
23 #include <nw/ut/ut_MoveArray.h>
24 #include <nw/ut/ut_ResUtil.h>
25 #include <nw/math.h>
26 #include <nw/dev/dev_CallbackChain.h>
27 #include <nn/gx.h>
28 #include <nn/ulcd/CTR/ulcd_StereoCamera.h>
29 #include <nw/demo/demo_GraphicsMemoryAllocator.h>
30 #include <nw/gfx.h>
31 
32 
33 //---------------------------------------------------------------------------
34 //! @brief        描画機能をまとめるためのクラスです。
35 //---------------------------------------------------------------------------
36 class SmRenderSystem : public SmBase
37 {
38 public:
39     enum CommandBufferSide
40     {
41         COMMAND_BUFFER_SIZE_0 = 0,
42         COMMAND_BUFFER_SIZE_1 = 1,
43         COMMAND_BUFFER_SIZE_MAX = 2
44     };
45 
46     //---------------------------------------------------------------------------
47     //! @brief        描画システムの設定内容です。
48     //---------------------------------------------------------------------------
49     struct Description
50     {
51         //! @brief 描画を行うスクリーンサイズを表します。
52         struct ScreenSize
53         {
54             s32 width;  //!< スクリーンの横幅を表します。
55             s32 height; //!< スクリーンの縦幅を表します。
56             //! @brief コンストラクタです。
ScreenSizeDescription::ScreenSize57             ScreenSize(s32 w, s32 h) : width(w), height(h) {}
58         };
59 
60         //! @brief スクリーンオフセットを表します。
61         struct ScreenOffset
62         {
63             s32 x;  //!< オフセットのX座標を表します。
64             s32 y;  //!< オフセットのY座標を表します。
65             //! @brief コンストラクタです。
ScreenOffsetDescription::ScreenOffset66             ScreenOffset(s32 x, s32 y) : x(x), y(y) {}
67         };
68         //! @brief 上画面のディスプレイバッファスワッパの設定内容です。
69         nw::demo::DisplayBufferSwapper::Description upperScreenDescription;
70 
71         //! @brief 下画面のディスプレイバッファスワッパの設定内容です。
72         nw::demo::DisplayBufferSwapper::Description lowerScreenDescription;
73 
74         nw::gfx::RenderColorFormat renderColorFormat;   //!< スクリーンのカラーフォーマットを表します。
75         size_t displayBufferCount;                      //!< 生成するディスプレイバッファの数です。
76         size_t maxGpuProfilingEntryCount;               //!< コマンドリストの GPU プロファイラエントリの上限数を表します。
77 
78         //! @brief コンストラクタです。
79         //!        立体視表示をしない場合のデフォルト値がセットされます。
DescriptionDescription80         Description()
81         : renderColorFormat(nw::gfx::RENDER_COLOR_FORMAT_RGBA8),
82           displayBufferCount(2),
83           maxGpuProfilingEntryCount(8)
84         {
85             upperScreenDescription.screenKind = nw::demo::UPPER_SCREEN;
86             upperScreenDescription.width  = NN_GX_DISPLAY0_HEIGHT;
87             upperScreenDescription.height = NN_GX_DISPLAY0_WIDTH;
88 
89             lowerScreenDescription.screenKind = nw::demo::LOWER_SCREEN;
90             lowerScreenDescription.width  = NN_GX_DISPLAY1_HEIGHT;
91             lowerScreenDescription.height = NN_GX_DISPLAY1_WIDTH;
92         }
93     };
94 
95 
96     //----------------------------------------
97     // コンストラクタです。
98     SmRenderSystem( const Description& description );
99 
100     //----------------------------------------
101     // デストラクタです。
102     ~SmRenderSystem();
103 
104     //----------------------------------------
105     // レンダターゲットを設定します。
106     void SetRenderTarget( nw::gfx::IRenderTarget* renderTarget );
107 
108     //----------------------------------------
109     // バッファを消去します。
110     void ClearBuffer( nw::ut::FloatColor clearColor );
111 
112     //----------------------------------------
113     // バッファを転送します。
114     void TransferBuffer(s32 screenKind);
115 
116     //----------------------------------------
117     // コマンドリスト処理の終了待ちを行います。
118     void WaitCommandList();
119 
120     //----------------------------------------
121     // VSync 待ちを行います。
122     void WaitVSync(s32 screenKind);
123 
124     //----------------------------------------
125     // バッファのスワップを予約します。
126     void SwapBuffer( s32 screenKind );
127 
128     //----------------------------------------
129     // RenderContextを取得します。
GetRenderContext()130     nw::gfx::RenderContext* GetRenderContext() { return m_RenderContext; }
131 
132     // 視差計算
133     void CalcStereoCamera(
134         nw::gfx::Camera* leftCamera,
135         nw::gfx::Camera* rightCamera,
136         nw::gfx::Camera* baseCamera,
137         f32 depthLevel = 1.0f,
138         f32 depthRange = 1.0f);
139 
GetCacheCmdListUpper(CommandBufferSide size)140     GLuint GetCacheCmdListUpper(CommandBufferSide size)  { return m_CacheCmdListUpper[size]; }
GetCacheCmdListLower()141     GLuint GetCacheCmdListLower()  { return m_CacheCmdListLower; }
142 
143 private:
144     NW_INLINE void CreateInternal_();
145 
146     nw::gfx::RenderContext*             m_RenderContext;
147     nw::demo::DisplayBufferSwapper*     m_UpperSwapper;
148     nw::demo::DisplayBufferSwapper*     m_LowerSwapper;
149     nw::demo::DisplayBufferSwapper*     m_ExtensionSwapper;
150 
151     GLuint                              m_CacheCmdListUpper[COMMAND_BUFFER_SIZE_MAX];
152     GLuint                              m_CacheCmdListLower;
153 
154     nn::ulcd::CTR::StereoCamera*        m_StereoCamera;
155 
156     nw::gfx::IRenderTarget*             m_RenderTarget;
157 };
158 
159 
160 //---------------------------------------------------------------------------
161 //! @brief        グラフィックスシステムに必要な各種初期化を行います。
162 //---------------------------------------------------------------------------
163 void SmInitializeGraphicsSystem(nw::demo::DemoAllocator* deviceAllocator);
164 
165 //---------------------------------------------------------------------------
166 //! @brief        グラフィックスシステムの終了処理を行います。
167 //---------------------------------------------------------------------------
168 void SmFinalizeGraphicsSystem(nw::demo::DemoAllocator* deviceAllocator);
169 
170 
171 #endif // SM_RENDER_SYSTEM_H_
172