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