1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     demo_SimpleApp.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_SIMPLEAPP_H_
19 #define NW_DEMO_SIMPLEAPP_H_
20 
21 #include <nw/sdk.h>
22 #include <nw/types.h>
23 #include <nw/demo/demo_GraphicsSystem.h>
24 #include <nw/demo/demo_Memory.h>
25 
26 namespace nw {
27 namespace demo {
28 
29 //---------------------------------------------------------------------------
30 //! @brief        シンプルアプリケーションです。
31 //---------------------------------------------------------------------------
32 class SimpleApp
33 {
34 public:
35     //! @brief 描画する画面の定義です。
36     enum Display
37     {
38         DISPLAY0,       //!< 画面0です。
39         DISPLAY1,       //!< 画面1です。
40         DISPLAY_BOTH,   //!< 画面0と画面1です。
41         DISPLAY_MAX     //!< (列挙値の数です。)
42     };
43 
44     //! @brief 画面のサイズの定数です。
45     enum DisplaySize
46     {
47         DISPLAY0_WIDTH = 400,   //!< 画面0の幅です。
48         DISPLAY0_HEIGHT = 240,  //!< 画面0の高さです。
49         DISPLAY1_WIDTH = 320,   //!< 画面1の幅です。
50         DISPLAY1_HEIGHT = 240   //!< 画面1の高さです。
51     };
52 
53     //! @brief インスタンスを取得します。
54     //!
55     //! @return シングルトンのインスタンスを返します。
GetInstance()56     static SimpleApp& GetInstance()
57     {
58         static SimpleApp s_Instance;
59         return s_Instance;
60     }
61 
62     //!
63     //! @brief 初期化を行います。
64     //!
65     void Initialize();
66 
67     //----------------------------------------
68     //! @name 描画
69     //@{
70 
71     //!
72     //! @brief レンダーターゲットを設定します。
73     //!
74     //! @details
75     //! display には DISPLAY0 か DISPLAY1 が指定できます。
76     //! ( DISPLAY_BOTH は指定できません。)
77     //!
78     //! @param[in] display ターゲットにするディスプレイです。
79     //!
80     void SetRenderingTarget(Display display);
81 
82     //!
83     //! @brief 設定されているレンダーターゲットのフレームバッファオブジェクトを取得します。
84     //!
85     //! @return フレームバッファオブジェクトへの参照を返します。
86     //!
87     const gfx::FrameBufferObject& GetFrameBufferObject() const;
88 
89     //!
90     //! @brief レンダーバッファからディスプレイバッファに表示します。
91     //!
92     //! @param[in]  display 表示するディスプレイです。
93     //!
94     void SwapBuffer(Display display);
95 
96     //@}
97 
98     //!
99     //! @brief 終了処理を行います。
100     //!
101     void Finalize();
102 
103     //----------------------------------------
104     //! @name メモリ確保/解放
105     //@{
106 
107     //!
108     //! @brief        メインメモリからメモリを確保します
109     //!
110     //! @param[in]    size        確保するサイズです。
111     //! @param[in]    alignment   確保するメモリのアライメントです。
112     //!
113     //! @return       確保したメモリへのアドレスを返します。
114     //!
115     static void* Allocate(size_t size, u8 alignment = 4);
116 
117     //!
118     //! @brief        デバイスメモリからメモリを確保します
119     //!
120     //! @param[in]    size        確保するサイズです。
121     //! @param[in]    alignment   確保するメモリのアライメントです。
122     //!
123     //! @return       確保したメモリへのアドレスを返します。
124     //!
125     static void* AllocateDeviceMemory(size_t size, u8 alignment = 4);
126 
127     //!
128     //! @brief        メモリを解放します
129     //!
130     //! @param[in] ptr 解放するメモリへのアドレスです。
131     //!                メインメモリとデバイスメモリは区別せずに解放できます。
132     //!
133     static void Free(void* ptr);
134 
135     //!
136     //! @brief メモリアロケータを取得します。
137     //!
138     //! @return メモリアロケータを返します。
139     //!
GetAllocator()140     nw::os::IAllocator& GetAllocator()
141     {
142         return m_DeviceAllocator;
143     }
144 
145     //!
146     //! @brief デバイスメモリアロケータを取得します。
147     //!
148     //! @return デバイスメモリアロケータを返します。
149     //!
GetDeviceAllocator()150     nw::os::IAllocator& GetDeviceAllocator()
151     {
152         return m_DeviceAllocator;
153     }
154 
155     //@}
156 
157     Display m_CurrentDisplay;
158     nw::demo::RenderSystem* m_pRenderSystem;
159     nw::gfx::IRenderTarget* m_pRenderTargetUpper;
160     nw::gfx::IRenderTarget* m_pRenderTargetLower;
161     nw::demo::DemoAllocator m_DeviceAllocator;
162 
163 protected:
164     //!
165     //! @brief コンストラクタです。
166     //!
167     //! 継承した場合はSimpleApp::GetInstance()は使えません。
168     //!
SimpleApp()169     SimpleApp()
170     {
171         if (s_pInstance != NULL)
172         {
173             NW_FATAL_ERROR("nw::demo::SimpleApp instance already exists.");
174         }
175         s_pInstance = this;
176     }
177 
178     //!
179     //! @brief 現在のバッファ内容を転送します。
180     //!
181     void TransferBuffer();
182 
183     //! シングルトンオブジェクトへのポインタです。
184     static SimpleApp* s_pInstance;
185 };
186 
187 } /* namespace demo */
188 } /* namespace nw   */
189 
190 #endif /* NW_DEMO_SIMPLEAPP_H_ */
191 
192