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