1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: demo_DisplayBufferSwapper.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_DISPLAYBUFFERSWAPPER_H_ 19 #define NW_DEMO_DISPLAYBUFFERSWAPPER_H_ 20 21 #include <nw/gfx/gfx_GfxObject.h> 22 #include <nw/gfx/gfx_IRenderTarget.h> 23 24 #include <nw/ut/ut_MoveArray.h> 25 #include <nw/ut/ut_Preprocessor.h> 26 27 namespace nw 28 { 29 namespace os 30 { 31 class IAllocator; 32 } // namespace os 33 34 namespace demo 35 { 36 37 //--------------------------------------------------------------------------- 38 //! @brief スクリーンの種別を表す定義です。 39 //--------------------------------------------------------------------------- 40 enum ScreenKind 41 { 42 UPPER_SCREEN = 0x1 << 0, //!< 上画面を表します。 43 LOWER_SCREEN = 0x1 << 1, //!< 下画面を表します。 44 EXTENSION_SCREEN = 0x1 << 2, //!< 拡張スクリーンを表します。 45 NORMAL_SCREENS = UPPER_SCREEN | LOWER_SCREEN, 46 BOTH_SCREENS = UPPER_SCREEN | LOWER_SCREEN | EXTENSION_SCREEN 47 }; 48 49 //--------------------------------------------------------------------------- 50 //! @brief ディスプレイバッファの転送モードを表す定義です。 51 //--------------------------------------------------------------------------- 52 enum BufferTransferMode 53 { 54 TRANSFER_MODE_ANTIALIASE_NOT_USED, //!< アンチエイリアスは行いません。 55 TRANSFER_MODE_ANTIALIASE_2x1, //!< 2×1アンチエイリアスで転送します。 56 TRANSFER_MODE_ANTIALIASE_2x2, //!< 2×2アンチエイリアスで転送します。 57 TRANSFER_MODE_ANTIALIASE_COUNT //!< 転送モードの数を表します。 58 }; 59 60 //--------------------------------------------------------------------------- 61 //! @brief ディスプレイバッファの転送を行うクラスです。 62 //--------------------------------------------------------------------------- 63 class DisplayBufferSwapper : public gfx::GfxObject 64 { 65 private: 66 NW_DISALLOW_COPY_AND_ASSIGN(DisplayBufferSwapper); 67 68 public: 69 NW_UT_RUNTIME_TYPEINFO; 70 71 //---------------------------------------- 72 //! @name 取得/設定 73 //@{ 74 75 //! @brief ディスプレイバッファスワッパの設定内容です。 76 struct Description 77 { 78 ScreenKind screenKind; //!< スクリーンバッファの種類です。 79 s32 width; //!< バッファの横幅です。 80 s32 height; //!< バッファの縦幅です。 81 gfx::RenderColorFormat format; //!< バッファのカラーフォーマットです。 82 BufferTransferMode transferMode;//!< バッファの転送モードです。 83 nw::gfx::GraphicsMemoryArea memoryArea; //!< 配置するメモリ領域です。 84 bool isTransferFlipX; //!< 転送時にX方向にフリップするかどうかを表します。 85 s32 transferOffsetX; //!< 転送を行う始点X座標です。 86 s32 transferOffsetY; //!< 転送を行う始点Y座標です。 87 s32 displayOffsetX; //!< 表示を行う始点X座標です。 88 s32 displayOffsetY; //!< 表示を行う始点Y座標です。 89 size_t bufferCount; //!< ディスプレイバッファの数です。 90 91 //! @brief コンストラクタです。 DescriptionDescription92 Description() 93 : screenKind(UPPER_SCREEN), 94 width(400), 95 height(240), 96 format(gfx::RENDER_COLOR_FORMAT_RGB8), 97 transferMode(TRANSFER_MODE_ANTIALIASE_NOT_USED), 98 memoryArea(nw::gfx::MEMORY_AREA_FCRAM), 99 isTransferFlipX(false), 100 transferOffsetX(0), 101 transferOffsetY(0), 102 displayOffsetX(0), 103 displayOffsetY(0), 104 bufferCount(1) 105 {} 106 }; 107 108 //! @brief ディスプレイバッファスワッパを構築するためのクラスです。 109 class Builder 110 { 111 public: 112 //! @brief 構築するディスプレイバッファの内容を設定します。 BufferDescription(const Description & description)113 Builder& BufferDescription(const Description& description) 114 { 115 m_Description = description; 116 return *this; 117 } 118 119 //! @brief 構築するディスプレイバッファのスクリーンを設定します。 ScreenKind(ScreenKind kind)120 Builder& ScreenKind(ScreenKind kind) 121 { 122 m_Description.screenKind = kind; 123 return *this; 124 } 125 126 //! @brief 構築するディスプレイバッファのサイズを設定します。 BufferSize(s32 width,s32 height)127 Builder& BufferSize(s32 width, s32 height) 128 { 129 m_Description.width = width; 130 m_Description.height = height; 131 return *this; 132 } 133 134 //! @brief 構築するディスプレイバッファの横幅を設定します。 Width(s32 width)135 Builder& Width(s32 width) { m_Description.width = width; return *this; } 136 137 //! @brief 構築するディスプレイバッファの縦幅を設定します。 Height(s32 height)138 Builder& Height(s32 height) { m_Description.height = height; return *this; } 139 140 //! @brief 構築するディスプレイバッファのカラーフォーマットを設定します。 Format(gfx::RenderColorFormat format)141 Builder& Format(gfx::RenderColorFormat format) 142 { 143 m_Description.format = format; 144 return *this; 145 } 146 147 //! @brief 構築するディスプレイバッファの転送モードを設定します。 TransferMode(BufferTransferMode mode)148 Builder& TransferMode(BufferTransferMode mode) 149 { 150 m_Description.transferMode = mode; 151 return *this; 152 } 153 154 //! @brief 構築するディスプレイバッファのメモリ配置を設定します。 MemoryArea(nw::gfx::GraphicsMemoryArea area)155 Builder& MemoryArea(nw::gfx::GraphicsMemoryArea area) 156 { 157 m_Description.memoryArea = area; 158 return *this; 159 } 160 161 //! @brief 構築するディスプレイバッファをX方向に反転するかどうかを設定します。 IsTransferFlipX(bool isTransferFlipX)162 Builder& IsTransferFlipX(bool isTransferFlipX) 163 { 164 m_Description.isTransferFlipX = isTransferFlipX; 165 return *this; 166 } 167 168 //! @brief 構築するディスプレイバッファにカラーバッファを転送する始点を設定します。 TransferOffset(s32 x,s32 y)169 Builder& TransferOffset(s32 x, s32 y) 170 { 171 m_Description.transferOffsetX = x; 172 m_Description.transferOffsetY = y; 173 return *this; 174 } 175 176 //! @brief 構築するディスプレイバッファの表示領域の始点を設定します。 DisplayOffset(s32 x,s32 y)177 Builder& DisplayOffset(s32 x, s32 y) 178 { 179 m_Description.displayOffsetX = x; 180 m_Description.displayOffsetY = y; 181 return *this; 182 } 183 184 //! @brief 構築するディスプレイバッファの数を設定します。 BufferCount(size_t count)185 Builder& BufferCount(size_t count) { m_Description.bufferCount = count; return *this; } 186 187 //--------------------------------------------------------------------------- 188 //! @brief ディスプレイバッファスワッパを生成します。 189 //! 190 //! @param[in] allocator アロケータです。 191 //! 192 //! @return 生成したディスプレイバッファスワッパを返します。 193 //--------------------------------------------------------------------------- 194 DisplayBufferSwapper* Create(os::IAllocator* allocator); 195 196 private: 197 Description m_Description; 198 }; 199 200 //! @brief 設定内容を取得します。 201 //! 202 //! @return 設定内容を返します。 GetDescription()203 const Description& GetDescription() const { return m_Description; } 204 205 //@} 206 207 208 //--------------------------------------------------------------------------- 209 //! @brief ディスプレイバッファにターゲットのバッファを転送するコマンドをコマンドリストに追加します。 210 //! 211 //! レンダーバッファーをディスプレイバッファに転送するコマンドを生成し、 212 //! バインドされているコマンドリストに追加します。 213 //! 214 //! コマンドリストが多重化されている場合は転送コマンドが実行されるタイミングが変わりますので、 215 //! 転送先のディスプレイバッファを変更します。 216 //! isMultiCommandList に true を指定することでこの変更は自動的に行われます。 217 //! 218 //! @param[in] target ディスプレイバッファに転送するバッファです。 219 //! @param[in] isMultiCommandList コマンドリストが多重化されているかを指定します。 220 //--------------------------------------------------------------------------- 221 void MakeTransferBufferCommand(gfx::IRenderTarget* target, bool isMultiCommandList); 222 223 //--------------------------------------------------------------------------- 224 //! @brief ディスプレイバッファを有効にします。 225 //--------------------------------------------------------------------------- 226 void ActivateBuffer(); 227 228 //---------------------------------------- 229 //! @name コンストラクタ/デストラクタ 230 //@{ 231 private: 232 //! コンストラクタです。 233 DisplayBufferSwapper( 234 os::IAllocator* allocator, 235 const Description& description); 236 DisplayBufferSwapper(os::IAllocator * allocator)237 DisplayBufferSwapper(os::IAllocator* allocator) : GfxObject(allocator) {} 238 239 protected: 240 //! デストラクタです。 ~DisplayBufferSwapper()241 virtual ~DisplayBufferSwapper() 242 { 243 if (m_DisplayBuffers) 244 { 245 nngxDeleteDisplaybuffers( m_Description.bufferCount, m_DisplayBuffers ); 246 nw::os::SafeFree(m_DisplayBuffers, &this->GetAllocator()); 247 } 248 } 249 250 //@} 251 252 private: 253 Description m_Description; 254 u32 m_CurrentDisplay; 255 GLuint* m_DisplayBuffers; 256 }; 257 258 } // namespace demo 259 } // namespace nw 260 261 #endif // NW_DEMO_DISPLAYBUFFERSWAPPER_H_ 262