1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_FrameBuffer.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 NW_GFX_FRAME_BUFFER_H_ 19 #define NW_GFX_FRAME_BUFFER_H_ 20 21 #include <gles2/gl2.h> 22 #include <nw/ut/ut_Color.h> 23 24 namespace nw { 25 namespace gfx { 26 27 //--------------------------------------------------------------------------- 28 //! @brief フレームバッファの設定です。 29 //--------------------------------------------------------------------------- 30 class FrameBufferObject 31 { 32 public: 33 34 //! @brief 設定内容です。 35 struct Description 36 { 37 GLuint fboID; //!< フレームバッファオブジェクトのIDを指定します。 38 u32 height; //!< バッファの高さ情報です。 39 u32 width; //!< バッファの幅情報です。 40 u32 colorFormat; //!< カラーバッファのフォーマットです。 41 u32 depthFormat; //!< デプスバッファのフォーマットです。 42 u32 colorAddress; //!< カラーバッファのアドレスを指定します。 43 u32 depthAddress; //!< デプスバッファのアドレスを指定します。 44 45 bool useBlock32; //!< ブロック32モードを使用するかどうかを指定します。EarlyDepthTest を使用しない場合は通常 false を設定します。 46 47 //! @brief デフォルトコンストラクタです。 DescriptionDescription48 Description() 49 { 50 fboID = 0; 51 useBlock32 = false; 52 colorAddress = NULL; 53 depthAddress = NULL; 54 } 55 }; 56 57 //--------------------------------------------------------------------------- 58 //! @brief 過去互換のための、フレームバッファオブジェクトID へのキャスト演算子です。 59 //! 60 //! @return gl の FBO を使用している場合は fbo のIDを返します。使用していない場合は 0 を返します。 61 //--------------------------------------------------------------------------- GLuint()62 operator GLuint() const 63 { 64 return m_Description.fboID; 65 } 66 67 //--------------------------------------------------------------------------- 68 //! @brief フレームバッファ設定を取得します。 69 //! 70 //! @return フレームバッファの設定情報です。 71 //--------------------------------------------------------------------------- GetDescription()72 const Description& GetDescription() const { return m_Description; } GetDescription()73 Description& GetDescription() { return m_Description; } 74 75 //--------------------------------------------------------------------------- 76 //! @brief フレームバッファ設定をセットします。 77 //! 78 //! @param[in] description フレームバッファ設定です。 79 //--------------------------------------------------------------------------- 80 void SetDescription(const Description& description); 81 82 //--------------------------------------------------------------------------- 83 //! @brief gl のフレームバッファオブジェクトのIDを取得します。 84 //! 85 //! @return gl のフレームバッファオブジェクトのIDです。 86 //--------------------------------------------------------------------------- GetFboID()87 GLuint GetFboID() const { return m_Description.fboID; } 88 89 //--------------------------------------------------------------------------- 90 //! @brief gl のフレームバッファオブジェクトのIDを設定します。 91 //! 92 //! @param[in] fboID gl のフレームバッファオブジェクトのIDです。 93 //--------------------------------------------------------------------------- 94 void SetFboID(GLuint fboID); 95 96 //--------------------------------------------------------------------------- 97 //! @brief フレームバッファの高さを取得します。 98 //! 99 //! @return フーレムバッファの高さです。 100 //--------------------------------------------------------------------------- GetHeight()101 u32 GetHeight() const { return m_Description.height; } 102 103 //--------------------------------------------------------------------------- 104 //! @brief フレームバッファの高さを設定します。 105 //! 106 //! @param[in] height フレームバッファの高さです。 107 //--------------------------------------------------------------------------- SetHeight(u32 height)108 void SetHeight(u32 height) { m_Description.height = height; } 109 110 //--------------------------------------------------------------------------- 111 //! @brief フレームバッファの幅を取得します。 112 //! 113 //! @return フレームバッファの幅です。 114 //--------------------------------------------------------------------------- GetWidth()115 u32 GetWidth() const { return m_Description.width; } 116 117 //--------------------------------------------------------------------------- 118 //! @brief フレームバッファの幅を設定します。 119 //! 120 //! @param[in] width フレームバッファの幅です。 121 //--------------------------------------------------------------------------- SetWidth(u32 width)122 void SetWidth(u32 width) { m_Description.width = width; } 123 124 //--------------------------------------------------------------------------- 125 //! @brief カラーバッファのフォーマットを取得します。 126 //! 127 //! @return カラーバッファのフォーマットです。 128 //--------------------------------------------------------------------------- GetColorFormat()129 u32 GetColorFormat() const { return m_Description.colorFormat; } 130 131 //--------------------------------------------------------------------------- 132 //! @brief カラーバッファのフォーマットを設定します。 133 //! 134 //! @param[in] colorFormat カラーバッファのフォーマットです。 135 //--------------------------------------------------------------------------- SetColorFormat(u32 colorFormat)136 void SetColorFormat(u32 colorFormat) { m_Description.colorFormat = colorFormat; } 137 138 //--------------------------------------------------------------------------- 139 //! @brief デプスバッファのフォーマットを取得します。 140 //! 141 //! @return デプスバッファのフォーマットです。 142 //--------------------------------------------------------------------------- GetDepthFormat()143 u32 GetDepthFormat() const { return m_Description.depthFormat; } 144 145 //--------------------------------------------------------------------------- 146 //! @brief デプスバッファのフォーマットを設定します。 147 //! 148 //! @param[in] depthFormat デプスバッファのフォーマットです。 149 //--------------------------------------------------------------------------- SetDepthFormat(u32 depthFormat)150 void SetDepthFormat(u32 depthFormat) { m_Description.depthFormat = depthFormat; } 151 152 //--------------------------------------------------------------------------- 153 //! @brief カラーバッファのアドレスを取得します。 154 //! 155 //! @return カラーバッファのアドレスです。 156 //--------------------------------------------------------------------------- GetColorAddress()157 u32 GetColorAddress() const { return m_Description.colorAddress; } 158 159 //--------------------------------------------------------------------------- 160 //! @brief カラーバッファのアドレスを設定します。 161 //! 162 //! @param[in] colorAddress カラーバッファのアドレスです。 163 //--------------------------------------------------------------------------- SetColorAddress(u32 colorAddress)164 void SetColorAddress(u32 colorAddress) { m_Description.colorAddress = colorAddress; } 165 166 //--------------------------------------------------------------------------- 167 //! @brief デプスバッファのアドレスを取得します。 168 //! 169 //! @return デプスバッファのアドレスです。 170 //--------------------------------------------------------------------------- GetDepthAddress()171 u32 GetDepthAddress() const { return m_Description.depthAddress; } 172 173 //--------------------------------------------------------------------------- 174 //! @brief デプスバッファのアドレスを設定します。 175 //! 176 //! @param[in] depthAddress デプスバッファのアドレスです。 177 //--------------------------------------------------------------------------- SetDepthAddress(u32 depthAddress)178 void SetDepthAddress(u32 depthAddress) { m_Description.depthAddress = depthAddress; } 179 180 //--------------------------------------------------------------------------- 181 //! @brief フレームバッファの設定用コマンドを設定します。 182 //--------------------------------------------------------------------------- 183 void ActivateBuffer() const; 184 185 //--------------------------------------------------------------------------- 186 //! @brief フレームバッファからディスプレイバッファへの転送コマンドを設定します。 187 //! 188 //! @param[in] dstAddress 転送先アドレスです。 189 //! @param[in] dstFormat 転送先のフォーマットです。 190 //! @param[in] antiAliasMode アンチエイリアスフィルタのモードです。 191 //! @param[in] yFlip Yフリップをおこなうかどうかのフラグです。 192 //--------------------------------------------------------------------------- TransferRenderImage(u32 dstAddress,GLenum dstFormat,GLenum antiAliasMode,bool yFlip)193 void TransferRenderImage(u32 dstAddress, GLenum dstFormat, GLenum antiAliasMode, bool yFlip) const 194 { 195 const void* srcAddress = reinterpret_cast<const void*>(this->GetColorAddress()); 196 const u32 width = this->GetWidth(); 197 const u32 height = this->GetHeight(); 198 const u32 srcFormat = this->GetColorFormat(); 199 200 nngxAddB2LTransferCommand( 201 srcAddress, width, height, srcFormat, 202 reinterpret_cast<void*>(dstAddress), width, height, dstFormat, 203 antiAliasMode, yFlip, 8); 204 } 205 206 enum 207 { 208 //! カラーバッファをクリアするフラグです。 209 CLEAR_MASK_COLOR = GL_COLOR_BUFFER_BIT, 210 211 //! デプスバッファとステンシルバッファをクリアするフラグです。 212 //! ステンシルバッファ単体でのクリアはできません。 213 CLEAR_MASK_DEPTH = GL_DEPTH_BUFFER_BIT, 214 215 //! カラーバッファ、デプスバッファの両方をクリアするフラグです。 216 CLEAR_MASK_ALL = CLEAR_MASK_COLOR | CLEAR_MASK_DEPTH 217 }; 218 219 //--------------------------------------------------------------------------- 220 //! @brief フレームバッファのクリアを実行します。 221 //! 222 //! @details AcitvateFrameBuffer で有効化されているフレームバッファに対して、 223 //! glClear 相当のクリア処理を実行します。 224 //! 225 //! @param[in] mask クリアするバッファを指定するマスク値です。 226 //! @param[in] clearColor クリアカラーです。 227 //! @param[in] clearDepth クリアデプスです。 228 //! @param[in] clearStencil クリアステンシル値です。 229 //--------------------------------------------------------------------------- 230 void ClearBuffer( u32 mask, const ut::FloatColor& clearColor, f32 clearDepth, u8 clearStencil = 0 ) const; 231 void ClearBuffer( const ut::FloatColor& clearColor, f32 clearDepth, u8 clearStencil = 0 ) const 232 { 233 this->ClearBuffer( CLEAR_MASK_ALL, clearColor, clearDepth, clearStencil ); 234 } 235 236 private: 237 Description m_Description; 238 }; 239 240 } // namespace gfx 241 } // namespace nw 242 243 244 #endif // NW_GFX_ACTIVATE_COMMAND_H_ 245