1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     gr_Combiner.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: 37389 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_GR_COMBINER_H_
17 #define NN_GR_COMBINER_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 Combiner
32             {
33             public :
34                 /*!
35                     @brief コンバイナのステージ設定のためのクラスです。
36                  */
37                 class Stage
38                 {
39                 public :
40                     /*!
41                         @brief コンバイン関数の入出力設定をあらわす構造体です。
42                      */
43                     struct CombineFunction
44                     {
45                         /*!
46                             @brief コンバイン関数の設定です。
47                                    型は @ref PicaDataTexEnvCombine です。
48                                    値には PICA マクロヘッダの列挙型の名前が
49                                    @ref PicaDataTexEnvCombine の列挙定数を使って下さい。
50                                    初期値はPICA_DATA_TEX_ENV_COMBINE_REPLACEです。
51                         */
52                         PicaDataTexEnvCombine combine;
53 
54                         /*!
55                             @brief オペランドの設定です。
56                                    型は @ref PicaDataTexEnvOperand[] です。
57                                    値にはPICAマクロヘッダの列挙型の名前が
58                                    @ref PicaDataTexEnvOperand
59                                    の列挙定数を使って下さい。
60                                    カラーのオペランドは、デフォルトは PICA_DATA_OPE_RGB_SRC_COLOR です。
61                                    アルファのオペランドは、デフォルトは PICA_DATA_OPE_ALPHA_SRC_ALPHA です。
62                         */
63                         PicaDataTexEnvOperand operand[3];
64 
65                         /*!
66                             @brief ソース0、ソース1、ソース2の設定です。
67                                    型は @ref PicaDataTexEnvSrc です。
68                                    値にはPICAマクロヘッダの列挙型の名前が
69                                    @ref PicaDataTexEnvSrc
70                                    の列挙定数を使って下さい。
71                                    ステージ0についての設定の場合、
72                                    デフォルトはPICA_DATA_TEX_ENV_SRC_RGBA_CONSTANTです。
73                                    ステージ0以外についての設定の場合は、
74                                    デフォルトはPICA_DATA_TEX_ENV_SRC_RGBA_PREVIOUSです。
75                         */
76                         PicaDataTexEnvSrc source[3];
77 
78                         /*!
79                             @brief スケールの設定です。
80                                    型は @ref PicaDataTexEnvScale です。
81                                    値にはPICAマクロヘッダの列挙型の名前が
82                                    @ref PicaDataTexEnvScale
83                                    の列挙定数を使って下さい。
84                                    デフォルトはPICA_DATA_TEX_ENV_SCALE_1です。
85                         */
86                         PicaDataTexEnvScale scale;
87 
88                         /*!
89                             @brief コンバイナバッファのソースの設定です。
90                                    型は @ref PicaDataTexEnvBufferInput です。
91                                    値にはPICAマクロヘッダの列挙型の名前が
92                                    @ref PicaDataTexEnvBufferInput
93                                    の列挙定数を使って下さい。
94                                    デフォルトはPICA_DATA_TEX_ENV_BUFFER_INPUT_PREVIOUS_BUFFER_DMPです。
95                         */
96                         PicaDataTexEnvBufferInput bufferInput;
97 
98                         /*!
99                             @brief コンバイン関数の設定について、初期値を設定します。
100 
101                             @param[in] stage_index コンバイン関数が使われるステージのインデックスです。
102                             @param[in] is_rgb      コンバイン関数がカラーが対象であればtrue、アルファが対象であればfalseです。
103                         */
104                         explicit CombineFunction( const u8 stage_index, bool is_rgb );
105 
106                     protected :
107                         /*!
108                             @brief Stage クラスを friend に設定しています。
109                         */
110                         friend class Stage;
111 
112                         /*!
113                             @brief デフォルトコンストラクタを呼べるのは、Stageクラスのみです。
114                         */
CombineFunctionCombineFunction115                         explicit CombineFunction(){};
116                     };
117 
118                     /*!
119                         @brief カラーについてのコンバイン関数です。
120                                型は nn::gr::CTR::Combiner::Stage::CombineFunction です。
121                     */
122                     CombineFunction rgb;
123 
124                     /*!
125                         @brief アルファについてのコンバイン関数です。
126                                型は nn::gr::CTR::Combiner::Stage::CombineFunction です。
127                     */
128                     CombineFunction alpha;
129 
130                     /*!
131                         @brief コンスタントカラーの赤成分です。
132                                型は u8 です。
133                     */
134                     u8 constColorR;
135 
136                     /*!
137                         @brief コンスタントカラーの青成分です。
138                                型は u8 です。
139                     */
140                     u8 constColorG;
141 
142                     /*!
143                         @brief コンスタントカラーの緑成分です。
144                                型は u8 です。
145                     */
146                     u8 constColorB;
147 
148                     /*!
149                         @brief コンスタントカラーのアルファ成分です。
150                                型は u8 です。
151                     */
152                     u8 constColorA;
153 
154                     /*!
155                         @brief 設定するステージの先頭レジスタを設定します。
156                                型は @ref PicaReg です。
157                     */
158                     /*
159                         値は、PICA_REG_TEX_ENV0、
160                               PICA_REG_TEX_ENV1、
161                               PICA_REG_TEX_ENV2、
162                               PICA_REG_TEX_ENV3、
163                               PICA_REG_TEX_ENV4、
164                               PICA_REG_TEX_ENV5
165                               のいずれかを設定します。
166                     */
167                     PicaReg headRegister;
168 
169                 public :
170                     /*!
171                         @brief PRIMARY_COLORで置き換える設定にします。
172                     */
173                     void SetupPrimary( void );
174 
175                     /*!
176                         @brief FRAGMENT_PRIMARY_COLORで置き換える設定にします.
177                     */
178                     void SetupFragmentPrimary( void );
179 
180                     /*!
181                         @brief TEXTURE0で置き換える設定にします。
182                     */
183                     void SetupTexture0( void );
184 
185                     /*!
186                         @brief 前ステージの色でスルーする設定にします。
187                     */
188                     void SetupPrevious( void );
189 
190                     /*!
191                         @brief PRIMARY_COLORとTEXTURE0との乗算の設定にします。
192                     */
193                     void SetupPrimaryModulateTexture0( void );
194 
195                     /*!
196                         @brief FRAGMENT_PRIMARY_COLORとTEXTURE0との乗算の設定にします。
197                     */
198                     void SetupFragmentPrimaryModulateTexture0( void );
199 
200                     /*!
201                         @brief     ステージの初期値を設定します。
202 
203                         @param[in] stage_index コンバイナステージインデックスです(値は、0-5 です)
204                     */
205                     explicit Stage( const int stage_index );
206 
207                     /*!
208                         @brief 設定された情報をもとに、コンバイナステージの設定コマンドを生成します。
209                                コンバイナバッファについてのコマンドは含まれませんので、注意して下さい。
210 
211                         @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
212 
213                         @return            書き込まれた描画コマンドの終端の次のアドレスを返します。
214                         @see               Combiner::MakeCombinerBufferCommand()
215                     */
216                     bit32* MakeCommand( bit32* command ) const;
217 
218                     /*!
219                         @brief コンバイナステージのコンスタントカラーのコマンドだけ生成します。
220 
221                         @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
222 
223                         @return            書き込まれた描画コマンドの終端の次のアドレスを返します。
224                     */
MakeConstantColorCommand(bit32 * command)225                     bit32* MakeConstantColorCommand( bit32* command ) const
226                     {
227                         NN_GR_ASSERT( ( PICA_REG_TEX_ENV0 <= headRegister ) &&
228                                       ( PICA_REG_TEX_ENV5 >= headRegister ) );
229 
230                         u32 constColorReg = headRegister + 3;
231 
232                         *command++ = PICA_CMD_DATA_TEX_ENV_CONST(
233                                         constColorR, constColorG,
234                                         constColorB, constColorA );
235 
236                         *command++ = PICA_CMD_HEADER_SINGLE( constColorReg );
237 
238                         return command;
239                     }
240 
241                 protected :
242                     /*!
243                         @brief デフォルトコンストラクタを呼べるのは、Combinerクラスのみです。
244                     */
245                     friend class Combiner;
246 
247                     /*!
248                         @brief デフォルトコンストラクタを呼べるのは、Combinerクラスのみです。
249                     */
Stage(void)250                     explicit Stage( void )
251                     {
252                     };
253                 };
254 
255             public :
256                 //! コンバイナは 6 つのステージから構成されます。
257                 static const u32 COMBINER_STAGE_MAX = 6;
258 
259                 /*!
260                     @brief 各ステージのコンバイナ設定を保持します。
261                            型は nn::gr::CTR::Combiner::Stage [] で、
262                            配列のサイズは @ref COMBINER_STAGE_MAX です。
263                            各コンバイナのステージのコマンドを個別に生成したい場合は、
264                            Stage::MakeCommand() を利用して下さい。
265                 */
266                 Stage stage[ COMBINER_STAGE_MAX ];
267 
268             public :
269                 /*!
270                     @brief 先頭ステージのコンバイナバッファの出力の赤成分です。
271                            型は u8 です。
272                 */
273                 u8 bufferColorR;
274 
275                 /*!
276                      @brief 先頭ステージのコンバイナバッファの出力の緑成分です。
277                             型は u8 です。
278                  */
279                 u8 bufferColorG;
280 
281                 /*!
282                      @brief 先頭ステージのコンバイナバッファの出力の青成分です。
283                             型は u8 です。
284                  */
285                 u8 bufferColorB;
286 
287                 /*!
288                      @brief 先頭ステージのコンバイナバッファの出力のアルファ成分です。
289                             型は u8 です。
290                  */
291                 u8 bufferColorA;
292 
293                 /*!
294                      @brief 各ステージの初期値を設定します。
295                  */
296                 explicit Combiner();
297 
298                 /*!
299                     @brief 設定された情報をもとに、すべてのコンバイナステージの設定コマンドを生成します。
300                            コンバイナバッファのコマンドも同時に生成されます。
301 
302                     @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
303 
304                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
305 
306                     @see       MakeBufferInputCommand()
307                 */
308                 bit32* MakeCommand( bit32* command ) const;
309 
310 
311                 /*!
312                     @brief 設定された情報をもとに、コンバイナバッファの設定コマンドを生成します。
313 
314                     @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
315 
316                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
317                  */
318                 bit32* MakeCombinerBufferCommand( bit32* command ) const;
319             };
320 
321         } // namespace CTR
322     } // namespace gr
323 } // namespace nn
324 
325 #endif // NN_GR_COMBINER_H_
326