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