1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     gr_Scissor.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: 33735 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_GR_SCISSOR_H_
17 #define NN_GR_SCISSOR_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 シザー関連のコマンドを生成するためのクラスです。glScissorと異なり、描画対象のカラーバッファサイズを与える必要があります。
30             */
31             class Scissor
32             {
33             public:
34                 /*!
35                     @brief コンストラクタです。初期値(シザー有効、シザー範囲 (0,0)-(240,320)、 バッファサイズ(256,320))を設定します.
36                  */
Scissor()37                 Scissor():
38                 isEnable( true ),
39                 x( 0 ),
40                 y( 0 ),
41                 width( 240 ),
42                 height( 320 ),
43                 bufferWidth( 256 ),
44                 bufferHeight( 320 )
45                 {
46                 }
47 
48                 /*!
49                     @brief コンストラクタです。値を指定して初期化します。
50 
51                     @param[in]  isEnable_     シザーを有効にするか。
52                     @param[in]  x_            シザー範囲の左下の X の値です。
53                     @param[in]  y_            シザー範囲の左下の Y の値です。
54                     @param[in]  width_        シザー範囲の幅です。
55                     @param[in]  height_       シザー範囲の高さです。
56                     @param[in]  bufferWidth_  カラーバッファの幅です。
57                     @param[in]  bufferHeight_ カラーバッファの高さです。
58                 */
Scissor(bool isEnable_,s32 x_,s32 y_,u32 width_,u32 height_,s32 bufferWidth_,s32 bufferHeight_)59                 Scissor( bool isEnable_, s32 x_, s32 y_, u32 width_, u32 height_, s32 bufferWidth_, s32 bufferHeight_ ) :
60                 isEnable( isEnable_ ),
61                 x( x_ ),
62                 y( y_ ),
63                 width( width_ ),
64                 height( height_ ),
65                 bufferWidth( bufferWidth_ ),
66                 bufferHeight( bufferHeight_ )
67                 {
68                 }
69 
70             public:
71                 /*!
72                     @brief 設定された情報をもとに、描画コマンドを生成します。
73 
74                     @param[in]    command  描画コマンド書き込み先の先頭アドレスです。
75 
76                     @return                書き込まれた描画コマンドの終端の次のアドレスを返します。
77                  */
78                 bit32* MakeCommand( bit32* command ) const;
79 
80                 /*!
81                     @brief シザーを無効化するコマンドを生成します。
82 
83                     @param[in]  command            描画コマンド書き込み先の先頭アドレスです。
84                     @param[in]  colorBufferWidth   カラーバッファの幅です。
85                     @param[in]  colorBufferHeight  カラーバッファの高さです。
86 
87                     @return                 書き込まれた描画コマンドの終端の次のアドレスを返します。
88                  */
MakeDisableCommand(bit32 * command,const s32 colorBufferWidth,const s32 colorBufferHeight)89                 static bit32* MakeDisableCommand( bit32* command,
90                     const s32 colorBufferWidth,
91                     const s32 colorBufferHeight )
92                 {
93                     s32 temp_width  = colorBufferWidth  - 1;
94                     s32 temp_height = colorBufferHeight - 1;
95 
96                     // 0x65-0x67
97                     *command++ = PICA_CMD_DATA_SCISSOR( false );
98                     *command++ = PICA_CMD_HEADER_BURSTSEQ( PICA_REG_SCISSOR, 3 );
99                     *command++ = 0;
100                     *command++ = PICA_CMD_DATA_SCISSOR_SIZE( temp_width, temp_height );
101 
102                     return command;
103                 }
104 
105             public:
106                 /*!
107                     @brief シザー範囲を一括で指定する便利関数です。
108 
109                     @param[in]    x_            シザー範囲の左下の X の値です。
110                     @param[in]    y_            シザー範囲の左下の Y の値です。
111                     @param[in]    width_        シザー範囲の幅です。
112                     @param[in]    height_       シザー範囲の高さです。
113                  */
Set(s32 x_,s32 y_,u32 width_,u32 height_)114                 void Set( s32 x_, s32 y_, u32 width_, u32 height_ )
115                 {
116                     x = x_; y = y_; width = width_; height = height_;
117                 }
118 
119                 /*!
120                     @brief バッファサイズを一括で指定する便利関数です。
121 
122                     @param[in]    bufferWidth_  カラーバッファの幅です。
123                     @param[in]    bufferHeight_ カラーバッファの高さです。
124                  */
SetBufferSize(s32 bufferWidth_,s32 bufferHeight_)125                 void SetBufferSize( s32 bufferWidth_, s32 bufferHeight_ )
126                 {
127                     bufferWidth = bufferWidth_; bufferHeight = bufferHeight_;
128                 }
129 
130             public:
131                 /*!
132                     @brief シザーを有効にするか。 型は bool です。
133                 */
134                 bool    isEnable;
135                 NN_PADDING3;
136 
137                 /*!
138                     @brief シザー範囲の左下の X の値です。 型は s32 です。
139                 */
140                 s32        x;
141 
142                 /*!
143                     @brief シザー範囲の左下の Y の値です。型は s32 です。
144                 */
145                 s32        y;
146 
147                 /*!
148                     @brief シザー範囲の幅です。型は u32 です。
149                 */
150                 u32        width;
151 
152                 /*!
153                     @brief シザー範囲の高さです。型は u32 です。
154                 */
155                 u32        height;
156 
157                 /*!
158                     @brief シザー範囲のカラーバッファの幅です。型は s32 です。
159                 */
160                 s32        bufferWidth;
161 
162                 /*!
163                     @brief シザー範囲のカラーバッファの幅です。型は s32 です。
164                 */
165                 s32        bufferHeight;
166             };
167 
168         } // namespace CTR
169     } // namespace gr
170 } // namespace nn
171 
172 #endif // NN_GR_SCISSOR_H_
173