1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     gr_FrameBuffer.h
4 
5   Copyright (C)2010 Nintendo Co., Ltd.  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   $Rev: 33699 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_GR_FRAME_BUFFER_H_
17 #define NN_GR_FRAME_BUFFER_H_
18 
19 #include <nn/gr/CTR/gr_Prefix.h>
20 
21 namespace nn
22 {
23     namespace gr
24     {
25         namespace CTR
26         {
27 
28             /*!
29                 @brief フレームバッファの設定をするためのクラスです。
30              */
31             class FrameBuffer
32             {
33             public :
34                 static const u32 COLOR_BUFFER_BIT         = 0x1; //!< カラーバッファを指定するビットです。
35                 static const u32 DEPTH_BUFFER_BIT         = 0x2; //!< デプスバッファを指定するビットです。
36                 static const u32 STENCIL_BUFFER_BIT       = 0x4; //!< ステンシルバッファを指定するビットです。
37                 static const u32 DEPTH_STENCIL_BUFFER_BIT = DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT; //!< デプスバッファとステンシルバッファを指定するビットです。
38 
39                 /*!
40                     @brief ブロックサイズを設定するための列挙定数です。
41                  */
42                 enum BlockSize
43                 {
44                     /*!
45                         @brief ブロックサイズを 8 にします。
46                     */
47                     BLOCK_SIZE8,
48 
49                     /*!
50                         @brief ブロックサイズを 32 にします。
51                                アーリーデプステスト時に使用します。
52                     */
53                     BLOCK_SIZE32
54                 };
55 
56                 /*!
57                     @brief カラーバッファの設定のためのクラスです。
58                 */
59                 class ColorBuffer
60                 {
61                 public :
62                     /*!
63                         @brief カラーバッファの仮想アドレスです。型は uptr です。
64                     */
65                     uptr  virtualAddr;
66 
67                     /*!
68                         @brief カラーバッファのフォーマットです。型は @ref PicaDataColor です。
69                     */
70                     PicaDataColor format;
71 
72                     /*!
73                         @brief カラーバッファのブロックサイズです。型は @ref BlockSize です。
74                     */
75                     BlockSize blockSize;
76                     NN_PADDING2;
77 
78                     /*!
79                         @brief カラーバッファの幅です。型は s32 です。
80                     */
81                     s32 width;
82 
83                     /*!
84                         @brief カラーバッファの高さです。型は s32 です。
85                     */
86                     s32 height;
87 
88                     /*!
89                         @brief クリアカラーを設定します。
90                                型は f32[ 4 ] です。
91                      */
92                     f32 clearColor[ 4 ];
93 
94                 public :
95                     /*!
96                         @brief カラーバッファの設定を初期値で初期化します。
97 
98                         @param[in] frameBuffer_ フレームバッファです。
99                      */
100                     explicit ColorBuffer( const FrameBuffer& frameBuffer_ );
101 
102                     /*!
103                         @brief 設定された情報をもとに、描画コマンドを生成します。
104 
105                         @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
106 
107                         @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
108                      */
109                     bit32* MakeCommand( bit32* command ) const;
110 
111                 protected :
112                     const FrameBuffer& m_FrameBuffer;
113                 };
114 
115                 /*!
116                     @brief デプス・ステンシルバッファを設定するためのクラスです。
117                 */
118                 class DepthStencilBuffer
119                 {
120                 public :
121                     /*!
122                         @brief デプス・ステンシルバッファの仮想ドレスです。型は uptr です。
123                     */
124                     uptr  virtualAddr;
125 
126                     /*!
127                         @brief デプス・ステンシルバッファのフォーマットです。型は @ref PicaDataDepth です。
128                     */
129                     PicaDataDepth format;
130                     NN_PADDING3;
131 
132                     /*!
133                         @brief デプス・ステンシルバッファの幅です。型は s32 です。
134                     */
135                     s32 width;
136 
137                     /*!
138                         @brief デプス・ステンシルバッファの高さです。型は s32 です。
139                     */
140                     s32 height;
141 
142                     /*!
143                         @brief デプスバッファのクリアの値です。
144                                型は f32 です。
145                                初期値は 1.0f です。
146                      */
147                     f32 clearDepth;
148 
149                     /*!
150                         @brief ステンシルバッファのクリアの値です。
151                                型は u8 です。
152                                初期値は 0 です。
153                      */
154                     u8 clearStencil;
155                     NN_PADDING3;
156 
157                 public :
158                     /*!
159                         @brief デプス・ステンシルバッファを初期値で初期化します。
160 
161                         @param[in] frameBuffer_ フレームバッファです。
162                      */
163                     explicit DepthStencilBuffer( const FrameBuffer& frameBuffer_ );
164 
165                     /*!
166                         @brief 設定された情報をもとに、描画コマンドを生成します。
167 
168                         @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
169 
170                         @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
171                      */
172                     bit32* MakeCommand( bit32* command ) const;
173 
174                 protected :
175                     const FrameBuffer& m_FrameBuffer;
176                 };
177 
178             public :
179                 /*!
180                     @brief カラーバッファの設定です。
181                            型は nn::gr::CTR::FrameBuffer::ColorBuffer です。
182                  */
183                 ColorBuffer colorBuffer;
184 
185                 /*!
186                     @brief デプス・ステンシルバッファの設定です。
187                            型は nn::gr::CTR::FrameBuffer::DepthStencilBuffer です。
188                  */
189                 DepthStencilBuffer depthStencilBuffer;
190 
191                 /*!
192                     @brief フレームバッファの幅です。型は s32 です。
193                  */
194                 s32 width;
195 
196                 /*!
197                     @brief フレームバッファの高さです。型は s32 です。
198                  */
199                 s32 height;
200 
201             public :
202                 /*!
203                     @brief フレームバッファの各々の設定を、初期値で初期化します。
204 
205                     @see FrameBuffer::ColorBuffer、
206                          FrameBuffer::DepthStencilBuffer
207                  */
208                 explicit FrameBuffer();
209 
210                 /*!
211                     @brief フレームバッファのキャッシュをクリアします。
212                            描画後に、0x100-0x130 のレジスタを変更する前に呼ぶ必要があります。
213 
214                     @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
215 
216                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
217                  */
218                 static bit32* MakeClearCacheCommand( bit32* command );
219 
220                 /*!
221                     @brief 設定された情報をもとに、フレームバッファの設定コマンドを生成します。
222 
223                     @param[in] command   描画コマンドの書き込み先の先頭アドレスです。
224                     @param[in] bufferBit レンダーバッファの種類です。@ref COLOR_BUFFER_BIT | @ref DEPTH_STENCIL_BUFFER_BIT などを指定します。
225                     @param[in] isClearCache フレームバッファのキャッシュクリアのメソッド MakeClearCacheCommand() を内部で最初に呼びます。
226 
227                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
228 
229                     @see FrameBuffer::ColorBuffer、
230                          FrameBuffer::DepthStencilBuffer
231                  */
232                 bit32* MakeCommand( bit32* command, const u32 bufferBit, bool isClearCache = true ) const;
233 
234                 /*!
235                     @brief カラーバッファやデプス・ステンシルバッファをクリアするリクエストを生成します。
236                            isSplitDrawCmdlist が false の場合、
237                            リクエストの呼び出し前に nngxSplitDrawCmdlist() を呼ぶ必要があります。
238 
239                     @param[in] bufferBit             レンダーバッファの種類です。@ref COLOR_BUFFER_BIT | @ref DEPTH_STENCIL_BUFFER_BIT などを指定します。
240                     @param[in] isAddSplitDrawCmdlist リクエストの生成前に、nngxSplitDrawCmdlist() を呼びます。
241                  */
242                 void MakeClearRequest( const u32 bufferBit, bool isAddSplitDrawCmdlist = true );
243             };
244 
245         } // namespace CTR
246     } // namespace gr
247 } // namespace nn
248 
249 #endif // NN_GR_FRAME_BUFFER_H_
250