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: 26253 $
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                 enum
35                 {
36                     //! 参照テーブルは256個の要素を持ちます。
37                     LOOKUP_TABLE_ELEMENT_NUM = 256
38                 };
39 
40             public :
41                 /*!
42                     @brief 参照テーブルを設定します。
43 
44                     @param[in] table 256個の参照データです。
45                  */
46                 void SetTable( const f32 table[ LOOKUP_TABLE_ELEMENT_NUM ] );
47 
48                 /*!
49                     @brief 参照テーブルをロードするコマンドを生成します。
50 
51                     @param[in] command 描画コマンドの書き込み先の先頭アドレスです。
52                     @param[in] type    参照テーブルのロード先の指定です。
53 
54                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
55                  */
56                 /*
57                     type は PICA_DATA_SAMPLER_D0、
58                             PICA_DATA_SAMPLER_D1、
59                             PICA_DATA_SAMPLER_FR、
60                             PICA_DATA_SAMPLER_FB、
61                             PICA_DATA_SAMPLER_FG、
62                             PICA_DATA_SAMPLER_RR
63                             のいずれかを指定します。
64                 */
65 
MakeCommand(u32 * command,const PicaDataFragLightSampler type)66                 u32* MakeCommand( u32* command, const PicaDataFragLightSampler type ) const
67                 {
68                     *command++ = PICA_CMD_DATA_FRAG_LIGHT_LUT( 0, type );
69                     *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_LUT );
70 
71                     std::memcpy( command, m_TableCommand, sizeof( m_TableCommand ) );
72 
73                     return command + ( LOOKUP_TABLE_ELEMENT_NUM + 4 );
74                 };
75 
76                 /*!
77                     @brief スポットライトの角度減衰で用いられる参照テーブルをロードするコマンドを生成します。
78 
79                     @param[in] command  描画コマンドの書き込み先の先頭アドレスです。
80                     @param[in] light_id スポットライト参照テーブルのロード先を、光源番号で指定します。
81 
82                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
83                  */
MakeSpotTableCommand(u32 * command,u8 light_id)84                 u32* MakeSpotTableCommand( u32* command, u8 light_id ) const
85                 {
86                     return MakeCommand( command, static_cast< PicaDataFragLightSampler >( PICA_DATA_SAMPLER_SP + light_id  ) );
87                 }
88 
89                 /*!
90                     @brief ライトの距離減衰で用いられる参照テーブルをロードするコマンドを生成します。
91 
92                     @param[in] command  描画コマンドの書き込み先の先頭アドレスです。
93                     @param[in] light_id 距離減衰参照テーブルのロード先を、光源番号で指定します。
94 
95                     @return    書き込まれた描画コマンドの終端の次のアドレスを返します。
96                  */
MakeDistAttnTableCommand(u32 * command,u8 light_id)97                 u32* MakeDistAttnTableCommand( u32* command, u8 light_id ) const
98                 {
99                     return MakeCommand( command, static_cast< PicaDataFragLightSampler >( PICA_DATA_SAMPLER_DA + light_id  ) );
100                 }
101 
102             private :
103                 /*!
104                     @brief 参照テーブルを描画コマンドの形に変換して保持します。
105                            型は u32 です。
106                            配列の上限値は nn::gr::CTR::LookUpTable::LOOKUP_TABLE_ELEMENT_NUM + 4 です。
107                 */
108                 u32 m_TableCommand[ LOOKUP_TABLE_ELEMENT_NUM + 4 ];
109             };
110 
111         } // namespace CTR
112     } // namespace gr
113 } // namespace nn
114 
115 #endif // NN_GR_LOOK_UP_TABLE_H_
116