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 //! nngxExtensionMode で指定する引数となります。 36 //--------------------------------------------------------------------------- 37 enum UpperScreenMode 38 { 39 UPPER_SCREEN_MODE_NORMAL = NN_GX_DISPLAYMODE_NORMAL, //!< 通常モードを表します。 40 UPPER_SCREEN_MODE_STEREO = NN_GX_DISPLAYMODE_STEREO //!< 3Dモードを表します。 41 }; 42 */ 43 44 //--------------------------------------------------------------------------- 45 //! @brief 描画機能をまとめるためのクラスです。 46 //--------------------------------------------------------------------------- 47 class SmRenderSystem : public SmBase 48 { 49 public: 50 51 //--------------------------------------------------------------------------- 52 //! @brief 描画システムの設定内容です。 53 //--------------------------------------------------------------------------- 54 struct Description 55 { 56 //! @brief 描画を行うスクリーンサイズを表します。 57 struct ScreenSize 58 { 59 s32 width; //!< スクリーンの横幅を表します。 60 s32 height; //!< スクリーンの縦幅を表します。 61 //! @brief コンストラクタです。 ScreenSizeDescription::ScreenSize62 ScreenSize(s32 w, s32 h) : width(w), height(h) {} 63 }; 64 65 //! @brief スクリーンオフセットを表します。 66 struct ScreenOffset 67 { 68 s32 x; //!< オフセットのX座標を表します。 69 s32 y; //!< オフセットのY座標を表します。 70 //! @brief コンストラクタです。 ScreenOffsetDescription::ScreenOffset71 ScreenOffset(s32 x, s32 y) : x(x), y(y) {} 72 }; 73 //! @brief 上画面のディスプレイバッファスワッパの設定内容です。 74 nw::demo::DisplayBufferSwapper::Description upperScreenDescription; 75 76 //! @brief 下画面のディスプレイバッファスワッパの設定内容です。 77 nw::demo::DisplayBufferSwapper::Description lowerScreenDescription; 78 79 nw::gfx::RenderColorFormat renderColorFormat; //!< スクリーンのカラーフォーマットを表します。 80 size_t commandBufferSize; //!< コマンドバッファのサイズを現します。 81 size_t commandRequestCount; //!< コマンドリクエストの上限数を表します。 82 size_t reusableCommandBufferSize; //!< 再利用コマンドリストのコマンドバッファのサイズを現します。 83 size_t reusableCommandRequestCount; //!< 再利用コマンドリストのコマンドリクエストの上限数を表します。 84 // UpperScreenMode upperScreenMode; //!< 上画面のモードです。 85 86 size_t commandListCount; //!< 生成するコマンドリストの数です。 87 size_t displayBufferCount; //!< 生成するディスプレイバッファの数です。 88 89 size_t maxGpuProfilingEntryCount; //!< コマンドリストの GPU プロファイラエントリの上限数を表します。 90 91 //! @brief コンストラクタです。 92 //! 立体視表示をしない場合のデフォルト値がセットされます。 DescriptionDescription93 Description() 94 : renderColorFormat(nw::gfx::RENDER_COLOR_FORMAT_RGBA8), 95 commandBufferSize(0x100000), 96 commandRequestCount(512), 97 reusableCommandBufferSize(0), 98 reusableCommandRequestCount(0), 99 // upperScreenMode(NN_GX_DISPLAYMODE_STEREO), 100 commandListCount(2), 101 displayBufferCount(2), 102 maxGpuProfilingEntryCount(8) 103 { 104 upperScreenDescription.screenKind = nw::demo::UPPER_SCREEN; 105 upperScreenDescription.width = NN_GX_DISPLAY0_HEIGHT; 106 upperScreenDescription.height = NN_GX_DISPLAY0_WIDTH; 107 108 lowerScreenDescription.screenKind = nw::demo::LOWER_SCREEN; 109 lowerScreenDescription.width = NN_GX_DISPLAY1_HEIGHT; 110 lowerScreenDescription.height = NN_GX_DISPLAY1_WIDTH; 111 } 112 }; 113 114 115 //---------------------------------------- 116 // コンストラクタです。 117 SmRenderSystem( const Description& description ); 118 119 //---------------------------------------- 120 // デストラクタです。 121 ~SmRenderSystem(); 122 123 //---------------------------------------- 124 // レンダターゲットを設定します。 125 void SetRenderTarget( nw::gfx::IRenderTarget* renderTarget ); 126 127 //---------------------------------------- 128 // バッファを消去します。 129 void ClearBuffer( nw::ut::FloatColor clearColor ); 130 131 //---------------------------------------- 132 // バッファを転送します。 133 void TransferBuffer(s32 screenKind); 134 135 //---------------------------------------- 136 // コマンドリスト処理の終了待ちを行います。 137 void WaitCommandList(); 138 139 //---------------------------------------- 140 // VSync 待ちを行います。 141 void WaitVSync(s32 screenKind); 142 143 //---------------------------------------- 144 // バッファのスワップを予約します。 145 void SwapBuffer( s32 screenKind ); 146 147 //---------------------------------------- 148 // RenderContextを取得します。 GetRenderContext()149 nw::gfx::RenderContext* GetRenderContext() { return m_RenderContext; } 150 151 // 視差計算 152 void CalcStereoCamera( 153 nw::gfx::Camera* leftCamera, 154 nw::gfx::Camera* rightCamera, 155 nw::gfx::Camera* baseCamera, 156 f32 depthLevel = 1.0f, 157 f32 depthRange = 1.0f); 158 159 // test GetCacheCmdListUpper()160 GLuint GetCacheCmdListUpper() { return m_CacheCmdListUpper; } GetCacheCmdListLower()161 GLuint GetCacheCmdListLower() { return m_CacheCmdListLower; } GetCommandList()162 GLuint GetCommandList() { return m_CommandList; } 163 164 private: 165 //! @brief CreateRenderSystemの内部メソッドです。 166 NW_INLINE void CreateInternal_(const Description& description); 167 168 nw::gfx::RenderContext* m_RenderContext; 169 nw::demo::DisplayBufferSwapper* m_UpperSwapper; 170 nw::demo::DisplayBufferSwapper* m_LowerSwapper; 171 nw::demo::DisplayBufferSwapper* m_ExtensionSwapper; 172 173 GLuint m_CommandList; 174 GLuint m_CacheCmdListUpper; 175 GLuint m_CacheCmdListLower; 176 177 nn::ulcd::CTR::StereoCamera* m_StereoCamera; 178 179 nw::gfx::IRenderTarget* m_RenderTarget; 180 }; 181 182 183 //--------------------------------------------------------------------------- 184 //! @brief グラフィックスシステムに必要な各種初期化を行います。 185 //--------------------------------------------------------------------------- 186 void SmInitializeGraphicsSystem(nw::demo::DemoAllocator* deviceAllocator); 187 188 //--------------------------------------------------------------------------- 189 //! @brief グラフィックスシステムの終了処理を行います。 190 //--------------------------------------------------------------------------- 191 void SmFinalizeGraphicsSystem(nw::demo::DemoAllocator* deviceAllocator); 192 193 194 #endif // SM_RENDER_SYSTEM_H_ 195