1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResLookupTable.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_RESLOOKUPTABLE_H_
17 #define NW_GFX_RESLOOKUPTABLE_H_
18 
19 #include <GLES2/gl2.h>
20 #include <GLES2/gl2ext.h>
21 
22 #include <nw/ut/ut_Color.h>
23 #include <nw/ut/ut_ResUtil.h>
24 #include <nw/ut/ut_ResDictionary.h>
25 #include <nw/gfx/res/gfx_ResSceneObject.h>
26 #include <nw/gfx/res/gfx_ResTypeInfo.h>
27 #include <nw/gfx/res/gfx_ResRevision.h>
28 
29 namespace nw {
30 namespace gfx {
31 namespace res {
32 
33 //! @details :private
34 struct ResLookupTableData
35 {
36     nw::ut::ResTypeInfo typeInfo;
37 };
38 
39 //! @details :private
40 //
41 // CommandCacheTable のコマンドフォーマットは次の通りです。
42 // 0 : LUT設定レジスタ(0x1c8, 0x132) などの 0 番目の設定値 [0:11]value, [23:12]diff。
43 // 1 : レジスタへの書き込みヘッダ。
44 // 2~ : LUTサイズ分の LUT設定。
45 struct ResImageLookupTableData : public ResLookupTableData
46 {
47     nw::ut::BinString toName;
48     nw::ut::ResBool m_IsAbs;
49     u8              _padding_0[3];
50     nw::ut::ResS32 m_CommandCacheTableCount;
51     nw::ut::Offset toCommandCacheTable;
52 };
53 
54 //! @details :private
55 struct ResReferenceLookupTableData : public ResLookupTableData
56 {
57     nw::ut::BinString toPath;
58     nw::ut::BinString toTableName;
59     nw::ut::Offset toTargetLut;
60 };
61 
62 class ResImageLookupTable;
63 
64 //--------------------------------------------------------------------------
65 //! @brief  参照テーブルを表すバイナリリソースのベースクラスです。
66 //---------------------------------------------------------------------------
67 class ResLookupTable : public nw::ut::ResCommon<ResLookupTableData>
68 {
69 public:
70     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResLookupTable) };
71 
NW_RES_CTOR(ResLookupTable)72     NW_RES_CTOR( ResLookupTable )
73 
74     //---------------------------------------------------------------------------
75     //! @brief        インスタンスの型情報を取得します。
76     //!
77     //! @return       型情報です。
78     //---------------------------------------------------------------------------
79     nw::ut::ResTypeInfo GetTypeInfo() const { return ref().typeInfo; }
80 
81     //---------------------------------------------------------------------------
82     //! @brief        参照を解決した、ResImageLookupTable のインスタンスを取得します。
83     //!
84     //! @return       ResImageLookupTable のインスタンスです。
85     //---------------------------------------------------------------------------
86     NW_INLINE ResImageLookupTable        Dereference();
87     NW_INLINE const ResImageLookupTable  Dereference() const;
88 
89     //---------------------------------------------------------------------------
90     //! @brief        リソースの初期化処理をおこないます。
91     //---------------------------------------------------------------------------
92     Result Setup();
93 
94     //---------------------------------------------------------------------------
95     //! @brief        リソースの後始末をおこないます。
96     //---------------------------------------------------------------------------
97     void Cleanup();
98 };
99 
100 //--------------------------------------------------------------------------
101 //! @brief  参照テーブルを表すバイナリリソースクラスです。
102 //---------------------------------------------------------------------------
103 class ResImageLookupTable : public ResLookupTable
104 {
105 public:
106     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResImageLookupTable) };
107     enum { SIGNATURE = NW_RES_SIGNATURE32('ILUT') };
108 
109     NW_RES_CTOR_INHERIT( ResImageLookupTable, ResLookupTable )
110 
111     //---------------------------------------------------------------------------
112     //! @fn           void SetCommandCache(int idx, u32 value)
113     //! @brief        コマンドキャッシュのリストに要素を設定します。
114     //---------------------------------------------------------------------------
115     //---------------------------------------------------------------------------
116     //! @fn           void SetAbs(bool value)
117     //! @brief        テーブルへアクセスするための入力値の絶対値化フラグを設定します。
118     //---------------------------------------------------------------------------
119     //---------------------------------------------------------------------------
120     //! @fn           bool IsAbs() const
121     //! @brief        テーブルへアクセスするための入力値の絶対値化フラグを取得します。
122     //---------------------------------------------------------------------------
123     //---------------------------------------------------------------------------
124     //! @fn           const char * GetName() const
125     //! @brief        テーブル名を取得します。
126     //---------------------------------------------------------------------------
127     //---------------------------------------------------------------------------
128     //! @fn           s32 GetCommandCacheCount() const
129     //! @brief        コマンドキャッシュの要素数を取得します。
130     //---------------------------------------------------------------------------
131     //---------------------------------------------------------------------------
132     //! @fn           u32 GetCommandCache(int idx) const
133     //! @brief        コマンドキャッシュを取得します。
134     //---------------------------------------------------------------------------
135     NW_RES_FIELD_STRING_DECL( Name )                    // GetName()
136     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Abs )             // IsAbs(), SetAbs()
137 
138     NW_RES_FIELD_PRIMITIVE_LIST_DECL( u32, CommandCache ) // GetCommandCache(), GetCommandCacheCount(), GetCommandCache(int idx)
139 };
140 
141 //--------------------------------------------------------------------------
142 //! @brief  参照テーブルへのリファレンス表すバイナリリソースクラスです。
143 //---------------------------------------------------------------------------
144 class ResReferenceLookupTable : public ResLookupTable
145 {
146 public:
147     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResReferenceLookupTable) };
148     enum { SIGNATURE = NW_RES_SIGNATURE32('RLUT') };
149 
150     NW_RES_CTOR_INHERIT( ResReferenceLookupTable, ResLookupTable )
151 
152     //---------------------------------------------------------------------------
153     //! @fn           ResImageLookupTable GetTargetLut()
154     //! @brief        参照解決済みのルックアップテーブルを取得します。
155     //---------------------------------------------------------------------------
156     //---------------------------------------------------------------------------
157     //! @fn           const char * GetTableName() const
158     //! @brief        参照先ルックアップテーブルの名前を取得します。
159     //---------------------------------------------------------------------------
160     //---------------------------------------------------------------------------
161     //! @fn           const char * GetPath() const
162     //! @brief        参照先ルックアップテーブルセットのパス名を取得します。
163     //---------------------------------------------------------------------------
164     NW_RES_FIELD_STRING_DECL( Path )        // GetPath()
165     NW_RES_FIELD_STRING_DECL( TableName )   // GetTableName()
166     NW_RES_FIELD_CLASS_DECL( ResImageLookupTable, TargetLut ) // GetTargetLut()
167 };
168 
169 
170 //! @details :private
171 struct ResLookupTableSetData : public ResSceneObjectData
172 {
173     nw::ut::ResS32 m_SamplersDicCount;
174     nw::ut::Offset toSamplersDic;
175 };
176 
177 //--------------------------------------------------------------------------
178 //! @brief  参照テーブルセットを表すバイナリリソースクラスです。
179 //---------------------------------------------------------------------------
180 class ResLookupTableSet : public ResSceneObject
181 {
182 public:
183     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResLookupTableSet) };
184     enum { SIGNATURE = NW_RES_SIGNATURE32('LUTS') };
185     enum { BINARY_REVISION = REVISION_RES_LUT_SET };
186 
187     NW_RES_CTOR_INHERIT( ResLookupTableSet, ResSceneObject )
188 
189     //---------------------------------------------------------------------------
190     //! @fn           s32 GetSamplersIndex(const char * key) const
191     //! @brief        参照テーブルセットの辞書データ中でのインデックス番号を取得します。
192     //---------------------------------------------------------------------------
193     //---------------------------------------------------------------------------
194     //! @fn           s32 GetSamplersCount() const
195     //! @brief        参照テーブルセットの要素数を取得します。
196     //---------------------------------------------------------------------------
197     //---------------------------------------------------------------------------
198     //! @fn           ResImageLookupTable GetSamplers(int idx)
199     //! @brief        参照テーブルセットを取得します。
200     //---------------------------------------------------------------------------
201     NW_RES_FIELD_CLASS_DIC_DECL( ResImageLookupTable, Samplers, nw::ut::ResDicPatricia )
202 
203     //---------------------------------------------------------------------------
204     //! @brief        リソースの初期化処理をおこないます。
205     //!
206     //! @param[in]    allocator アロケータです。
207     //! @param[in]    graphicsFile グラフィックスリソースです。
208     //---------------------------------------------------------------------------
209     Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile);
210 
211     //---------------------------------------------------------------------------
212     //! @brief        リソースの後始末をおこないます。
213     //---------------------------------------------------------------------------
214     void Cleanup();
215 
216     //---------------------------------------------------------------------------
217     //! @brief        リビジョンを取得します。
218     //!
219     //! @return       リソースのリビジョン情報です。
220     //---------------------------------------------------------------------------
GetRevision()221     u32 GetRevision() const { return this->GetHeader().revision; }
222 };
223 
224 //----------------------------------------
225 NW_INLINE ResImageLookupTable
Dereference()226 ResLookupTable::Dereference()
227 {
228     NW_ASSERT( this->IsValid() );
229 
230     switch ( this->ref().typeInfo )
231     {
232     case ResImageLookupTable::TYPE_INFO:
233         {
234             return ResStaticCast<ResImageLookupTable>(*this);
235         }
236     case ResReferenceLookupTable::TYPE_INFO:
237         {
238             ResReferenceLookupTable resRefLut = ResStaticCast<ResReferenceLookupTable>( *this );
239 
240             NW_ASSERT( resRefLut.GetTargetLut().IsValid() );
241             return resRefLut.GetTargetLut();
242         }
243     default:
244         {
245             NW_FATAL_ERROR("Unsupported lut type.");
246             return ResImageLookupTable();
247         }
248     }
249 }
250 
251 
252 //----------------------------------------
253 NW_INLINE const ResImageLookupTable
Dereference()254 ResLookupTable::Dereference() const
255 {
256     NW_ASSERT( this->IsValid() );
257 
258     switch ( this->ref().typeInfo )
259     {
260     case ResImageLookupTable::TYPE_INFO:
261         {
262             return ResStaticCast<ResImageLookupTable>(*this);
263         }
264     case ResReferenceLookupTable::TYPE_INFO:
265         {
266             ResReferenceLookupTable resRefLut = ResStaticCast<ResReferenceLookupTable>( *this );
267 
268             NW_ASSERT( resRefLut.GetTargetLut().IsValid() );
269             return resRefLut.GetTargetLut();
270         }
271     default:
272         {
273             NW_FATAL_ERROR("Unsupported lut type.");
274             return ResImageLookupTable();
275         }
276     }
277 }
278 
279 } // namespace res
280 } // namespace gfx
281 } // namespace nw
282 
283 #endif // NW_GFX_RESLOOKUPTABLE_H_
284