1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResGraphicsFile.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_RESGRAPHICSFILE_H_
19 #define NW_GFX_RESGRAPHICSFILE_H_
20 
21 #include <nw/ut/ut_ResUtil.h>
22 #include <nw/ut/ut_ResDictionary.h>
23 #include <nw/gfx/gfx_Common.h>
24 #include <nw/gfx/res/gfx_ResRevision.h>
25 #include <nw/gfx/res/gfx_ResModel.h>
26 #include <nw/gfx/res/gfx_ResSceneObject.h>
27 #include <nw/gfx/res/gfx_ResShape.h>
28 #include <nw/gfx/res/gfx_ResMaterial.h>
29 #include <nw/gfx/res/gfx_ResParticleEmitter.h>
30 #include <nw/gfx/res/gfx_ResParticleModel.h>
31 #include <nw/gfx/res/gfx_ResCamera.h>
32 #include <nw/gfx/res/gfx_ResLight.h>
33 #include <nw/gfx/res/gfx_ResFog.h>
34 #include <nw/gfx/res/gfx_ResSceneEnvironmentSetting.h>
35 #include <nw/anim/res/anim_ResAnim.h>
36 
37 namespace nw {
38 namespace gfx {
39 namespace res {
40 
41 //! @details :private
42 struct ResFileHeaderData
43 {
44     nw::ut::ResU32  m_Signature;
45     nw::ut::ResU16  m_ByteOrder;
46     nw::ut::ResU16  m_HeaderSize;
47     nw::ut::ResU32  m_Revision;
48     nw::ut::ResU32  m_FileSize;
49     nw::ut::ResU16  m_NumBlocks;
50     u8              padding_[2];
51     nw::ut::BinaryBlockHeader m_BlockHeader;
52 };
53 
54 
55 //! @details :private
56 struct ResGraphicsFileData : public ResFileHeaderData
57 {
58     nw::ut::ResS32 m_ModelsDicCount;
59     nw::ut::Offset toModelsDic;
60     nw::ut::ResS32 m_TexturesDicCount;
61     nw::ut::Offset toTexturesDic;
62     nw::ut::ResS32 m_LutSetsDicCount;
63     nw::ut::Offset toLutSetsDic;
64     nw::ut::ResS32 m_MaterialsDicCount;
65     nw::ut::Offset toMaterialsDic;
66     nw::ut::ResS32 m_ShadersDicCount;
67     nw::ut::Offset toShadersDic;
68     nw::ut::ResS32 m_CamerasDicCount;
69     nw::ut::Offset toCamerasDic;
70     nw::ut::ResS32 m_LightsDicCount;
71     nw::ut::Offset toLightsDic;
72     nw::ut::ResS32 m_FogsDicCount;
73     nw::ut::Offset toFogsDic;
74     nw::ut::ResS32 m_SceneEnvironmentSettingsDicCount;
75     nw::ut::Offset toSceneEnvironmentSettingsDic;
76     nw::ut::ResS32 m_SkeletalAnimsDicCount;
77     nw::ut::Offset toSkeletalAnimsDic;
78     nw::ut::ResS32 m_MaterialAnimsDicCount;
79     nw::ut::Offset toMaterialAnimsDic;
80     nw::ut::ResS32 m_VisibilityAnimsDicCount;
81     nw::ut::Offset toVisibilityAnimsDic;
82     nw::ut::ResS32 m_CameraAnimsDicCount;
83     nw::ut::Offset toCameraAnimsDic;
84     nw::ut::ResS32 m_LightAnimsDicCount;
85     nw::ut::Offset toLightAnimsDic;
86     nw::ut::ResS32 m_FogAnimsDicCount;
87     nw::ut::Offset toFogAnimsDic;
88     nw::ut::ResS32 m_EmittersDicCount;
89     nw::ut::Offset toEmittersDic;
90 };
91 
92 
93 //--------------------------------------------------------------------------
94 //! @brief  グラフィックス用のファイルヘッダを表すバイナリリソースクラスです。
95 //---------------------------------------------------------------------------
96 class ResFileHeader : public nw::ut::ResCommon< ResFileHeaderData >
97 {
98 public:
NW_RES_CTOR(ResFileHeader)99     NW_RES_CTOR( ResFileHeader )
100 
101     //---------------------------------------------------------------------------
102     //! @fn           u32 GetSignature() const
103     //! @brief        シグニチャを取得します。
104     //---------------------------------------------------------------------------
105     //---------------------------------------------------------------------------
106     //! @fn           void SetSignature(u32 value)
107     //! @brief        シグニチャを設定します。
108     //---------------------------------------------------------------------------
109     NW_RES_FIELD_PRIMITIVE_DECL( u32, Signature )    // GetSignature(), SetSignature()
110 
111     //---------------------------------------------------------------------------
112     //! @fn           u16 GetByteOrder() const
113     //! @brief        バイトオーダーを取得します。
114     //---------------------------------------------------------------------------
115     //---------------------------------------------------------------------------
116     //! @fn           void SetByteOrder(u16 value)
117     //! @brief        バイトオーダーを設定します。
118     //---------------------------------------------------------------------------
119     NW_RES_FIELD_PRIMITIVE_DECL( u16, ByteOrder )    // GetByteOrder(), SetByteOrder()
120 
121     //---------------------------------------------------------------------------
122     //! @fn           u16 GetHeaderSize() const
123     //! @brief        ヘッダーサイズを取得します。
124     //---------------------------------------------------------------------------
125     //---------------------------------------------------------------------------
126     //! @fn           void SetHeaderSize(u16 value)
127     //! @brief        ヘッダーサイズを設定します。
128     //---------------------------------------------------------------------------
129     NW_RES_FIELD_PRIMITIVE_DECL( u16, HeaderSize )   // GetHeaderSize(), SetHeaderSize()
130 
131     //---------------------------------------------------------------------------
132     //! @fn           u32 GetRevision() const
133     //! @brief        リビジョン情報を取得します。
134     //---------------------------------------------------------------------------
135     //---------------------------------------------------------------------------
136     //! @fn           void SetRevision(u32 value)
137     //! @brief        リビジョン情報を設定します。
138     //---------------------------------------------------------------------------
139     NW_RES_FIELD_PRIMITIVE_DECL( u32, Revision )     // GetRevision(), SetRevision()
140 
141     //---------------------------------------------------------------------------
142     //! @fn           u32 GetFileSize() const
143     //! @brief        ファイルサイズを取得します。
144     //---------------------------------------------------------------------------
145     //---------------------------------------------------------------------------
146     //! @fn           void SetFileSize(u32 value)
147     //! @brief        ファイルサイズを設定します。
148     //---------------------------------------------------------------------------
149     NW_RES_FIELD_PRIMITIVE_DECL( u32, FileSize )     // GetFileSize(), SetFileSize()
150 
151     //---------------------------------------------------------------------------
152     //! @fn           u16 GetNumBlocks() const
153     //! @brief        ブロック数を取得します。
154     //---------------------------------------------------------------------------
155     //---------------------------------------------------------------------------
156     //! @fn           void SetNumBlocks(u16 value)
157     //! @brief        ブロック数を設定します。
158     //---------------------------------------------------------------------------
159     NW_RES_FIELD_PRIMITIVE_DECL( u16, NumBlocks )    // GetNumBlocks(), SetNumBlocks()
160 
161 
162     //---------------------------------------------------------------------------
163     //! @brief        バイナリのファイルヘッダを取得します。
164     //!
165     //! @return       バイナリのファイルヘッダへの参照です。
166     //---------------------------------------------------------------------------
167     const nw::ut::BinaryFileHeader& GetFileHeader() const
168     {
169         return *reinterpret_cast<const nw::ut::BinaryFileHeader*>( this->ptr() );
170     }
171 
172     //---------------------------------------------------------------------------
173     //! @brief        バイナリのブロック情報を取得します。
174     //!
175     //! @details  ResGraphicsFile には kind が "DATA" となっている通常ブロックと "IMAG"
176     //!           となっているテクスチャ、頂点イメージブロックの2種類のブロックが存在します。
177     //!           nw::ut::GetNextBinaryBlockHeader 関数を使用してイメージブロックを取得して、
178     //!           まとめて VRAM に転送することで、イメージデータの VRAMへの転送コストを抑える事が可能です。
179     //!           この場合、アプリケーション側でまとめて転送した VRAM のアドレスと
180     //!           各リソース上のイメージデータのアドレス情報を元に、それぞれの VRAM アドレスを計算し、
181     //!           ResImageTexture や ResVertexStream, ResIndexStream にある SetLocationAddress 関数を
182     //!           使用して Setup 前に設定してください。
183     //!
184     //! @return       バイナリのブロック情報への参照です。
185     //---------------------------------------------------------------------------
GetFirstBlockHeader()186     const nw::ut::BinaryBlockHeader& GetFirstBlockHeader() const
187     {
188         return ref().m_BlockHeader;
189     }
190 
191     //---------------------------------------------------------------------------
192     //! @brief        イメージデータブロックの先頭のデータアドレスを取得します。
193     //!
194     //! @return       イメージデータブロックの先頭のデータアドレスです。
195     //---------------------------------------------------------------------------
GetImageBlockData()196     void* GetImageBlockData()
197     {
198         return const_cast<void*>(this->GetImageBlockDataImpl());
199     }
200 
201     //---------------------------------------------------------------------------
202     //! @brief        イメージデータブロックの先頭のアドレスを取得します。
203     //!
204     //! @return       バイナリのブロック情報への参照です。
205     //---------------------------------------------------------------------------
GetImageBlockData()206     const void* GetImageBlockData() const
207     {
208         return this->GetImageBlockDataImpl();
209     }
210 
211     //---------------------------------------------------------------------------
212     //! @brief        イメージデータブロックのデータサイズを取得します。
213     //!
214     //! @return       イメージデータブロックのデータサイズです。
215     //---------------------------------------------------------------------------
GetImageBlockDataSize()216     s32 GetImageBlockDataSize() const
217     {
218         NW_ASSERT( this->IsValid() );
219 
220         const nw::ut::BinaryFileHeader& header = *reinterpret_cast<const nw::ut::BinaryFileHeader*>( this->ptr() );
221         const nw::ut::BinaryBlockHeader* block = &ref().m_BlockHeader;
222 
223         for (int i = 0; i < header.dataBlocks; ++i)
224         {
225             if (block->kind == nw::ut::ReverseEndian('IMAG'))
226             {
227                 return block->size - sizeof(nw::ut::BinaryBlockHeader);
228             }
229 
230             block = nw::ut::GetNextBinaryBlockHeader( &header, block );
231         }
232 
233         return 0;
234     }
235 
236 private:
237     //---------------------------------------------------------------------------
238     //! @brief        イメージデータブロックの先頭のアドレスを取得します。
239     //---------------------------------------------------------------------------
GetImageBlockDataImpl()240     const void* GetImageBlockDataImpl() const
241     {
242         NW_ASSERT( this->IsValid() );
243 
244         const nw::ut::BinaryFileHeader& header = *reinterpret_cast<const nw::ut::BinaryFileHeader*>( this->ptr() );
245         const nw::ut::BinaryBlockHeader* block = &ref().m_BlockHeader;
246 
247         for (int i = 0; i < header.dataBlocks; ++i)
248         {
249             if (block->kind == nw::ut::ReverseEndian('IMAG'))
250             {
251                 return nw::ut::AddOffsetToPtr(block, sizeof(nw::ut::BinaryBlockHeader));
252             }
253 
254             block = nw::ut::GetNextBinaryBlockHeader( &header, block );
255         }
256 
257         return NULL;
258     }
259 
260 };
261 
262 //--------------------------------------------------------------------------
263 //! @brief  グラフィックス用のファイルを表すバイナリリソースクラスです。
264 //---------------------------------------------------------------------------
265 class ResGraphicsFile : public ResFileHeader
266 {
267 public:
268     enum {
269         BINARY_REVISION = REVISION_RES_GRAPHICS_FILE
270     };
271 
272     NW_RES_CTOR_INHERIT( ResGraphicsFile, ResFileHeader )
273 
274     //---------------------------------------------------------------------------
275     //! @fn           s32 GetVisibilityAnimsIndex(const char * key) const
276     //! @brief        ビジビリティアニメーションリソースの辞書データ中でのインデックス番号を取得します。
277     //---------------------------------------------------------------------------
278     //---------------------------------------------------------------------------
279     //! @fn           s32 GetVisibilityAnimsCount() const
280     //! @brief        ビジビリティアニメーションリソースの要素数を取得します。
281     //---------------------------------------------------------------------------
282     //---------------------------------------------------------------------------
283     //! @fn           anim::res::ResAnim GetVisibilityAnims(int idx)
284     //! @brief        ビジビリティアニメーションリソースを取得します。
285     //---------------------------------------------------------------------------
286     //---------------------------------------------------------------------------
287     //! @fn           s32 GetTexturesIndex(const char * key) const
288     //! @brief        テクスチャリソースの辞書データ中でのインデックス番号を取得します。
289     //---------------------------------------------------------------------------
290     //---------------------------------------------------------------------------
291     //! @fn           s32 GetTexturesCount() const
292     //! @brief        テクスチャリソースの要素数を取得します。
293     //---------------------------------------------------------------------------
294     //---------------------------------------------------------------------------
295     //! @fn           ResTexture GetTextures(int idx)
296     //! @brief        テクスチャリソースを取得します。
297     //---------------------------------------------------------------------------
298     //---------------------------------------------------------------------------
299     //! @fn           s32 GetSkeletalAnimsIndex(const char * key) const
300     //! @brief        スケルタルアニメーションリソースの辞書データ中でのインデックス番号を取得します。
301     //---------------------------------------------------------------------------
302     //---------------------------------------------------------------------------
303     //! @fn           s32 GetSkeletalAnimsCount() const
304     //! @brief        スケルタルアニメーションリソースの要素数を取得します。
305     //---------------------------------------------------------------------------
306     //---------------------------------------------------------------------------
307     //! @fn           anim::res::ResAnim GetSkeletalAnims(int idx)
308     //! @brief        スケルタルアニメーションリソースを取得します。
309     //---------------------------------------------------------------------------
310     //---------------------------------------------------------------------------
311     //! @fn           s32 GetShadersIndex(const char * key) const
312     //! @brief        シェーダリソースの辞書データ中でのインデックス番号を取得します。
313     //---------------------------------------------------------------------------
314     //---------------------------------------------------------------------------
315     //! @fn           s32 GetShadersCount() const
316     //! @brief        シェーダリソースの要素数を取得します。
317     //---------------------------------------------------------------------------
318     //---------------------------------------------------------------------------
319     //! @fn           ResShader GetShaders(int idx)
320     //! @brief        シェーダリソースを取得します。
321     //---------------------------------------------------------------------------
322     //---------------------------------------------------------------------------
323     //! @fn           s32 GetSceneEnvironmentSettingsIndex(const char * key) const
324     //! @brief        シーン環境設定リソースの辞書データ中でのインデックス番号を取得します。
325     //---------------------------------------------------------------------------
326     //---------------------------------------------------------------------------
327     //! @fn           s32 GetSceneEnvironmentSettingsCount() const
328     //! @brief        シーン環境設定リソースの要素数を取得します。
329     //---------------------------------------------------------------------------
330     //---------------------------------------------------------------------------
331     //! @fn           ResSceneEnvironmentSetting GetSceneEnvironmentSettings(int idx)
332     //! @brief        シーン環境設定リソースを取得します。
333     //---------------------------------------------------------------------------
334     //---------------------------------------------------------------------------
335     //! @fn           s32 GetModelsIndex(const char * key) const
336     //! @brief        モデルリソースの辞書データ中でのインデックス番号を取得します。
337     //---------------------------------------------------------------------------
338     //---------------------------------------------------------------------------
339     //! @fn           s32 GetModelsCount() const
340     //! @brief        モデルリソースの要素数を取得します。
341     //---------------------------------------------------------------------------
342     //---------------------------------------------------------------------------
343     //! @fn           ResModel GetModels(int idx)
344     //! @brief        モデルリソースを取得します。
345     //---------------------------------------------------------------------------
346     //---------------------------------------------------------------------------
347     //! @fn           s32 GetMaterialAnimsIndex(const char * key) const
348     //! @brief        マテリアルアニメーションリソースの辞書データ中でのインデックス番号を取得します。
349     //---------------------------------------------------------------------------
350     //---------------------------------------------------------------------------
351     //! @fn           s32 GetMaterialAnimsCount() const
352     //! @brief        マテリアルアニメーションリソースの要素数を取得します。
353     //---------------------------------------------------------------------------
354     //---------------------------------------------------------------------------
355     //! @fn           anim::res::ResAnim GetMaterialAnims(int idx)
356     //! @brief        マテリアルアニメーションリソースを取得します。
357     //---------------------------------------------------------------------------
358     //---------------------------------------------------------------------------
359     //! @fn           s32 GetLutSetsIndex(const char * key) const
360     //! @brief        ルックアップテーブルセットリソースの辞書データ中でのインデックス番号を取得します。
361     //---------------------------------------------------------------------------
362     //---------------------------------------------------------------------------
363     //! @fn           s32 GetLutSetsCount() const
364     //! @brief        ルックアップテーブルセットリソースの要素数を取得します。
365     //---------------------------------------------------------------------------
366     //---------------------------------------------------------------------------
367     //! @fn           ResLookupTableSet GetLutSets(int idx)
368     //! @brief        ルックアップテーブルセットリソースを取得します。
369     //---------------------------------------------------------------------------
370     //---------------------------------------------------------------------------
371     //! @fn           s32 GetLightsIndex(const char * key) const
372     //! @brief        ライトリソースの辞書データ中でのインデックス番号を取得します。
373     //---------------------------------------------------------------------------
374     //---------------------------------------------------------------------------
375     //! @fn           s32 GetLightsCount() const
376     //! @brief        ライトリソースの要素数を取得します。
377     //---------------------------------------------------------------------------
378     //---------------------------------------------------------------------------
379     //! @fn           ResLight GetLights(int idx)
380     //! @brief        ライトリソースを取得します。
381     //---------------------------------------------------------------------------
382     //---------------------------------------------------------------------------
383     //! @fn           s32 GetLightAnimsIndex(const char * key) const
384     //! @brief        ライトアニメーションリソースの辞書データ中でのインデックス番号を取得します。
385     //---------------------------------------------------------------------------
386     //---------------------------------------------------------------------------
387     //! @fn           s32 GetLightAnimsCount() const
388     //! @brief        ライトアニメーションリソースの要素数を取得します。
389     //---------------------------------------------------------------------------
390     //---------------------------------------------------------------------------
391     //! @fn           anim::res::ResLightAnim GetLightAnims(int idx)
392     //! @brief        ライトアニメーションリソースを取得します。
393     //---------------------------------------------------------------------------
394     //---------------------------------------------------------------------------
395     //! @fn           s32 GetFogsIndex(const char * key) const
396     //! @brief        フォグリソースの辞書データ中でのインデックス番号を取得します。
397     //---------------------------------------------------------------------------
398     //---------------------------------------------------------------------------
399     //! @fn           s32 GetFogsCount() const
400     //! @brief        フォグリソースの要素数を取得します。
401     //---------------------------------------------------------------------------
402     //---------------------------------------------------------------------------
403     //! @fn           ResFog GetFogs(int idx)
404     //! @brief        フォグリソースを取得します。
405     //---------------------------------------------------------------------------
406     //---------------------------------------------------------------------------
407     //! @fn           s32 GetEmittersIndex(const char * key) const
408     //! @brief        エミッターリソースの辞書データ中でのインデックス番号を取得します。
409     //---------------------------------------------------------------------------
410     //---------------------------------------------------------------------------
411     //! @fn           s32 GetEmittersCount() const
412     //! @brief        エミッターリソースの要素数を取得します。
413     //---------------------------------------------------------------------------
414     //---------------------------------------------------------------------------
415     //! @fn           ResParticleEmitter GetEmitters(int idx)
416     //! @brief        エミッターリソースを取得します。
417     //---------------------------------------------------------------------------
418     //---------------------------------------------------------------------------
419     //! @fn           s32 GetCamerasIndex(const char * key) const
420     //! @brief        カメラリソースの辞書データ中でのインデックス番号を取得します。
421     //---------------------------------------------------------------------------
422     //---------------------------------------------------------------------------
423     //! @fn           s32 GetCamerasCount() const
424     //! @brief        カメラリソースの要素数を取得します。
425     //---------------------------------------------------------------------------
426     //---------------------------------------------------------------------------
427     //! @fn           ResCamera GetCameras(int idx)
428     //! @brief        カメラリソースを取得します。
429     //---------------------------------------------------------------------------
430     //---------------------------------------------------------------------------
431     //! @fn           s32 GetCameraAnimsIndex(const char * key) const
432     //! @brief        カメラアニメーションリソースの辞書データ中でのインデックス番号を取得します。
433     //---------------------------------------------------------------------------
434     //---------------------------------------------------------------------------
435     //! @fn           s32 GetCameraAnimsCount() const
436     //! @brief        カメラアニメーションリソースの要素数を取得します。
437     //---------------------------------------------------------------------------
438     //---------------------------------------------------------------------------
439     //! @fn           anim::res::ResCameraAnim GetCameraAnims(int idx)
440     //! @brief        カメラアニメーションリソースを取得します。
441     //---------------------------------------------------------------------------
442 
443     NW_RES_FIELD_CLASS_DIC_DECL( ResModel, Models, nw::ut::ResDicPatricia )                 // GetModels(int idx), GetModels(const char*), GetModelsIndex(const char*), GetModelsCount()
444     NW_RES_FIELD_CLASS_DIC_DECL( ResTexture, Textures, nw::ut::ResDicPatricia )             // GetTextures(int idx), GetTextures(const char*), GetTexturesIndex(const char*), GetTexturesCount()
445     NW_RES_FIELD_CLASS_DIC_DECL( ResLookupTableSet, LutSets, nw::ut::ResDicPatricia )       // GetLutSets(int idx), GetLutSets(const char*), GetLutSetsIndex(const char*), GetLutSetsCount()
446     NW_RES_FIELD_CLASS_DIC_DECL( ResShader, Shaders, nw::ut::ResDicPatricia )               // GetShaders(int idx), GetShaders(const char*), GetShadersIndex(const char*), GetShadersCount()
447     NW_RES_FIELD_CLASS_DIC_DECL( ResCamera, Cameras, nw::ut::ResDicPatricia )               // GetCameras(int idx), GetCameras(const char*), GetCamerasIndex(const char*), GetCamerasCount()
448     NW_RES_FIELD_CLASS_DIC_DECL( ResLight, Lights, nw::ut::ResDicPatricia )                 // GetLights(int idx), GetLights(const char*), GetLightsIndex(const char*), GetLightsCount()
449     NW_RES_FIELD_CLASS_DIC_DECL( ResFog, Fogs, nw::ut::ResDicPatricia )                     // GetFogs(int idx), GetFogs(const char*), GetFogsIndex(const char*), GetFogsCount()
450     NW_RES_FIELD_CLASS_DIC_DECL( ResSceneEnvironmentSetting, SceneEnvironmentSettings, nw::ut::ResDicPatricia ) // GetSceneEnvironmentSettings(int idx), GetSceneEnvironmentSettings(const char*), GetSceneEnvironmentSettingsIndex(const char*), GetSceneEnvironmentCount()
451     NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, SkeletalAnims, nw::ut::ResDicPatricia )     // GetSkeletalAnims(int idx), GetSkeletalAnims(const char*), GetSkeletalAnimsIndex(const char*), GetSkeletalAnimsCount()
452     NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, MaterialAnims, nw::ut::ResDicPatricia )     // GetMaterialAnims(int idx), GetMaterialAnims(const char*), GetMaterialAnimsIndex(const char*), GetMaterialAnimsCount()
453     NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, VisibilityAnims, nw::ut::ResDicPatricia )   // GetVisibilityAnims(int idx), GetVisibilityAnims(const char*), GetVisibilityAnimsIndex(const char*), GetVisibilityAnimsCount()
454     NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResCameraAnim, CameraAnims, nw::ut::ResDicPatricia )       // GetCameraAnims(int idx), GetCameraAnims(const char*), GetCameraAnimsIndex(const char*), GetCameraAnimsCount()
455     NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResLightAnim, LightAnims, nw::ut::ResDicPatricia )        // GetLightAnims(int idx), GetLightAnims(const char*), GetLightAnimsIndex(const char*), GetLightAnimsCount()
456     NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, FogAnims, nw::ut::ResDicPatricia )        // GetFogAnims(int idx), GetFogAnims(const char*), GetFogAnimsIndex(const char*), GetFogAnimsCount()
457     NW_RES_FIELD_CLASS_DIC_DECL( ResParticleEmitter, Emitters, nw::ut::ResDicPatricia )     // GetEmitters(int idx), GetEmitters(const char*), GetEmittersIndex(const char*), GetEmittersCount()
458 
459     //---------------------------------------------------------------------------
460     //! @brief        ファイル中のコンテントの初期化処理をおこないます。
461     //!               コマンドの生成と、引数に与えられたファイルを使用した外部参照解決をおこないます。
462     //!
463     //! @param[in]    allocator アロケータです。
464     //! @param[in]    graphicsFile 参照解決を試みるグラフィックスリソースです。
465     //!
466     //! @return       ファイル内のすべての参照が解決済みの場合には、RESOURCE_RESULT_OK を返します。
467     //!               未解決の外部参照が残っている場合には、未解決コンテントの種類を示すフラグを返します。
468     //---------------------------------------------------------------------------
469     Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile);
470 
471     //---------------------------------------------------------------------------
472     //! @brief        自分のファイル内で完結した初期化処理をおこないます。
473     //!
474     //! @param[in]    allocator アロケータです。
475     //!
476     //! @return       ファイル内のすべての参照が解決済みの場合には、RESOURCE_RESULT_OK を返します。
477     //!               未解決の外部参照が残っている場合には、未解決コンテントの種類を示すフラグを返します。
478     //---------------------------------------------------------------------------
Setup(os::IAllocator * allocator)479     Result Setup(os::IAllocator* allocator) { return this->Setup( allocator, *this ); }
480 
481     //---------------------------------------------------------------------------
482     //! @brief        リソースの解放処理をおこないます。
483     //!
484     //! @details      他のファイルから参照されているオブジェクトもすべて解放します。
485     //---------------------------------------------------------------------------
486     void Cleanup();
487 
488     // TODO: 参照カウント方式を用意する。
489     // Result SafeCleanup();
490 
491     //---------------------------------------------------------------------------
492     //! @brief        ResGraphicsFile 内の全ての ResModel を巡回して TFunction を適用します。
493     //!
494     //! @tparam       TFunction ResModel を引数に取る関数(オブジェクト)の型です。
495     //! @param[in]    function 適用する関数(オブジェクト)です。
496     //---------------------------------------------------------------------------
497     template<typename TFunction>
ForeachModel(TFunction function)498     void ForeachModel(TFunction function)
499     {
500         ResModelArray::iterator end = this->GetModels().end();
501         for (ResModelArray::iterator model = this->GetModels().begin();
502             model != end; ++model)
503         {
504             function(*model);
505         }
506     }
507 
508     //---------------------------------------------------------------------------
509     //! @brief        ResGraphicsFile 内の全ての ResModel を巡回して TFunction を適用します。
510     //!               ポインタの特別バージョンです。
511     //!
512     //! @tparam       TFunction ResModel を引数に取る関数(オブジェクト)の型です。
513     //! @param[in]    function 適用する関数(オブジェクト)です。
514     //---------------------------------------------------------------------------
515     template<typename TFunction>
ForeachModel(TFunction * function)516     void ForeachModel(TFunction* function)
517     {
518         NW_NULL_ASSERT(function);
519         this->ForeachModel<TFunction&>(*function);
520     }
521 
522     //---------------------------------------------------------------------------
523     //! @brief        ResGraphicsFile 内の全ての ResMaterial を巡回して TFunction を適用します。
524     //!
525     //! @tparam       TFunction ResMaterial を引数に取る関数(オブジェクト)の型です。
526     //! @param[in]    function 適用する関数(オブジェクト)です。
527     //---------------------------------------------------------------------------
528     template<typename TFunction>
ForeachMaterial(TFunction function)529     void ForeachMaterial(TFunction function)
530     {
531         ResModelArray::iterator end = this->GetModels().end();
532         for (ResModelArray::iterator model = this->GetModels().begin();
533             model != end; ++model)
534         {
535             ResMaterialArray::iterator materialEnd = (*model).GetMaterials().end();
536             for (ResMaterialArray::iterator material = (*model).GetMaterials().begin();
537                 material != materialEnd;
538                 ++material)
539             {
540                 function(*material);
541             }
542         }
543     }
544     //---------------------------------------------------------------------------
545     //! @brief        ResGraphicsFile 内の全ての ResMaterial を巡回して TFunction を適用します。
546     //!               ポインタの特別バージョンです。
547     //!
548     //! @tparam       TFunction ResMaterial を引数に取る関数(オブジェクト)の型です。
549     //! @param[in]    function 適用する関数(オブジェクト)です。
550     //---------------------------------------------------------------------------
551     template<typename TFunction>
ForeachMaterial(TFunction * function)552     void ForeachMaterial(TFunction* function)
553     {
554         NW_NULL_ASSERT(function);
555         this->ForeachMaterial<TFunction&>(*function);
556     }
557 
558 
559     //---------------------------------------------------------------------------
560     //! @brief        ResGraphicsFile 内の全ての ResModel, ResMaterial を巡回して TFunction を適用します。
561     //!
562     //! @tparam       TFunction ResModel, ResMaterial を引数に取る関数(オブジェクト)の型です。
563     //! @param[in]    function 適用する関数(オブジェクト)です。
564     //---------------------------------------------------------------------------
565     template<typename TFunction>
ForeachModelMaterial(TFunction function)566     void ForeachModelMaterial(TFunction function)
567     {
568         ResModelArray::iterator end = this->GetModels().end();
569         for (ResModelArray::iterator model = this->GetModels().begin();
570             model != end; ++model)
571         {
572             ResMaterialArray::iterator materialEnd = (*model).GetMaterials().end();
573             for (ResMaterialArray::iterator material = (*model).GetMaterials().begin();
574                 material != materialEnd;
575                 ++material)
576             {
577                 function(*model, *material);
578             }
579         }
580     }
581     //---------------------------------------------------------------------------
582     //! @brief        ResGraphicsFile 内の全ての ResModel, ResMaterial を巡回して TFunction を適用します。
583     //!               ポインタの特別バージョンです。
584     //!
585     //! @tparam       TFunction ResModel, ResMaterial を引数に取る関数(オブジェクト)の型です。
586     //! @param[in]    function 適用する関数(オブジェクト)です。
587     //---------------------------------------------------------------------------
588     template<typename TFunction>
ForeachModelMaterial(TFunction * function)589     void ForeachModelMaterial(TFunction* function)
590     {
591         NW_NULL_ASSERT(function);
592         this->ForeachModelMaterial<TFunction&>(*function);
593     }
594 
595     //---------------------------------------------------------------------------
596     //! @brief        ResGraphicsFile 内の全ての ResTexture を巡回して TFunction を適用します。
597     //!
598     //! @tparam       TFunction ResTexture を引数に取る関数(オブジェクト)の型です。
599     //! @param[in]    function 適用する関数(オブジェクト)です。
600     //!
601     //! @sa nw::gfx::res::TextureLocationFlagSetter
602     //---------------------------------------------------------------------------
603     template<typename TFunction>
ForeachTexture(TFunction function)604     void ForeachTexture(TFunction function)
605     {
606         ResTextureArray::iterator end = this->GetTextures().end();
607         for (ResTextureArray::iterator texture = this->GetTextures().begin();
608             texture != end; ++texture)
609         {
610             function(*texture);
611         }
612     }
613 
614     //---------------------------------------------------------------------------
615     //! @brief        ResGraphicsFile 内の全ての ResTexture を巡回して TFunction を適用します。
616     //!               ポインタの特別バージョンです。
617     //!
618     //! @tparam       TFunction ResTexture を引数に取る関数(オブジェクト)の型です。
619     //! @param[in]    function 適用する関数(オブジェクト)です。
620     //!
621     //! @sa nw::gfx::res::TextureLocationFlagSetter
622     //---------------------------------------------------------------------------
623     template<typename TFunction>
ForeachTexture(TFunction * function)624     void ForeachTexture(TFunction* function)
625     {
626         NW_NULL_ASSERT(function);
627         this->ForeachTexture<TFunction&>(*function);
628     }
629 
630     //---------------------------------------------------------------------------
631     //! @brief        ResGraphicsFile 内の全ての ResIndexStream を巡回して TFunction を適用します。
632     //!
633     //! @tparam       TFunction ResIndexStream を引数に取る関数(オブジェクト)の型です。
634     //! @param[in]    function 適用する関数(オブジェクト)です。
635     //!
636     //! @sa nw::gfx::res::IndexStreamLocationFlagSetter
637     //---------------------------------------------------------------------------
638     template<typename TFunction>
ForeachIndexStream(TFunction function)639     void ForeachIndexStream(TFunction function)
640     {
641         ResModelArray::iterator modelsEnd = this->GetModels().end();
642         for (ResModelArray::iterator model = this->GetModels().begin();
643             model != modelsEnd ; ++model)
644         {
645             ResShapeArray::iterator shapesEnd = (*model).GetShapes().end();
646             for (ResShapeArray::iterator shape = (*model).GetShapes().begin();
647                 shape != shapesEnd; ++shape)
648             {
649                 ResPrimitiveSetArray::iterator primitiveSetsEnd = (*shape).GetPrimitiveSets().end();
650                 for (ResPrimitiveSetArray::iterator primitiveSet = (*shape).GetPrimitiveSets().begin();
651                     primitiveSet != primitiveSetsEnd; ++primitiveSet)
652                 {
653                     ResPrimitiveArray::iterator primitivesEnd = (*primitiveSet).GetPrimitives().end();
654                     for (ResPrimitiveArray::iterator primitive = (*primitiveSet).GetPrimitives().begin();
655                         primitive != primitivesEnd; ++primitive)
656                     {
657                         ResIndexStreamArray::iterator indexStreamsEnd = (*primitive).GetIndexStreams().end();
658                         for (ResIndexStreamArray::iterator indexStream = (*primitive).GetIndexStreams().begin();
659                             indexStream != indexStreamsEnd; ++indexStream)
660                         {
661                             function(*indexStream);
662                         }
663                     }
664                 }
665             }
666         }
667     }
668 
669     //---------------------------------------------------------------------------
670     //! @brief        ResGraphicsFile 内の全ての ResIndexStream を巡回して TFunction を適用します。
671     //!               ポインタの特別バージョンです。
672     //!
673     //! @tparam       TFunction ResIndexStream を引数に取る関数(オブジェクト)の型です。
674     //! @param[in]    function 適用する関数(オブジェクト)です。
675     //!
676     //! @sa nw::gfx::res::IndexStreamLocationFlagSetter
677     //---------------------------------------------------------------------------
678     template<typename TFunction>
ForeachIndexStream(TFunction * function)679     void ForeachIndexStream(TFunction* function)
680     {
681         this->ForeachIndexStream<TFunction&>(*function);
682     }
683 
684     //---------------------------------------------------------------------------
685     //! @brief        ResGraphicsFile 内の全ての ResVertexStream を巡回して TFunction を適用します。
686     //!
687     //! @tparam       TFunction ResVertexStream を引数に取る関数(オブジェクト)の型です。
688     //! @param[in]    function 適用する関数(オブジェクト)です。
689     //!
690     //! @sa nw::gfx::res::VertexStreamLocationFlagSetter
691     //---------------------------------------------------------------------------
692     template<typename TFunction>
ForeachVertexStream(TFunction function)693     void ForeachVertexStream(TFunction function)
694     {
695         ResModelArray::iterator modelsEnd = this->GetModels().end();
696         for (ResModelArray::iterator model = this->GetModels().begin(); model != modelsEnd ; ++model)
697         {
698             ResShapeArray::iterator shapesEnd = (*model).GetShapes().end();
699             for (ResShapeArray::iterator shape = (*model).GetShapes().begin();
700                 shape != shapesEnd; ++shape)
701             {
702                 ResSeparateDataShape resSeparateDataShape = ResDynamicCast<ResSeparateDataShape>(*shape);
703 
704                 if (resSeparateDataShape.IsValid())
705                 {
706                     ResVertexAttributeArray::iterator vertexAttributesEnd = resSeparateDataShape.GetVertexAttributes().end();
707                     for (ResVertexAttributeArray::iterator vertexAttribute = resSeparateDataShape.GetVertexAttributes().begin();
708                         vertexAttribute != vertexAttributesEnd; ++vertexAttribute)
709                     {
710                         ResVertexStreamBase resVertexStream = ResDynamicCast<ResVertexStreamBase>(*vertexAttribute);
711 
712                         if (resVertexStream.IsValid())
713                         {
714                             function(resVertexStream);
715                         }
716                     }
717                 }
718             }
719         }
720     }
721 
722     //---------------------------------------------------------------------------
723     //! @brief        ResGraphicsFile 内の全ての ResVertexStream を巡回して TFunction を適用します。
724     //!               ポインタの特別バージョンです。
725     //!
726     //! @tparam       TFunction ResVertexStream を引数に取る関数(オブジェクト)の型です。
727     //! @param[in]    function 適用する関数(オブジェクト)です。
728     //!
729     //! @sa nw::gfx::res::VertexStreamLocationFlagSetter
730     //---------------------------------------------------------------------------
731     template<typename TFunction>
ForeachVertexStream(TFunction * function)732     void ForeachVertexStream(TFunction* function)
733     {
734         NW_NULL_ASSERT(function);
735         this->ForeachVertexStream<TFunction&>(*function);
736     }
737 
738     //---------------------------------------------------------------------------
739     //! @brief        ResGraphicsFile 内の全ての ResTexture を巡回して、
740     //!               未解決の ReferenceTexture ならば TFunction を適用します。
741     //!
742     //! @tparam       TFunction ResTexture を引数に取る関数(オブジェクト)の型です。
743     //! @param[in]    function 適用する関数(オブジェクト)です。
744     //---------------------------------------------------------------------------
745     template<typename TFunction>
ForeachUnresolvedReferenceTexture(TFunction function)746     void ForeachUnresolvedReferenceTexture(TFunction function)
747     {
748         this->ForeachTexture(CheckUnresolvedTextureFunctor<TFunction>(function));
749     }
750 
751     //---------------------------------------------------------------------------
752     //! @brief        ResGraphicsFile 内の全ての ResTexture を巡回して、
753     //!               未解決の ReferenceTexture ならば TFunction を適用します。
754     //!               ポインタの特別バージョンです。
755     //!
756     //! @tparam       TFunction ResTexture を引数に取る関数(オブジェクト)の型です。
757     //! @param[in]    function 適用する関数(オブジェクト)です。
758     //---------------------------------------------------------------------------
759     template <typename TFunction>
ForeachUnresolvedReferenceTexture(TFunction * function)760     void ForeachUnresolvedReferenceTexture(TFunction* function)
761     {
762         this->ForeachUnresolvedReferenceTexture<TFunction&>(*function);
763     }
764 
765     //---------------------------------------------------------------------------
766     //! @brief        ResGraphicsFile 内の全ての ResLookupTable を巡回して、
767     //!               未解決の ReferenceLookupTable ならば TFunction を適用します。
768     //!
769     //! @tparam       TFunction ResReferenceLookupTable を引数に取る関数(オブジェクト)の型です。
770     //! @param[in]    function 適用する関数(オブジェクト)です。
771     //---------------------------------------------------------------------------
772     template <typename TFunction>
ForeachUnresolvedReferenceLut(TFunction function)773     void ForeachUnresolvedReferenceLut(TFunction function)
774     {
775         this->ForeachMaterial(CheckUnresolvedMaterialLutFunctor<TFunction>(function));
776 
777         const int lightCount = this->GetLightsCount();
778         for (int i = 0; i < lightCount; ++i)
779         {
780             ResFragmentLight fragmentLight =
781                 ResDynamicCast<ResFragmentLight>(this->GetLights(i));
782 
783             if (fragmentLight.IsValid())
784             {
785                 // distanceSampler
786                 ResReferenceLookupTable distance =
787                     ResDynamicCast<ResReferenceLookupTable>(fragmentLight.GetDistanceSampler());
788                 if (distance.IsValid() && !distance.GetTargetLut().IsValid())
789                 {
790                     function(distance);
791                 }
792 
793                 // angleSampler
794                 ResLightingLookupTable lightingLut = fragmentLight.GetAngleSampler();
795                 if (lightingLut.IsValid())
796                 {
797                     ResReferenceLookupTable angle =
798                         ResDynamicCast<ResReferenceLookupTable>(lightingLut.GetSampler());
799                     if (angle.IsValid() && !angle.GetTargetLut().IsValid())
800                     {
801                         function(angle);
802                     }
803                 }
804             }
805         }
806     }
807 
808     //---------------------------------------------------------------------------
809     //! @brief        ResGraphicsFile 内の全ての ResLookupTable を巡回して、
810     //!               未解決の ReferenceLookupTable ならば TFunction を適用します。
811     //!               ポインタの特別バージョンです。
812     //!
813     //! @tparam       TFunction ResReferenceShader を引数に取る関数(オブジェクト)の型です。
814     //! @param[in]    function 適用する関数(オブジェクト)です。
815     //---------------------------------------------------------------------------
816     template <typename TFunction>
ForeachUnresolvedReferenceLut(TFunction * function)817     void ForeachUnresolvedReferenceLut(TFunction* function)
818     {
819         NW_NULL_ASSERT(function);
820         this->ForeachUnresolvedReferenceLut<TFunction&>(*function);
821     }
822 
823     //---------------------------------------------------------------------------
824     //! @brief        ResGraphicsFile 内の全ての ResShader を巡回して、
825     //!               未解決の ReferenceShader ならば TFunction を適用します。
826     //!
827     //! @tparam       TFunction ResReferenceShader を引数に取る関数(オブジェクト)の型です。
828     //! @param[in]    function 適用する関数(オブジェクト)です。
829     //---------------------------------------------------------------------------
830     template <typename TFunction>
ForeachUnresolvedReferenceShader(TFunction function)831     void ForeachUnresolvedReferenceShader(TFunction function)
832     {
833         const int shaderCount = this->GetShadersCount();
834         for (int i = 0; i < shaderCount; ++i)
835         {
836             ResReferenceShader refer =
837                 ResDynamicCast<ResReferenceShader>(this->GetShaders(i));
838             if (refer.IsValid())
839             {
840                 if (!refer.GetTargetShader().IsValid())
841                 {
842                     function(refer);
843                 }
844             }
845         }
846     }
847 
848     //---------------------------------------------------------------------------
849     //! @brief        ResGraphicsFile 内の全ての ResShader を巡回して、
850     //!               未解決の ReferenceShader ならば TFunction を適用します。
851     //!               ポインタの特別バージョンです。
852     //!
853     //! @tparam       TFunction ResReferenceShader を引数に取る関数(オブジェクト)の型です。
854     //! @param[in]    function 適用する関数(オブジェクト)です。
855     //---------------------------------------------------------------------------
856     template <typename TFunction>
ForeachUnresolvedReferenceShader(TFunction * function)857     void ForeachUnresolvedReferenceShader(TFunction* function)
858     {
859         NW_NULL_ASSERT(function);
860         this->ForeachUnresolvedReferenceShader<TFunction&>(*function);
861     }
862 
863     //---------------------------------------------------------------------------
864     //! @brief        ResGraphicsFile 内の全ての参照オブジェクトを巡回して、
865     //!               未解決の参照オブジェクトならば TFunction を適用します。
866     //!
867     //! @tparam       TFunction 参照オブジェクトを引数に取る関数オブジェクトの型です。
868     //! @param[in]    function 適用する関数オブジェクトです。
869     //!                        ResTexture , ResReferenceShader , ResReferenceLookupTable を
870     //!                        それぞれ引数にとるように operator() をオーバーロードしてください。
871     //---------------------------------------------------------------------------
872     template <typename TFunction>
ForeachUnresolvedReference(TFunction function)873     void ForeachUnresolvedReference(TFunction function)
874     {
875         this->ForeachUnresolvedReferenceTexture(function);
876         this->ForeachUnresolvedReferenceShader(function);
877         this->ForeachUnresolvedReferenceLut(function);
878     }
879 
880     //---------------------------------------------------------------------------
881     //! @brief        ResGraphicsFile 内の全ての参照オブジェクトを巡回して、
882     //!               未解決の参照オブジェクトならば TFunction を適用します。
883     //!               ポインタの特別バージョンです。
884     //!
885     //! @tparam       TFunction 参照オブジェクトを引数に取る関数オブジェクトの型です。
886     //! @param[in]    function 適用する関数オブジェクトです。
887     //!                        ResTexture , ResReferenceShader , ResReferenceLookupTable を
888     //!                        それぞれ引数にとるように operator() をオーバーロードしてください。
889     //---------------------------------------------------------------------------
890     template <typename TFunction>
ForeachUnresolvedReference(TFunction * function)891     void ForeachUnresolvedReference(TFunction* function)
892     {
893         NW_NULL_ASSERT(function);
894         this->ForeachUnresolvedReference<TFunction&>(*function);
895     }
896 
897     //---------------------------------------------------------------------------
898     //! @brief      ライブラリが使用可能なリビジョンであるかを確認します。
899     //!
900     //!             この関数が false を返したときは、
901     //!             ライブラリとリソースのコンバーターでバージョンが異なっている可能性があります。
902     //!             そのときは、ライブラリとともに NW4C パッケージに同梱されているツールを使用して
903     //!             リソースを再度コンバートしてください。
904     //!
905     //! @return     使用可能であれば true を返します。
906     //---------------------------------------------------------------------------
IsValidRevision()907     bool IsValidRevision() const
908     {
909         NW_ASSERT( this->IsValid() );
910 
911         int modelsCount = this->GetModelsCount();
912         for (int i = 0 ; i < modelsCount ; ++i )
913         {
914             if ( !internal::ResCheckRevision( this->GetModels(i) ) )
915             {
916                 return false;
917             }
918         }
919 
920         int texturesCount = this->GetTexturesCount();
921         for (int i = 0 ; i < texturesCount ; ++i )
922         {
923             if ( !internal::ResCheckRevision( this->GetTextures(i) ) )
924             {
925                 return false;
926             }
927         }
928 
929         int lutSetsCount = this->GetLutSetsCount();
930         for (int i = 0 ; i < lutSetsCount ; ++i )
931         {
932             if ( !internal::ResCheckRevision( this->GetLutSets(i) ) )
933             {
934                 return false;
935             }
936         }
937 
938         int shadersCount = this->GetShadersCount();
939         for (int i = 0 ; i < shadersCount ; ++i )
940         {
941             if ( !internal::ResCheckRevision( this->GetShaders(i) ) )
942             {
943                 return false;
944             }
945         }
946 
947         int camerasCount = this->GetCamerasCount();
948         for (int i = 0 ; i < camerasCount ; ++i )
949         {
950             if ( !internal::ResCheckRevision( this->GetCameras(i) ) )
951             {
952                 return false;
953             }
954         }
955 
956         int lightsCount = this->GetLightsCount();
957         for (int i = 0 ; i < lightsCount ; ++i )
958         {
959             if ( !internal::ResCheckRevision( this->GetLights(i) ) )
960             {
961                 return false;
962             }
963         }
964 
965         int fogsCount = this->GetFogsCount();
966         for (int i = 0 ; i < fogsCount ; ++i )
967         {
968             if ( !internal::ResCheckRevision( this->GetFogs(i) ) )
969             {
970                 return false;
971             }
972         }
973 
974         int sceneEnvironmentSettingsCount = this->GetSceneEnvironmentSettingsCount();
975         for (int i = 0 ; i < sceneEnvironmentSettingsCount ; ++i )
976         {
977             if ( !internal::ResCheckRevision( this->GetSceneEnvironmentSettings(i) ) )
978             {
979                 return false;
980             }
981         }
982 
983         int skeletalAnimsCount = this->GetSkeletalAnimsCount();
984         for (int i = 0 ; i < skeletalAnimsCount ; ++i )
985         {
986             if ( !internal::ResCheckRevision( this->GetSkeletalAnims(i) ) )
987             {
988                 return false;
989             }
990         }
991 
992         int materialAnimsCount = this->GetMaterialAnimsCount();
993         for (int i = 0 ; i < materialAnimsCount ; ++i )
994         {
995             if ( !internal::ResCheckRevision( this->GetMaterialAnims(i) ) )
996             {
997                 return false;
998             }
999         }
1000 
1001         int visibilityAnimsCount = this->GetVisibilityAnimsCount();
1002         for (int i = 0 ; i < visibilityAnimsCount ; ++i )
1003         {
1004             if ( !internal::ResCheckRevision( this->GetVisibilityAnims(i) ) )
1005             {
1006                 return false;
1007             }
1008         }
1009 
1010         int cameraAnimsCount = this->GetCameraAnimsCount();
1011         for (int i = 0 ; i < cameraAnimsCount ; ++i )
1012         {
1013             if ( !internal::ResCheckRevision( this->GetCameraAnims(i) ) )
1014             {
1015                 return false;
1016             }
1017         }
1018 
1019         int lightAnimsCount = this->GetLightAnimsCount();
1020         for (int i = 0 ; i < lightAnimsCount ; ++i )
1021         {
1022             if ( !internal::ResCheckRevision( this->GetLightAnims(i) ) )
1023             {
1024                 return false;
1025             }
1026         }
1027 
1028         int fogAnimsCount = this->GetFogAnimsCount();
1029         for (int i = 0 ; i < fogAnimsCount ; ++i )
1030         {
1031             if ( !internal::ResCheckRevision( this->GetFogAnims(i) ) )
1032             {
1033                 return false;
1034             }
1035         }
1036 
1037         return true;
1038     }
1039 
1040 private:
1041     // 未解決の参照オブジェクトにアクセスする際に使用する関数オブジェクトです。
1042 
1043     // 引数に渡された ResTexture が ReferenceTexture で、
1044     // 未解決なら function を実行する関数オブジェクト
1045     template <typename TFunction>
1046     class CheckUnresolvedTextureFunctor
1047     {
1048     public:
CheckUnresolvedTextureFunctor(TFunction function)1049         explicit CheckUnresolvedTextureFunctor(TFunction function) : m_Function(function) {}
operator()1050         void operator() (ResTexture texture)
1051         {
1052             if (texture.ref().typeInfo == ResReferenceTexture::TYPE_INFO)
1053             {
1054                 ResReferenceTexture refer = ResStaticCast<ResReferenceTexture>(texture);
1055                 if (!refer.GetTargetTexture().IsValid())
1056                 {
1057                     m_Function(texture);
1058                 }
1059             }
1060         }
1061     private:
1062         TFunction m_Function;
1063     };
1064 
1065     // 引数に渡された ResMaterial の中のLUTを走査し、
1066     // 未解決のReferenceLutを見つけたらそれに対して function を実行する関数オブジェクト
1067     template <typename TFunction>
1068     class CheckUnresolvedMaterialLutFunctor
1069     {
1070     public:
CheckUnresolvedMaterialLutFunctor(TFunction function)1071         explicit CheckUnresolvedMaterialLutFunctor(TFunction function) : m_Function(function) {}
operator()1072         void operator() (ResMaterial material)
1073         {
1074             NW_ASSERT(material.IsValid());
1075 
1076             if (material.GetFragmentShader().IsValid())
1077             {
1078                 ResFragmentLightingTable table =
1079                    material.GetFragmentShader().GetFragmentLightingTable();
1080                 if (table.IsValid())
1081                 {
1082                     CheckReferenceLutAndExec(table.GetReflectanceRSampler());
1083                     CheckReferenceLutAndExec(table.GetReflectanceGSampler());
1084                     CheckReferenceLutAndExec(table.GetReflectanceBSampler());
1085                     CheckReferenceLutAndExec(table.GetDistribution0Sampler());
1086                     CheckReferenceLutAndExec(table.GetDistribution1Sampler());
1087                     CheckReferenceLutAndExec(table.GetFresnelSampler());
1088                 }
1089             }
1090         }
1091     private:
CheckReferenceLutAndExec(ResLightingLookupTable lightingLut)1092         void CheckReferenceLutAndExec(ResLightingLookupTable lightingLut)
1093         {
1094             if (lightingLut.IsValid() && lightingLut.GetSampler().IsValid())
1095             {
1096                 ResReferenceLookupTable refer =
1097                     ResDynamicCast<ResReferenceLookupTable>(lightingLut.GetSampler());
1098                 if (refer.IsValid() && !refer.GetTargetLut().IsValid())
1099                 {
1100                     m_Function(refer);
1101                 }
1102             }
1103         }
1104 
1105         TFunction m_Function;
1106     };
1107 };
1108 
1109 
1110 //---------------------------------------------------------------------------
1111 //! @brief        テクスチャや頂点データの配置アドレスを設定する関数オブジェクトです。
1112 //!
1113 //! @sa nw::gfx::res::ResGraphicsFile::ForeachTexture
1114 //! @sa nw::gfx::res::ResGraphicsFile::ForeachIndexStream
1115 //! @sa nw::gfx::res::ResGraphicsFile::ForeachVertexStream
1116 //---------------------------------------------------------------------------
1117 class TransferedVramAddressSetter
1118 {
1119 public:
TransferedVramAddressSetter(void * fcramImageAddress,void * vramImageAddress)1120     TransferedVramAddressSetter(void* fcramImageAddress, void* vramImageAddress)
1121      : m_FcramImageAddress(fcramImageAddress),
1122        m_VramImageAddress(vramImageAddress)
1123     {}
1124 
1125     //---------------------------------------------------------------------------
1126     //! @brief        テクスチャイメージデータに VRAM アドレスを設定します。
1127     //---------------------------------------------------------------------------
operator()1128     void operator()(nw::gfx::ResTexture resTexture) const
1129     {
1130          // ImageTextureとCubeTextureのときだけloadFlagを設定.
1131         switch( resTexture.ref().typeInfo )
1132         {
1133         case nw::gfx::ResImageTexture::TYPE_INFO:
1134             {
1135                 nw::gfx::ResImageTexture resImageTexture = nw::gfx::ResStaticCast<nw::gfx::ResImageTexture>( resTexture );
1136 
1137                 nw::gfx::ResPixelBasedImage resImage = resImageTexture.GetImage();
1138                 const void* locationAddress = this->GetVramLocation( resImage.GetImageData() );
1139                 resImage.SetLocationAddress( locationAddress );
1140             }
1141             break;
1142         case nw::gfx::ResCubeTexture::TYPE_INFO:
1143             {
1144                 nw::gfx::ResCubeTexture resCubeTexture = nw::gfx::ResStaticCast<nw::gfx::ResCubeTexture>( resTexture );
1145 
1146                 for ( int face = 0; face < nw::gfx::ResCubeTexture::MAX_CUBE_FACE; ++face )
1147                 {
1148                     nw::gfx::ResPixelBasedImage resImage = resCubeTexture.GetImage( nw::gfx::ResCubeTexture::CubeFace(face) );
1149                     const void* locationAddress = this->GetVramLocation( resImage.GetImageData() );
1150                     resImage.SetLocationAddress( locationAddress );
1151                 }
1152             }
1153             break;
1154         default:
1155             break;
1156         }
1157     }
1158 
1159     //---------------------------------------------------------------------------
1160     //! @brief        インデックスストリームデータに VRAM アドレスを設定します。
1161     //---------------------------------------------------------------------------
operator()1162     void operator()(nw::gfx::ResIndexStream resIndexStream) const
1163     {
1164         const void* locationAddress = this->GetVramLocation( resIndexStream.GetStream() );
1165         resIndexStream.SetLocationAddress( locationAddress );
1166     }
1167 
1168     //---------------------------------------------------------------------------
1169     //! @brief        頂点ストリームデータに VRAM アドレスを設定します。
1170     //---------------------------------------------------------------------------
operator()1171     void operator()(nw::gfx::ResVertexStreamBase resVertexStream) const
1172     {
1173         const void* locationAddress = this->GetVramLocation( resVertexStream.GetStream() );
1174         resVertexStream.SetLocationAddress( locationAddress );
1175     }
1176 
1177 private:
1178 
1179     //---------------------------------------------------------------------------
1180     //! @brief        FCRAM 上のアドレスから VRAM 上のアドレスを計算します。
1181     //!
1182     //! @param[in]    fcramLocation FCRAM 上のアドレスです。
1183     //!
1184     //! @return       VRAM 上のアドレスを返します。
1185     //---------------------------------------------------------------------------
GetVramLocation(const void * fcramLocation)1186     const void* GetVramLocation(const void* fcramLocation) const
1187     {
1188         u32 addressOffset = nw::ut::GetOffsetFromPtr( m_FcramImageAddress, fcramLocation );
1189         return nw::ut::AddOffsetToPtr( m_VramImageAddress, addressOffset );
1190     }
1191 
1192     void* m_FcramImageAddress;
1193     void* m_VramImageAddress;
1194 };
1195 
1196 
1197 //---------------------------------------------------------------------------
1198 //! @brief        テクスチャ、頂点情報の配置場所を設定する関数オブジェクトです。
1199 //!
1200 //! @sa nw::gfx::res::ResGraphicsFile::ForeachTexture
1201 //! @sa nw::gfx::res::ResGraphicsFile::ForeachIndexStream
1202 //! @sa nw::gfx::res::ResGraphicsFile::ForeachVertexStream
1203 //---------------------------------------------------------------------------
1204 class LocationFlagSetter
1205 {
1206 public:
LocationFlagSetter(u32 flag)1207     LocationFlagSetter(u32 flag) : m_Flag(flag) {}
1208 
1209     //---------------------------------------------------------------------------
1210     //! @brief        テクスチャのロケーションフラグを設定します。
1211     //---------------------------------------------------------------------------
operator()1212     void operator()(ResTexture resTexture) const
1213     {
1214          // ImageTextureとCubeTextureのときだけloadFlagを設定.
1215         switch( resTexture.ref().typeInfo )
1216         {
1217         case ResImageTexture::TYPE_INFO:
1218             {
1219                 ResImageTexture resImageTexture = ResStaticCast<ResImageTexture>( resTexture );
1220                 resImageTexture.SetLocationFlag( m_Flag );
1221             }
1222             break;
1223         case ResCubeTexture::TYPE_INFO:
1224             {
1225                 ResCubeTexture resCubeTexture = ResStaticCast<ResCubeTexture>( resTexture );
1226                 resCubeTexture.SetLocationFlag( m_Flag );
1227             }
1228             break;
1229         default:
1230             break;
1231         }
1232     }
1233 
1234     //---------------------------------------------------------------------------
1235     //! @brief        インデックスストリームのロケーションフラグを設定します。
1236     //---------------------------------------------------------------------------
operator()1237     void operator()(ResIndexStream resIndexStream) const
1238     {
1239         resIndexStream.SetLocationFlag(m_Flag);
1240     }
1241 
1242     //---------------------------------------------------------------------------
1243     //! @brief        頂点ストリームのロケーションフラグを設定します。
1244     //---------------------------------------------------------------------------
operator()1245     void operator()(ResVertexStreamBase resVertexStream) const
1246     {
1247         resVertexStream.SetLocationFlag(m_Flag);
1248     }
1249 
1250 private:
1251     u32 m_Flag;
1252 };
1253 
1254 //---------------------------------------------------------------------------
1255 //! @brief        テクスチャの配置場所を設定する関数オブジェクトです。
1256 //!
1257 //! @sa nw::gfx::res::ResGraphicsFile::ForeachTexture
1258 //---------------------------------------------------------------------------
1259 typedef LocationFlagSetter TextureLocationFlagSetter;
1260 
1261 //---------------------------------------------------------------------------
1262 //! @brief        インデックスストリームの配置場所を設定する関数オブジェクトです。
1263 //!
1264 //! @sa nw::gfx::res::ResGraphicsFile::ForeachIndexStream
1265 //---------------------------------------------------------------------------
1266 typedef LocationFlagSetter IndexStreamLocationFlagSetter;
1267 
1268 //---------------------------------------------------------------------------
1269 //! @brief        頂点バッファの配置場所を設定する関数オブジェクトです。
1270 //!
1271 //! @sa nw::gfx::res::ResGraphicsFile::ForeachVertexStream
1272 //---------------------------------------------------------------------------
1273 typedef LocationFlagSetter VertexStreamLocationFlagSetter;
1274 
1275 
1276 //---------------------------------------------------------------------------
1277 //! @brief        エフェクトリソース内、パーティクルマテリアル使用フラグを設定する関数オブジェクトです。
1278 //!
1279 //! @sa nw::gfx::res::ResGraphicsFile::ForeachModelMaterial
1280 //---------------------------------------------------------------------------
1281 class ParticleMaterialFlagSetter
1282 {
1283 public:
operator()1284     void operator()(ResModel resModel, ResMaterial resMaterial) const
1285     {
1286         NW_ASSERT(resMaterial.IsValid());
1287 
1288         ut::ResTypeInfo resTypeInfo = resModel.GetTypeInfo();
1289         if (resTypeInfo == nw::gfx::ResParticleModel::TYPE_INFO)
1290         {
1291             resMaterial.SetFlags(ut::EnableFlag(resMaterial.GetFlags(), nw::gfx::ResMaterialData::FLAG_PARTICLE_MATERIAL_ENABLED));
1292         }
1293     }
1294 };
1295 
1296 //---------------------------------------------------------------------------
1297 //! @brief       デフォルトシェーダーでの ShaderProgramDescriptionIndex を設定する関数オブジェクトです。
1298 //!
1299 //! @sa nw::gfx::res::ResGraphicsFile::ForeachMaterial
1300 //---------------------------------------------------------------------------
1301 class DefaultShaderAutoSelector
1302 {
1303 public:
operator()1304     void operator()(ResModel resModel, ResMaterial resMaterial) const
1305     {
1306         const char* DEFAULT_SHADER = "DefaultShader";
1307         NW_ASSERT(resMaterial.IsValid());
1308         ut::ResTypeInfo resTypeInfo = resModel.GetTypeInfo();
1309         if (resTypeInfo == ResModel::TYPE_INFO ||
1310             resTypeInfo == ResSkeletalModel::TYPE_INFO)
1311         {
1312             ResReferenceShader referenceShader = ResDynamicCast<ResReferenceShader>(resMaterial.GetShader());
1313             // HACK: 1.3 で ASSERT に変更します。
1314             // NW_ASSERT(referenceShader.IsValid());
1315             if (referenceShader.IsValid())
1316             {
1317                 if (::std::strcmp(referenceShader.GetPath(), DEFAULT_SHADER) == 0)
1318                 {
1319                     // アクティブなコーディネータの数によって DescriptionIndex を変えます。
1320                     s32 activeCoordinatorsCount = resMaterial.GetActiveTextureCoordinatorsCount();
1321 
1322                     enum { TEXTURE_COUNT_0 = 3, TEXTURE_COUNT_1 = 2, TEXTURE_COUNT_2 = 1, TEXTURE_COUNT_3 = 0 };
1323                     const int table[] =
1324                     {
1325                         TEXTURE_COUNT_0,
1326                         TEXTURE_COUNT_1,
1327                         TEXTURE_COUNT_2,
1328                         TEXTURE_COUNT_3
1329                     };
1330 
1331                     resMaterial.SetShaderProgramDescriptionIndex(table[activeCoordinatorsCount]);
1332                 }
1333             }
1334         }
1335     }
1336 };
1337 
1338 } // namespace res
1339 } // namespace gfx
1340 } // namespace nw
1341 
1342 #endif // NW_GFX_RESGRAPHICSFILE_H_
1343