/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ResGraphicsFile.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 19617 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_RESGRAPHICSFILE_H_ #define NW_GFX_RESGRAPHICSFILE_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace nw { namespace gfx { namespace res { //! @details :private struct ResFileHeaderData { nw::ut::ResU32 m_Signature; nw::ut::ResU16 m_ByteOrder; nw::ut::ResU16 m_HeaderSize; nw::ut::ResU32 m_Revision; nw::ut::ResU32 m_FileSize; nw::ut::ResU16 m_NumBlocks; u8 padding_[2]; nw::ut::BinaryBlockHeader m_BlockHeader; }; //! @details :private struct ResGraphicsFileData : public ResFileHeaderData { nw::ut::ResS32 m_ModelsDicCount; nw::ut::Offset toModelsDic; nw::ut::ResS32 m_TexturesDicCount; nw::ut::Offset toTexturesDic; nw::ut::ResS32 m_LutSetsDicCount; nw::ut::Offset toLutSetsDic; nw::ut::ResS32 m_MaterialsDicCount; nw::ut::Offset toMaterialsDic; nw::ut::ResS32 m_ShadersDicCount; nw::ut::Offset toShadersDic; nw::ut::ResS32 m_CamerasDicCount; nw::ut::Offset toCamerasDic; nw::ut::ResS32 m_LightsDicCount; nw::ut::Offset toLightsDic; nw::ut::ResS32 m_FogsDicCount; nw::ut::Offset toFogsDic; nw::ut::ResS32 m_SceneEnvironmentSettingsDicCount; nw::ut::Offset toSceneEnvironmentSettingsDic; nw::ut::ResS32 m_SkeletalAnimsDicCount; nw::ut::Offset toSkeletalAnimsDic; nw::ut::ResS32 m_MaterialAnimsDicCount; nw::ut::Offset toMaterialAnimsDic; nw::ut::ResS32 m_VisibilityAnimsDicCount; nw::ut::Offset toVisibilityAnimsDic; nw::ut::ResS32 m_CameraAnimsDicCount; nw::ut::Offset toCameraAnimsDic; nw::ut::ResS32 m_LightAnimsDicCount; nw::ut::Offset toLightAnimsDic; nw::ut::ResS32 m_FogAnimsDicCount; nw::ut::Offset toFogAnimsDic; nw::ut::ResS32 m_EmittersDicCount; nw::ut::Offset toEmittersDic; }; //-------------------------------------------------------------------------- //! @brief グラフィックス用のファイルヘッダを表すバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResFileHeader : public nw::ut::ResCommon< ResFileHeaderData > { public: NW_RES_CTOR( ResFileHeader ) //--------------------------------------------------------------------------- //! @fn u32 GetSignature() const //! @brief シグニチャを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetSignature(u32 value) //! @brief シグニチャを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, Signature ) // GetSignature(), SetSignature() //--------------------------------------------------------------------------- //! @fn u16 GetByteOrder() const //! @brief バイトオーダーを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetByteOrder(u16 value) //! @brief バイトオーダーを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u16, ByteOrder ) // GetByteOrder(), SetByteOrder() //--------------------------------------------------------------------------- //! @fn u16 GetHeaderSize() const //! @brief ヘッダーサイズを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetHeaderSize(u16 value) //! @brief ヘッダーサイズを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u16, HeaderSize ) // GetHeaderSize(), SetHeaderSize() //--------------------------------------------------------------------------- //! @fn u32 GetRevision() const //! @brief リビジョン情報を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetRevision(u32 value) //! @brief リビジョン情報を設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, Revision ) // GetRevision(), SetRevision() //--------------------------------------------------------------------------- //! @fn u32 GetFileSize() const //! @brief ファイルサイズを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetFileSize(u32 value) //! @brief ファイルサイズを設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u32, FileSize ) // GetFileSize(), SetFileSize() //--------------------------------------------------------------------------- //! @fn u16 GetNumBlocks() const //! @brief ブロック数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetNumBlocks(u16 value) //! @brief ブロック数を設定します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( u16, NumBlocks ) // GetNumBlocks(), SetNumBlocks() //--------------------------------------------------------------------------- //! @brief バイナリのファイルヘッダを取得します。 //! //! @return バイナリのファイルヘッダへの参照です。 //--------------------------------------------------------------------------- const nw::ut::BinaryFileHeader& GetFileHeader() const { return *reinterpret_cast( this->ptr() ); } //--------------------------------------------------------------------------- //! @brief バイナリのブロック情報を取得します。 //! //! @details ResGraphicsFile には kind が "DATA" となっている通常ブロックと "IMAG" //! となっているテクスチャ、頂点イメージブロックの2種類のブロックが存在します。 //! nw::ut::GetNextBinaryBlockHeader 関数を使用してイメージブロックを取得して、 //! まとめて VRAM に転送することで、イメージデータの VRAMへの転送コストを抑える事が可能です。 //! この場合、アプリケーション側でまとめて転送した VRAM のアドレスと //! 各リソース上のイメージデータのアドレス情報を元に、それぞれの VRAM アドレスを計算し、 //! ResImageTexture や ResVertexStream, ResIndexStream にある SetLocationAddress 関数を //! 使用して Setup 前に設定してください。 //! //! @return バイナリのブロック情報への参照です。 //--------------------------------------------------------------------------- const nw::ut::BinaryBlockHeader& GetFirstBlockHeader() const { return ref().m_BlockHeader; } //--------------------------------------------------------------------------- //! @brief イメージデータブロックの先頭のデータアドレスを取得します。 //! //! @return イメージデータブロックの先頭のデータアドレスです。 //--------------------------------------------------------------------------- void* GetImageBlockData() { return const_cast(this->GetImageBlockDataImpl()); } //--------------------------------------------------------------------------- //! @brief イメージデータブロックの先頭のアドレスを取得します。 //! //! @return バイナリのブロック情報への参照です。 //--------------------------------------------------------------------------- const void* GetImageBlockData() const { return this->GetImageBlockDataImpl(); } //--------------------------------------------------------------------------- //! @brief イメージデータブロックのデータサイズを取得します。 //! //! @return イメージデータブロックのデータサイズです。 //--------------------------------------------------------------------------- s32 GetImageBlockDataSize() const { NW_ASSERT( this->IsValid() ); const nw::ut::BinaryFileHeader& header = *reinterpret_cast( this->ptr() ); const nw::ut::BinaryBlockHeader* block = &ref().m_BlockHeader; for (int i = 0; i < header.dataBlocks; ++i) { if (block->kind == nw::ut::ReverseEndian('IMAG')) { return block->size - sizeof(nw::ut::BinaryBlockHeader); } block = nw::ut::GetNextBinaryBlockHeader( &header, block ); } return 0; } private: //--------------------------------------------------------------------------- //! @brief イメージデータブロックの先頭のアドレスを取得します。 //--------------------------------------------------------------------------- const void* GetImageBlockDataImpl() const { NW_ASSERT( this->IsValid() ); const nw::ut::BinaryFileHeader& header = *reinterpret_cast( this->ptr() ); const nw::ut::BinaryBlockHeader* block = &ref().m_BlockHeader; for (int i = 0; i < header.dataBlocks; ++i) { if (block->kind == nw::ut::ReverseEndian('IMAG')) { return nw::ut::AddOffsetToPtr(block, sizeof(nw::ut::BinaryBlockHeader)); } block = nw::ut::GetNextBinaryBlockHeader( &header, block ); } return NULL; } }; //-------------------------------------------------------------------------- //! @brief グラフィックス用のファイルを表すバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResGraphicsFile : public ResFileHeader { public: enum { BINARY_REVISION = REVISION_RES_GRAPHICS_FILE }; NW_RES_CTOR_INHERIT( ResGraphicsFile, ResFileHeader ) //--------------------------------------------------------------------------- //! @fn s32 GetVisibilityAnimsIndex(const char * key) const //! @brief ビジビリティアニメーションリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetVisibilityAnimsCount() const //! @brief ビジビリティアニメーションリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn anim::res::ResAnim GetVisibilityAnims(int idx) //! @brief ビジビリティアニメーションリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetTexturesIndex(const char * key) const //! @brief テクスチャリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetTexturesCount() const //! @brief テクスチャリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResTexture GetTextures(int idx) //! @brief テクスチャリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetSkeletalAnimsIndex(const char * key) const //! @brief スケルタルアニメーションリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetSkeletalAnimsCount() const //! @brief スケルタルアニメーションリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn anim::res::ResAnim GetSkeletalAnims(int idx) //! @brief スケルタルアニメーションリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetShadersIndex(const char * key) const //! @brief シェーダリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetShadersCount() const //! @brief シェーダリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResShader GetShaders(int idx) //! @brief シェーダリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetSceneEnvironmentSettingsIndex(const char * key) const //! @brief シーン環境設定リソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetSceneEnvironmentSettingsCount() const //! @brief シーン環境設定リソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResSceneEnvironmentSetting GetSceneEnvironmentSettings(int idx) //! @brief シーン環境設定リソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetModelsIndex(const char * key) const //! @brief モデルリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetModelsCount() const //! @brief モデルリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResModel GetModels(int idx) //! @brief モデルリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetMaterialAnimsIndex(const char * key) const //! @brief マテリアルアニメーションリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetMaterialAnimsCount() const //! @brief マテリアルアニメーションリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn anim::res::ResAnim GetMaterialAnims(int idx) //! @brief マテリアルアニメーションリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetLutSetsIndex(const char * key) const //! @brief ルックアップテーブルセットリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetLutSetsCount() const //! @brief ルックアップテーブルセットリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResLookupTableSet GetLutSets(int idx) //! @brief ルックアップテーブルセットリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetLightsIndex(const char * key) const //! @brief ライトリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetLightsCount() const //! @brief ライトリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResLight GetLights(int idx) //! @brief ライトリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetLightAnimsIndex(const char * key) const //! @brief ライトアニメーションリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetLightAnimsCount() const //! @brief ライトアニメーションリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn anim::res::ResLightAnim GetLightAnims(int idx) //! @brief ライトアニメーションリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetFogsIndex(const char * key) const //! @brief フォグリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetFogsCount() const //! @brief フォグリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResFog GetFogs(int idx) //! @brief フォグリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetEmittersIndex(const char * key) const //! @brief エミッターリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetEmittersCount() const //! @brief エミッターリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResParticleEmitter GetEmitters(int idx) //! @brief エミッターリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetCamerasIndex(const char * key) const //! @brief カメラリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetCamerasCount() const //! @brief カメラリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ResCamera GetCameras(int idx) //! @brief カメラリソースを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetCameraAnimsIndex(const char * key) const //! @brief カメラアニメーションリソースの辞書データ中でのインデックス番号を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn s32 GetCameraAnimsCount() const //! @brief カメラアニメーションリソースの要素数を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn anim::res::ResCameraAnim GetCameraAnims(int idx) //! @brief カメラアニメーションリソースを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_CLASS_DIC_DECL( ResModel, Models, nw::ut::ResDicPatricia ) // GetModels(int idx), GetModels(const char*), GetModelsIndex(const char*), GetModelsCount() NW_RES_FIELD_CLASS_DIC_DECL( ResTexture, Textures, nw::ut::ResDicPatricia ) // GetTextures(int idx), GetTextures(const char*), GetTexturesIndex(const char*), GetTexturesCount() NW_RES_FIELD_CLASS_DIC_DECL( ResLookupTableSet, LutSets, nw::ut::ResDicPatricia ) // GetLutSets(int idx), GetLutSets(const char*), GetLutSetsIndex(const char*), GetLutSetsCount() NW_RES_FIELD_CLASS_DIC_DECL( ResShader, Shaders, nw::ut::ResDicPatricia ) // GetShaders(int idx), GetShaders(const char*), GetShadersIndex(const char*), GetShadersCount() NW_RES_FIELD_CLASS_DIC_DECL( ResCamera, Cameras, nw::ut::ResDicPatricia ) // GetCameras(int idx), GetCameras(const char*), GetCamerasIndex(const char*), GetCamerasCount() NW_RES_FIELD_CLASS_DIC_DECL( ResLight, Lights, nw::ut::ResDicPatricia ) // GetLights(int idx), GetLights(const char*), GetLightsIndex(const char*), GetLightsCount() NW_RES_FIELD_CLASS_DIC_DECL( ResFog, Fogs, nw::ut::ResDicPatricia ) // GetFogs(int idx), GetFogs(const char*), GetFogsIndex(const char*), GetFogsCount() NW_RES_FIELD_CLASS_DIC_DECL( ResSceneEnvironmentSetting, SceneEnvironmentSettings, nw::ut::ResDicPatricia ) // GetSceneEnvironmentSettings(int idx), GetSceneEnvironmentSettings(const char*), GetSceneEnvironmentSettingsIndex(const char*), GetSceneEnvironmentCount() NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, SkeletalAnims, nw::ut::ResDicPatricia ) // GetSkeletalAnims(int idx), GetSkeletalAnims(const char*), GetSkeletalAnimsIndex(const char*), GetSkeletalAnimsCount() NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, MaterialAnims, nw::ut::ResDicPatricia ) // GetMaterialAnims(int idx), GetMaterialAnims(const char*), GetMaterialAnimsIndex(const char*), GetMaterialAnimsCount() NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, VisibilityAnims, nw::ut::ResDicPatricia ) // GetVisibilityAnims(int idx), GetVisibilityAnims(const char*), GetVisibilityAnimsIndex(const char*), GetVisibilityAnimsCount() NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResCameraAnim, CameraAnims, nw::ut::ResDicPatricia ) // GetCameraAnims(int idx), GetCameraAnims(const char*), GetCameraAnimsIndex(const char*), GetCameraAnimsCount() NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResLightAnim, LightAnims, nw::ut::ResDicPatricia ) // GetLightAnims(int idx), GetLightAnims(const char*), GetLightAnimsIndex(const char*), GetLightAnimsCount() NW_RES_FIELD_CLASS_DIC_DECL( anim::res::ResAnim, FogAnims, nw::ut::ResDicPatricia ) // GetFogAnims(int idx), GetFogAnims(const char*), GetFogAnimsIndex(const char*), GetFogAnimsCount() NW_RES_FIELD_CLASS_DIC_DECL( ResParticleEmitter, Emitters, nw::ut::ResDicPatricia ) // GetEmitters(int idx), GetEmitters(const char*), GetEmittersIndex(const char*), GetEmittersCount() //--------------------------------------------------------------------------- //! @brief ファイル中のコンテントの初期化処理をおこないます。 //! コマンドの生成と、引数に与えられたファイルを使用した外部参照解決をおこないます。 //! //! @param[in] allocator アロケータです。 //! @param[in] graphicsFile 参照解決を試みるグラフィックスリソースです。 //! //! @return ファイル内のすべての参照が解決済みの場合には、RESOURCE_RESULT_OK を返します。 //! 未解決の外部参照が残っている場合には、未解決コンテントの種類を示すフラグを返します。 //--------------------------------------------------------------------------- Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile); //--------------------------------------------------------------------------- //! @brief 自分のファイル内で完結した初期化処理をおこないます。 //! //! @param[in] allocator アロケータです。 //! //! @return ファイル内のすべての参照が解決済みの場合には、RESOURCE_RESULT_OK を返します。 //! 未解決の外部参照が残っている場合には、未解決コンテントの種類を示すフラグを返します。 //--------------------------------------------------------------------------- Result Setup(os::IAllocator* allocator) { return this->Setup( allocator, *this ); } //--------------------------------------------------------------------------- //! @brief リソースの解放処理をおこないます。 //! //! @details 他のファイルから参照されているオブジェクトもすべて解放します。 //--------------------------------------------------------------------------- void Cleanup(); // TODO: 参照カウント方式を用意する。 // Result SafeCleanup(); //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResModel を巡回して TFunction を適用します。 //! //! @tparam TFunction ResModel を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //--------------------------------------------------------------------------- template void ForeachModel(TFunction function) { ResModelArray::iterator end = this->GetModels().end(); for (ResModelArray::iterator model = this->GetModels().begin(); model != end; ++model) { function(*model); } } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResModel を巡回して TFunction を適用します。 //! ポインタの特別バージョンです。 //! //! @tparam TFunction ResModel を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //--------------------------------------------------------------------------- template void ForeachModel(TFunction* function) { this->ForeachModel(*function); } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResMaterial を巡回して TFunction を適用します。 //! //! @tparam TFunction ResMaterial を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //--------------------------------------------------------------------------- template void ForeachMaterial(TFunction function) { ResModelArray::iterator end = this->GetModels().end(); for (ResModelArray::iterator model = this->GetModels().begin(); model != end; ++model) { ResMaterialArray::iterator materialEnd = (*model).GetMaterials().end(); for (ResMaterialArray::iterator material = (*model).GetMaterials().begin(); material != materialEnd; ++material) { function(*material); } } } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResMaterial を巡回して TFunction を適用します。 //! ポインタの特別バージョンです。 //! //! @tparam TFunction ResMaterial を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //--------------------------------------------------------------------------- template void ForeachMaterial(TFunction* function) { this->ForeachMaterial(*function); } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResModel, ResMaterial を巡回して TFunction を適用します。 //! //! @tparam TFunction ResModel, ResMaterial を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //--------------------------------------------------------------------------- template void ForeachModelMaterial(TFunction function) { ResModelArray::iterator end = this->GetModels().end(); for (ResModelArray::iterator model = this->GetModels().begin(); model != end; ++model) { ResMaterialArray::iterator materialEnd = (*model).GetMaterials().end(); for (ResMaterialArray::iterator material = (*model).GetMaterials().begin(); material != materialEnd; ++material) { function(*model, *material); } } } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResModel, ResMaterial を巡回して TFunction を適用します。 //! ポインタの特別バージョンです。 //! //! @tparam TFunction ResModel, ResMaterial を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //--------------------------------------------------------------------------- template void ForeachModelMaterial(TFunction* function) { this->ForeachModelMaterial(*function); } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResTexture を巡回して TFunction を適用します。 //! //! @tparam TFunction ResTexture を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //! //! @sa nw::gfx::res::TextureLocationFlagSetter //--------------------------------------------------------------------------- template void ForeachTexture(TFunction function) { ResTextureArray::iterator end = this->GetTextures().end(); for (ResTextureArray::iterator texture = this->GetTextures().begin(); texture != end; ++texture) { function(*texture); } } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResTexture を巡回して TFunction を適用します。 //! ポインタの特別バージョンです。 //! //! @tparam TFunction ResTexture を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //! //! @sa nw::gfx::res::TextureLocationFlagSetter //--------------------------------------------------------------------------- template void ForeachTexture(TFunction* function) { this->ForeachTexture(*function); } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResIndexStream を巡回して TFunction を適用します。 //! //! @tparam TFunction ResIndexStream を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //! //! @sa nw::gfx::res::IndexStreamLocationFlagSetter //--------------------------------------------------------------------------- template void ForeachIndexStream(TFunction function) { ResModelArray::iterator modelsEnd = this->GetModels().end(); for (ResModelArray::iterator model = this->GetModels().begin(); model != modelsEnd ; ++model) { ResShapeArray::iterator shapesEnd = (*model).GetShapes().end(); for (ResShapeArray::iterator shape = (*model).GetShapes().begin(); shape != shapesEnd; ++shape) { ResPrimitiveSetArray::iterator primitiveSetsEnd = (*shape).GetPrimitiveSets().end(); for (ResPrimitiveSetArray::iterator primitiveSet = (*shape).GetPrimitiveSets().begin(); primitiveSet != primitiveSetsEnd; ++primitiveSet) { ResPrimitiveArray::iterator primitivesEnd = (*primitiveSet).GetPrimitives().end(); for (ResPrimitiveArray::iterator primitive = (*primitiveSet).GetPrimitives().begin(); primitive != primitivesEnd; ++primitive) { ResIndexStreamArray::iterator indexStreamsEnd = (*primitive).GetIndexStreams().end(); for (ResIndexStreamArray::iterator indexStream = (*primitive).GetIndexStreams().begin(); indexStream != indexStreamsEnd; ++indexStream) { function(*indexStream); } } } } } } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResIndexStream を巡回して TFunction を適用します。 //! ポインタの特別バージョンです。 //! //! @tparam TFunction ResIndexStream を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //! //! @sa nw::gfx::res::IndexStreamLocationFlagSetter //--------------------------------------------------------------------------- template void ForeachIndexStream(TFunction* function) { this->ForeachIndexStream(*function); } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResVertexStream を巡回して TFunction を適用します。 //! //! @tparam TFunction ResVertexStream を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //! //! @sa nw::gfx::res::VertexStreamLocationFlagSetter //--------------------------------------------------------------------------- template void ForeachVertexStream(TFunction function) { ResModelArray::iterator modelsEnd = this->GetModels().end(); for (ResModelArray::iterator model = this->GetModels().begin(); model != modelsEnd ; ++model) { ResShapeArray::iterator shapesEnd = (*model).GetShapes().end(); for (ResShapeArray::iterator shape = (*model).GetShapes().begin(); shape != shapesEnd; ++shape) { ResSeparateDataShape resSeparateDataShape = ResDynamicCast(*shape); if (resSeparateDataShape.IsValid()) { ResVertexAttributeArray::iterator vertexAttributesEnd = resSeparateDataShape.GetVertexAttributes().end(); for (ResVertexAttributeArray::iterator vertexAttribute = resSeparateDataShape.GetVertexAttributes().begin(); vertexAttribute != vertexAttributesEnd; ++vertexAttribute) { ResVertexStreamBase resVertexStream = ResDynamicCast(*vertexAttribute); if (resVertexStream.IsValid()) { function(resVertexStream); } } } } } } //--------------------------------------------------------------------------- //! @brief ResGraphicsFile 内の全ての ResVertexStream を巡回して TFunction を適用します。 //! ポインタの特別バージョンです。 //! //! @tparam TFunction ResVertexStream を引数に取る関数(オブジェクト)の型です。 //! @param[in] function 適用する関数(オブジェクト)です。 //! //! @sa nw::gfx::res::VertexStreamLocationFlagSetter //--------------------------------------------------------------------------- template void ForeachVertexStream(TFunction* function) { this->ForeachVertexStream(*function); } }; //--------------------------------------------------------------------------- //! @brief テクスチャや頂点データの配置アドレスを設定する関数オブジェクトです。 //! //! @sa nw::gfx::res::ResGraphicsFile::ForeachTexture //! @sa nw::gfx::res::ResGraphicsFile::ForeachIndexStream //! @sa nw::gfx::res::ResGraphicsFile::ForeachVertexStream //--------------------------------------------------------------------------- class TransferedVramAddressSetter { public: TransferedVramAddressSetter(void* fcramImageAddress, void* vramImageAddress) : m_FcramImageAddress(fcramImageAddress), m_VramImageAddress(vramImageAddress) {} //--------------------------------------------------------------------------- //! @brief テクスチャイメージデータに VRAM アドレスを設定します。 //--------------------------------------------------------------------------- void operator()(nw::gfx::ResTexture resTexture) const { // ImageTextureとCubeTextureのときだけloadFlagを設定. switch( resTexture.ref().typeInfo ) { case nw::gfx::ResImageTexture::TYPE_INFO: { nw::gfx::ResImageTexture resImageTexture = nw::gfx::ResStaticCast( resTexture ); nw::gfx::ResPixelBasedImage resImage = resImageTexture.GetImage(); const void* locationAddress = this->GetVramLocation( resImage.GetImageData() ); resImage.SetLocationAddress( locationAddress ); } break; case nw::gfx::ResCubeTexture::TYPE_INFO: { nw::gfx::ResCubeTexture resCubeTexture = nw::gfx::ResStaticCast( resTexture ); for ( int face = 0; face < nw::gfx::ResCubeTexture::MAX_CUBE_FACE; ++face ) { nw::gfx::ResPixelBasedImage resImage = resCubeTexture.GetImage( nw::gfx::ResCubeTexture::CubeFace(face) ); const void* locationAddress = this->GetVramLocation( resImage.GetImageData() ); resImage.SetLocationAddress( locationAddress ); } } break; default: break; } } //--------------------------------------------------------------------------- //! @brief インデックスストリームデータに VRAM アドレスを設定します。 //--------------------------------------------------------------------------- void operator()(nw::gfx::ResIndexStream resIndexStream) const { const void* locationAddress = this->GetVramLocation( resIndexStream.GetStream() ); resIndexStream.SetLocationAddress( locationAddress ); } //--------------------------------------------------------------------------- //! @brief 頂点ストリームデータに VRAM アドレスを設定します。 //--------------------------------------------------------------------------- void operator()(nw::gfx::ResVertexStreamBase resVertexStream) const { const void* locationAddress = this->GetVramLocation( resVertexStream.GetStream() ); resVertexStream.SetLocationAddress( locationAddress ); } private: //--------------------------------------------------------------------------- //! @brief FCRAM 上のアドレスから VRAM 上のアドレスを計算します。 //! //! @param[in] fcramLocation FCRAM 上のアドレスです。 //! //! @return VRAM 上のアドレスを返します。 //--------------------------------------------------------------------------- const void* GetVramLocation(const void* fcramLocation) const { u32 addressOffset = nw::ut::GetOffsetFromPtr( m_FcramImageAddress, fcramLocation ); return nw::ut::AddOffsetToPtr( m_VramImageAddress, addressOffset ); } void* m_FcramImageAddress; void* m_VramImageAddress; }; //--------------------------------------------------------------------------- //! @brief テクスチャ、頂点情報の配置場所を設定する関数オブジェクトです。 //! //! @sa nw::gfx::res::ResGraphicsFile::ForeachTexture //! @sa nw::gfx::res::ResGraphicsFile::ForeachIndexStream //! @sa nw::gfx::res::ResGraphicsFile::ForeachVertexStream //--------------------------------------------------------------------------- class LocationFlagSetter { public: LocationFlagSetter(u32 flag) : m_Flag(flag) {} //--------------------------------------------------------------------------- //! @brief テクスチャのロケーションフラグを設定します。 //--------------------------------------------------------------------------- void operator()(ResTexture resTexture) const { // ImageTextureとCubeTextureのときだけloadFlagを設定. switch( resTexture.ref().typeInfo ) { case ResImageTexture::TYPE_INFO: { ResImageTexture resImageTexture = ResStaticCast( resTexture ); resImageTexture.SetLocationFlag( m_Flag ); } break; case ResCubeTexture::TYPE_INFO: { ResCubeTexture resCubeTexture = ResStaticCast( resTexture ); resCubeTexture.SetLocationFlag( m_Flag ); } break; default: break; } } //--------------------------------------------------------------------------- //! @brief インデックスストリームのロケーションフラグを設定します。 //--------------------------------------------------------------------------- void operator()(ResIndexStream resIndexStream) const { resIndexStream.SetLocationFlag(m_Flag); } //--------------------------------------------------------------------------- //! @brief 頂点ストリームのロケーションフラグを設定します。 //--------------------------------------------------------------------------- void operator()(ResVertexStreamBase resVertexStream) const { resVertexStream.SetLocationFlag(m_Flag); } private: u32 m_Flag; }; //--------------------------------------------------------------------------- //! @brief テクスチャの配置場所を設定する関数オブジェクトです。 //! //! @sa nw::gfx::res::ResGraphicsFile::ForeachTexture //--------------------------------------------------------------------------- typedef LocationFlagSetter TextureLocationFlagSetter; //--------------------------------------------------------------------------- //! @brief インデックスストリームの配置場所を設定する関数オブジェクトです。 //! //! @sa nw::gfx::res::ResGraphicsFile::ForeachIndexStream //--------------------------------------------------------------------------- typedef LocationFlagSetter IndexStreamLocationFlagSetter; //--------------------------------------------------------------------------- //! @brief 頂点バッファの配置場所を設定する関数オブジェクトです。 //! //! @sa nw::gfx::res::ResGraphicsFile::ForeachVertexStream //--------------------------------------------------------------------------- typedef LocationFlagSetter VertexStreamLocationFlagSetter; //--------------------------------------------------------------------------- //! @brief エフェクトリソース内、パーティクルマテリアル使用フラグを設定する関数オブジェクトです。 //! //! @sa nw::gfx::res::ResGraphicsFile::ForeachModelMaterial //--------------------------------------------------------------------------- class ParticleMaterialFlagSetter { public: void operator()(ResModel resModel, ResMaterial resMaterial) const { NW_ASSERT(resMaterial.IsValid()); ut::ResTypeInfo resTypeInfo = resModel.GetTypeInfo(); if (resTypeInfo == nw::gfx::ResParticleModel::TYPE_INFO) { resMaterial.SetFlags(ut::EnableFlag(resMaterial.GetFlags(), nw::gfx::ResMaterialData::FLAG_PARTICLE_MATERIAL_ENABLED)); } } }; //--------------------------------------------------------------------------- //! @brief デフォルトシェーダーでの ShaderProgramDescriptionIndex を設定する関数オブジェクトです。 //! //! @sa nw::gfx::res::ResGraphicsFile::ForeachMaterial //--------------------------------------------------------------------------- class DefaultShaderAutoSelector { public: void operator()(ResModel resModel, ResMaterial resMaterial) const { const char* DEFAULT_SHADER = "DefaultShader"; NW_ASSERT(resMaterial.IsValid()); ut::ResTypeInfo resTypeInfo = resModel.GetTypeInfo(); if (resTypeInfo == ResModel::TYPE_INFO || resTypeInfo == ResSkeletalModel::TYPE_INFO) { ResReferenceShader referenceShader = ResDynamicCast(resMaterial.GetShader()); // HACK: 1.3 で ASSERT に変更します。 // NW_ASSERT(referenceShader.IsValid()); if (referenceShader.IsValid()) { if (::std::strcmp(referenceShader.GetPath(), DEFAULT_SHADER) == 0) { // アクティブなコーディネータの数によって DescriptionIndex を変えます。 s32 activeCoordinatorsCount = resMaterial.GetActiveTextureCoordinatorsCount(); enum { TEXTURE_COUNT_0 = 3, TEXTURE_COUNT_1 = 2, TEXTURE_COUNT_2 = 1, TEXTURE_COUNT_3 = 0 }; const int table[] = { TEXTURE_COUNT_0, TEXTURE_COUNT_1, TEXTURE_COUNT_2, TEXTURE_COUNT_3 }; resMaterial.SetShaderProgramDescriptionIndex(table[activeCoordinatorsCount]); } } } } }; } // namespace res } // namespace gfx } // namespace nw #endif // NW_GFX_RESGRAPHICSFILE_H_