1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResFog.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_GFX_RESFOG_H_
19 #define NW_GFX_RESFOG_H_
20 
21 #include <nw/ut/ut_ResUtil.h>
22 #include <nw/ut/ut_ResDictionary.h>
23 #include <nw/gfx/res/gfx_ResLookupTable.h>
24 #include <nw/gfx/res/gfx_ResSceneObject.h>
25 #include <nw/gfx/res/gfx_ResTypeInfo.h>
26 #include <nw/gfx/res/gfx_ResRevision.h>
27 
28 namespace nw {
29 namespace gfx {
30 namespace res {
31 
32 //! @details :private
33 struct ResFogUpdaterData
34 {
35     nw::ut::ResS32 m_FogUpdaterType;
36     nw::ut::ResF32 m_MinFogDepth;
37     nw::ut::ResF32 m_MaxFogDepth;
38     nw::ut::ResF32 m_Density;
39 };
40 
41 //! @details :private
42 struct ResFogData : public ResTransformNodeData
43 {
44     enum Flag
45     {
46         FLAG_ZFLIP_ENABLED_SHIFT = ResTransformNode::FLAG_SHIFT_MAX,
47         FLAG_ATTENUATE_DISTANCE_ENABLED_SHIFT,
48         FLAG_SHIFT_MAX,
49 
50         FLAG_ZFLIP_ENABLED              = 0x1 << FLAG_ZFLIP_ENABLED_SHIFT,
51         FLAG_ATTENUATE_DISTANCE_ENABLED = 0x1 << FLAG_ATTENUATE_DISTANCE_ENABLED_SHIFT
52     };
53 
54     nw::ut::ResFloatColor m_Color;
55     nw::ut::Offset toFogSampler;
56     nw::ut::Offset toFogUpdater;
57 };
58 
59 
60 //--------------------------------------------------------------------------
61 //! @brief  フォグアップデータを表すバイナリリソースクラスです。
62 //---------------------------------------------------------------------------
63 class ResFogUpdater : public nw::ut::ResCommon<ResFogUpdaterData>
64 {
65 public:
66     //! @brief フォグアップデータの種類です。
67     enum FogUpdaterType
68     {
69         FOG_UPDATER_TYPE_NONE,              //!< 使用しません。
70         FOG_UPDATER_TYPE_LINEAR,            //!< 線形関数を利用したフォグです。
71         FOG_UPDATER_TYPE_EXPONENT,          //!< 指数関数を利用したフォグです。
72         FOG_UPDATER_TYPE_EXPONENT_SQUARE    //!< 二乗の指数関数を利用したフォグです。
73     };
74 
75     NW_RES_CTOR( ResFogUpdater )
76 
77     //---------------------------------------------------------------------------
78     //! @fn           void SetMinFogDepth(f32 value)
79     //! @brief        フォグがかかり始める視点座標系におけるデプス値を設定します。
80     //---------------------------------------------------------------------------
81     //---------------------------------------------------------------------------
82     //! @fn           void SetMaxFogDepth(f32 value)
83     //! @brief        フォグ濃度が最大になる視点座標系におけるデプス値を設定します。
84     //---------------------------------------------------------------------------
85     //---------------------------------------------------------------------------
86     //! @fn           void SetFogUpdaterType(FogUpdaterType value)
87     //! @brief        フォグアップデータのタイプを設定します。
88     //---------------------------------------------------------------------------
89     //---------------------------------------------------------------------------
90     //! @fn           void SetDensity(f32 value)
91     //! @brief        フォグの濃度を調整するパラメータを設定します。
92     //---------------------------------------------------------------------------
93     //---------------------------------------------------------------------------
94     //! @fn           f32 GetMinFogDepth() const
95     //! @brief        フォグがかかり始める視点座標系におけるデプス値を取得します。
96     //---------------------------------------------------------------------------
97     //---------------------------------------------------------------------------
98     //! @fn           f32 GetMaxFogDepth() const
99     //! @brief        フォグ濃度が最大になる視点座標系におけるデプス値を取得します。
100     //---------------------------------------------------------------------------
101     //---------------------------------------------------------------------------
102     //! @fn           FogUpdaterType GetFogUpdaterType() const
103     //! @brief        フォグアップデータのタイプを取得します。
104     //---------------------------------------------------------------------------
105     //---------------------------------------------------------------------------
106     //! @fn           f32 GetDensity() const
107     //! @brief        フォグの濃度を調整するパラメータを取得します。
108     //---------------------------------------------------------------------------
109     NW_RES_FIELD_PRIMITIVE_DECL( FogUpdaterType, FogUpdaterType )
110     NW_RES_FIELD_PRIMITIVE_DECL( f32, MinFogDepth )
111     NW_RES_FIELD_PRIMITIVE_DECL( f32, MaxFogDepth )
112     NW_RES_FIELD_PRIMITIVE_DECL( f32, Density )
113 };
114 
115 //--------------------------------------------------------------------------
116 //! @brief  フォグを表すバイナリリソースクラスです。
117 //---------------------------------------------------------------------------
118 class ResFog : public ResTransformNode
119 {
120 public:
121     enum { BINARY_REVISION = REVISION_RES_FOG };
122     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResFog) };
123     enum { SIGNATURE = NW_RES_SIGNATURE32('CFOG') };
124 
NW_RES_CTOR_INHERIT(ResFog,ResTransformNode)125     NW_RES_CTOR_INHERIT( ResFog, ResTransformNode )
126 
127 
128     //---------------------------------------------------------------------------
129     //! @fn           void SetColor(f32 r, f32 g, f32 b)
130     //! @brief        フォグカラーを設定します。
131     //---------------------------------------------------------------------------
132     //---------------------------------------------------------------------------
133     //! @fn           const nw::ut::FloatColor & GetColor() const
134     //! @brief        フォグカラーを取得します。
135     //---------------------------------------------------------------------------
136     NW_RES_FIELD_FLOAT_COLOR_DECL( nw::ut::FloatColor, Color )   // FloatColor& GetColor()
137 
138     //---------------------------------------------------------------------------
139     //! @fn           ResImageLookupTable GetFogSampler()
140     //! @brief        フォグの参照テーブルを取得します。
141     //---------------------------------------------------------------------------
142     NW_RES_FIELD_CLASS_DECL( ResImageLookupTable, FogSampler )  // GetFogSampler()
143 
144     //---------------------------------------------------------------------------
145     //! @fn           ResFogUpdater GetFogUpdater()
146     //! @brief        フォグアップデータを取得します。
147     //---------------------------------------------------------------------------
148     NW_RES_FIELD_CLASS_DECL( ResFogUpdater, FogUpdater )    // GetFogUpdater
149 
150     //---------------------------------------------------------------------------
151     //! @brief        リビジョンを取得します。
152     //!
153     //! @return       リソースのリビジョン情報です。
154     //---------------------------------------------------------------------------
155     u32 GetRevision() const { return this->GetHeader().revision; }
156 
157     //---------------------------------------------------------------------------
158     //! @brief        Zフリップフラグを取得します。
159     //!
160     //! @return       Zフリップフラグの値です。
161     //---------------------------------------------------------------------------
IsZFlip()162     bool    IsZFlip() const
163         { return (ref().m_Flags & ResFogData::FLAG_ZFLIP_ENABLED) != 0; }
164 
165     //---------------------------------------------------------------------------
166     //! @brief        Zフリップフラグを取得します。
167     //!
168     //! @return       Zフリップフラグの値です。
169     //---------------------------------------------------------------------------
IsAttenuateDistance()170     bool    IsAttenuateDistance() const
171         { return (ref().m_Flags & ResFogData::FLAG_ATTENUATE_DISTANCE_ENABLED) != 0; }
172 
173     //---------------------------------------------------------------------------
174     //! @brief        リソースのセットアップをおこないます。
175     //!
176     //! @param[in]    allocator アロケータです。
177     //! @param[in]    graphicsFile グラフィックスリソースです。
178     //---------------------------------------------------------------------------
179     Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile);
180 
181     //---------------------------------------------------------------------------
182     //! @brief        リソースの後始末をおこないます。
183     //---------------------------------------------------------------------------
184     void Cleanup();
185 };
186 
187 typedef nw::ut::ResArrayPatricia<ResFog>::type  ResFogArray;
188 
189 } // namespace res
190 } // namespace gfx
191 } // namespace nw
192 
193 #endif // NW_GFX_RESFOG_H_
194