1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     gr_LookUpTable.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_LOOK_UP_TABLE_H_
17 #define NN_GR_LOOK_UP_TABLE_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 LookUpTable
32             {
33             public :
34                 //! 参照テーブルは256個の要素を持ちます。
35                 static const u32 LOOKUP_TABLE_ELEMENT_NUM = 256;
36 
37             public :
38                 /*!
39                     @brief 参照テーブルを設定します。
40 
41                     @param[in] table         256個の参照データです。
42                     @param[in] lastDiffValue 参照データの最後の差分値です。
43                     @param[in] isInputAbs    入力値が絶対値 [0.0, 1.0] の場合に true 、入力値が [-1.0, 1.0] のとき false にします。
44                  */
45                 void SetTable( const f32 table[ LOOKUP_TABLE_ELEMENT_NUM ],
46                                const f32 lastDiffValue = 0.0f,
47                                const bool isInputAbs   = true );
48 
49                 /*!
50                     @brief 入力値が [0.0, 1.0] の参照テーブルを設定します。
51 
52                     @param[in] table 256個の参照データです。入力値が 0.0 のものは 0 番目、入力値が 1.0 のものは 255 番目に対応させて下さい。
53                     @param[in] lastDiffValue 参照データの最後の差分値です。
54                  */
55                 void SetAbsTable( const f32 table[ LOOKUP_TABLE_ELEMENT_NUM ],
56                                   const f32 lastDiffValue = 0.0f );
57 
58                 /*!
59                     @brief 入力値が [-1.0, 1.0] の参照テーブルを設定します。
60 
61                     @param[in] table 256個の参照データです。入力値が -1.0 のものは 0 番目、入力値が 1.0 のものは 255 番目に対応させて下さい。
62                     @param[in] lastDiffValue 参照データの最後の差分値です。
63                  */
64                 void SetNotAbsTable( const f32 table[ LOOKUP_TABLE_ELEMENT_NUM ],
65                                      const f32 lastDiffValue = 0.0f );
66 
67 
68                 /*!
69                     @brief 参照テーブルをロードするコマンドを生成します。
70 
71                     @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
72                     @param[in] type    参照テーブルのロード先の指定です。
73 
74                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
75                  */
76                 /*
77                     type は PICA_DATA_SAMPLER_D0、
78                             PICA_DATA_SAMPLER_D1、
79                             PICA_DATA_SAMPLER_FR、
80                             PICA_DATA_SAMPLER_FB、
81                             PICA_DATA_SAMPLER_FG、
82                             PICA_DATA_SAMPLER_RR
83                             のいずれかを指定します。
84                 */
85 
MakeCommand(bit32 * command,const PicaDataFragLightSampler type)86                 bit32* MakeCommand( bit32* command, const PicaDataFragLightSampler type ) const
87                 {
88                     // 0x1c5
89                     *command++ = PICA_CMD_DATA_FRAG_LIGHT_LUT( 0, type );
90                     *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_LUT );
91 
92                     std::memcpy( command, m_TableCommand, sizeof( m_TableCommand ) );
93 
94                     return command + ( LOOKUP_TABLE_ELEMENT_NUM + 4 );
95                 };
96 
97                 /*!
98                     @brief スポットライトの角度減衰で用いられる参照テーブルをロードするコマンドを生成します。
99 
100                     @param[in] command  描画コマンドの書き込み先の先頭アドレスです。
101                     @param[in] light_id スポットライト参照テーブルのロード先を、光源番号で指定します。
102 
103                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
104                  */
MakeSpotTableCommand(bit32 * command,u8 light_id)105                 bit32* MakeSpotTableCommand( bit32* command, u8 light_id ) const
106                 {
107                     return MakeCommand( command, static_cast< PicaDataFragLightSampler >( PICA_DATA_SAMPLER_SP + light_id  ) );
108                 }
109 
110                 /*!
111                     @brief ライトの距離減衰で用いられる参照テーブルをロードするコマンドを生成します。
112 
113                     @param[in] command  描画コマンドの書き込み先の先頭アドレスです。
114                     @param[in] light_id 距離減衰参照テーブルのロード先を、光源番号で指定します。
115 
116                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
117                  */
MakeDistAttnTableCommand(bit32 * command,u8 light_id)118                 bit32* MakeDistAttnTableCommand( bit32* command, u8 light_id ) const
119                 {
120                     return MakeCommand( command, static_cast< PicaDataFragLightSampler >( PICA_DATA_SAMPLER_DA + light_id  ) );
121                 }
122 
123             protected :
124                 /*!
125                     @brief 参照テーブルを描画コマンドの形に変換して保持します。
126                            型は bit32 です。
127                            配列の上限値は nn::gr::CTR::LookUpTable::LOOKUP_TABLE_ELEMENT_NUM + 4 です。
128                 */
129                 bit32 m_TableCommand[ LOOKUP_TABLE_ELEMENT_NUM + 4 ];
130             };
131 
132         } // namespace CTR
133     } // namespace gr
134 } // namespace nn
135 
136 #endif // NN_GR_LOOK_UP_TABLE_H_
137