1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: gr_Fog.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_FRAGMENT_FOG_H_ 17 #define NN_GR_FRAGMENT_FOG_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 Fog 32 { 33 public : 34 //! フォグ参照テーブルは128個の要素を持ちます。 35 static const u32 FOG_LOOKUP_TABLE_ELEMENT_NUM = 128; 36 37 public : 38 /*! 39 @brief フォグを有効にする場合はtrueを設定します。 40 型は bool です。 41 */ 42 bool isEnable; 43 44 /*! 45 @brief Zフリップモードの有効化/無効化の設定です。 46 型は bool です。 47 */ 48 bool isEnableZFlip; 49 50 /*! 51 @brief フォグカラーの赤成分です。 52 型は u8 です。 53 */ 54 u8 colorR; 55 56 /*! 57 @brief フォグカラーの緑成分です。 58 型は u8 です。 59 */ 60 u8 colorG; 61 62 /*! 63 @brief フォグカラーの青成分です。 64 型は u8 です。 65 */ 66 u8 colorB; 67 NN_PADDING3; 68 69 public : 70 /*! 71 @brief フォグ参照テーブルを設定します。 72 73 @param[in] table 128個の参照データです。 74 @param[in] lastDiffValue 参照データの最後の差分値です。 75 */ 76 void SetTable( const f32 table[ FOG_LOOKUP_TABLE_ELEMENT_NUM ], 77 const f32 lastDiffValue = 0.0f ); 78 79 /*! 80 @brief フォグを設定するコマンドを生成します。 81 82 @param[in] command 描画コマンドの書き込み先の先頭アドレスです。 83 84 @return 書き込まれた描画コマンドの終端の次のアドレスを返します。 85 */ MakeAllCommand(bit32 * command)86 bit32* MakeAllCommand( bit32* command ) const 87 { 88 // 設定用コマンド 89 command = MakeConfigCommand( command ); 90 91 // フォグの参照テーブルコマンド 92 if ( isEnable ) 93 { 94 command = MakeTableCommand( command ); 95 } 96 return command; 97 } 98 99 100 /*! 101 @brief フォグを無効化する最低限のコマンドを生成します。 102 103 @param[in] command 描画コマンドの書き込み先の先頭アドレスです。 104 105 @return 書き込まれた描画コマンドの終端の次のアドレスを返します。 106 */ MakeDisableCommand(bit32 * command)107 static bit32* MakeDisableCommand( bit32* command ) 108 { 109 // 0x0e0 110 *command++ = PICA_DATA_FOG_FALSE; 111 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_GAS_FOG_MODE, 0x1 ); 112 113 return command; 114 } 115 116 /*! 117 @brief フォグを設定するコマンドを生成します。 118 119 @param[in] command 描画コマンドの書き込み先の先頭アドレスです。 120 121 @return 書き込まれた描画コマンドの終端の次のアドレスを返します。 122 */ MakeConfigCommand(bit32 * command)123 bit32* MakeConfigCommand( bit32* command ) const 124 { 125 // 0x0e0 126 *command++ = ( isEnable ? PICA_DATA_FOG : PICA_DATA_FOG_FALSE ) | ( ( isEnableZFlip ? 1 : 0 ) << 16 ); 127 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_GAS_FOG_MODE, 0x5 ); 128 129 // 0x0e1 130 *command++ = colorR | colorG << 8 | colorB << 16; 131 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FOG_COLOR ); 132 133 return command; 134 } 135 136 /*! 137 @brief フォグを設定するコマンドを生成します。 138 139 @param[in] command 描画コマンドの書き込み先の先頭アドレスです。 140 141 @return 書き込まれた描画コマンドの終端の次のアドレスを返します。 142 */ MakeTableCommand(bit32 * command)143 bit32* MakeTableCommand( bit32* command ) const 144 { 145 std::memcpy( command, m_TableCommand, sizeof( m_TableCommand ) ); 146 return command + ( FOG_LOOKUP_TABLE_ELEMENT_NUM + 4 ); 147 } 148 149 public : 150 /*! 151 @brief フォグを設定するコマンドを生成します。 152 */ Fog()153 Fog() : 154 isEnable( false ), 155 isEnableZFlip( false ), 156 colorR( 0 ), 157 colorG( 0 ), 158 colorB( 0 ) 159 { 160 } 161 162 protected : 163 /*! 164 @brief 参照テーブルを描画コマンドの形に変換して保持します。 165 型は u32[] です。 166 */ 167 u32 m_TableCommand[ FOG_LOOKUP_TABLE_ELEMENT_NUM + 4 ]; 168 }; 169 170 } // namespace CTR 171 } // namespace gr 172 } //namespace nn 173 174 #endif // NN_GR_FRAGMENT_FOG_H_ 175