1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     gr_Shadow.h
4   Copyright (C)2010 Nintendo Co., Ltd.  All rights reserved.
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law. They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10   $Rev: 34909 $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 
16 #ifndef NN_GR_SHADOW_H_
17 #define NN_GR_SHADOW_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             /* Please see man pages for details
29 
30                      
31 
32              */
33             class Shadow
34             {
35             public :
36                 /* Please see man pages for details
37 
38                 */
Shadow(void)39                 Shadow( void ) :
40                 isPerspective( true ),
41                 zBias( 0.0f ),
42                 zScale( 1.0f ),
43                 penumbraScale( 0.0f ),
44                 penumbraBias( 1.0f )
45                 {
46                 }
47 
48                 /* Please see man pages for details
49 
50 
51 
52 
53 
54 
55 
56 */
57                 bit32* MakeCommand( bit32* command, bool isAddDummyCommand = true, bool isAddCacheClearCommand = true ) const
58                 {
59                     command = MakeTextureCommand( command, isAddDummyCommand );
60                     command = MakeAttenuationCommand( command, isAddCacheClearCommand );
61 
62                     return command;
63                 }
64 
65                 /* Please see man pages for details
66 
67 
68 
69 
70 
71 
72 */
73                 bit32* MakeTextureCommand( bit32* command, bool isAddDummyCommand = true ) const
74                 {
75                     // Send the dummy command to 0x080 three times
76                     if ( isAddDummyCommand )
77                     {
78                         *command++ = 0x0;
79                         *command++ = PICA_CMD_HEADER_BURST_BE( PICA_REG_TEXTURE_FUNC, 0x3, 0x0 );
80 
81                         *command++ = 0x0;
82                         *command++ = 0x0;
83                     }
84 
85                     // Clears the lowest 1 bit.
86                     bit32 clearMask = ~( 0xfffffe );
87                     u32 zBiasFix24 = Float32ToUnsignedFix24( zBias );
88                     zBiasFix24 &= clearMask;
89 
90                     // 0x8b
91                     *command++ =
92                         PICA_CMD_DATA_TEXTURE_SHADOW( isPerspective,
93                                     // f32 -> 24bit  Upper 23 bits of unsigned fixed point number
94                                     zBiasFix24,
95                                     // Converts f32 (exponent part -127) to unsigned 8-bit integer
96                                     FloatToUnsignedByte( zScale ) );
97                     *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_TEXTURE0_SHADOW );
98 
99                     return command;
100                 }
101 
102 
103                 /* Please see man pages for details
104 
105 
106 
107 
108 
109 
110                  */
111                 bit32* MakeAttenuationCommand( bit32* command, bool isAddCacheClearCommand = true ) const
112                 {
113                     // Clears the frame buffer cache.
114                     if ( isAddCacheClearCommand )
115                     {
116                         // 0x111
117                         *command++ = 0x1;
118                         *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR1 );
119 
120                         // 0x110
121                         *command++ = 0x1;
122                         *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR0 );
123 
124                     }
125 
126                     // 0x130
127                     *command++ = ( Float32ToFloat16( - penumbraScale ) ) << 16 |
128                                    Float32ToFloat16( penumbraScale + penumbraBias );
129                     *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_SHADOW );
130 
131                     return command;
132                 }
133 
134                 /* Please see man pages for details
135 
136 
137 
138                 */
139                 bool isPerspective;
140                 NN_PADDING3;
141 
142                 /* Please see man pages for details
143 
144 
145 
146 
147                 */
148                 f32 zBias;
149 
150                 /* Please see man pages for details
151 
152 
153 
154                 */
155                 f32 zScale;
156 
157                 /* Please see man pages for details
158 
159 
160 
161 
162 */
163                 f32 penumbraScale;
164 
165                 /* Please see man pages for details
166 
167 
168 
169                 */
170                 f32 penumbraBias;
171             };
172 
173         } // namespace CTR
174     } // namespace gr
175 } // namespace nn
176 
177 #endif // NN_GR_SHADOW_H_
178