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