/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ResModel.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: $ *---------------------------------------------------------------------------*/ #include "../precompiled.h" #include #include #include #include #include #include #include #include #include #include namespace nw { namespace gfx { namespace res { //---------------------------------------------------------------------------- Result ResModel::Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile) { Result result = RESOURCE_RESULT_OK; NW_ASSERT( this->IsValid() ); NW_ASSERT( internal::ResCheckRevision( *this ) ); NW_ASSERT( internal::ResCheckRevision( graphicsFile ) ); s32 shapeNum = this->GetShapesCount(); for ( int i = 0; i < shapeNum; ++i ) { if (!ut::CheckFlag(this->GetShapes(i).GetFlags(), ResShape::FLAG_HAS_BEEN_SETUP)) { result |= this->GetShapes( i ).Setup(allocator); } } s32 materialNum = this->GetMaterialsCount(); for ( int i = 0; i < materialNum; ++i ) { if (!ut::CheckFlag(this->GetMaterials( i ).GetFlags(), ResMaterialData::FLAG_HAS_BEEN_SETUP)) { result |= this->GetMaterials( i ).Setup(allocator, graphicsFile); } } #if defined(NW_CALL_DRAW_ELEMENTS_MANUALLY) // シェーダーの参照解決が終わるまでは頂点用のコマンド生成ができない。 if ( (result.GetDescription() & RESOURCE_RESULT_NOT_FOUND_SHADER) == 0 ) { // 各メッシュに対して、頂点アトリビュートの設定コマンドを生成する。 s32 meshNum = this->GetMeshesCount(); for ( int i = 0; i < meshNum; ++ i ) { ResMesh mesh = this->GetMeshes( i ); if (!ut::CheckFlag(mesh.GetFlags(), ResMesh::FLAG_HAS_BEEN_SETUP)) { mesh.Setup( *this, allocator, graphicsFile ); } } } #endif return result; } //---------------------------------------------------------------------------- void ResModel::Cleanup() { s32 shapeNum = this->GetShapesCount(); for ( int i = 0; i < shapeNum; ++i ) { if (ut::CheckFlag(this->GetShapes(i).GetFlags(), ResShape::FLAG_HAS_BEEN_SETUP)) { this->GetShapes( i ).Cleanup(); } } s32 materialNum = this->GetMaterialsCount(); for ( int i = 0; i < materialNum; ++i ) { this->GetMaterials( i ).Cleanup(); } s32 meshNum = this->GetMeshesCount(); for ( int i = 0; i < meshNum; ++ i ) { this->GetMeshes( i ).Cleanup(); } } //---------------------------------------------------------------------------- void ResModel::ForceSetupTexture(const char* targetName, ResTexture texture) { NW_ASSERT(texture.IsValid()); NW_NULL_ASSERT(targetName); const int materialNum = GetMaterialsCount(); for (int idx = 0; idx < materialNum; ++idx) { ResMaterial material = GetMaterials(idx); if (material.IsValid()) { material.ForceSetupTexture(targetName, texture); } } } //---------------------------------------------------------------------------- void ResModel::ForceSetupShader(const char* targetName, ResShader shader) { NW_ASSERT(shader.IsValid()); NW_NULL_ASSERT(targetName); const int materialNum = GetMaterialsCount(); for (int idx = 0; idx < materialNum; ++idx) { ResMaterial material = GetMaterials(idx); if (material.IsValid()) { material.ForceSetupShader(targetName, shader); } } } //---------------------------------------------------------------------------- void ResModel::ForceSetupLookupTable(const char* targetName, ResLookupTable lut) { NW_ASSERT(lut.IsValid()); NW_NULL_ASSERT(targetName); const int materialNum = GetMaterialsCount(); for (int idx = 0; idx < materialNum; ++idx) { ResMaterial material = GetMaterials(idx); if (material.IsValid()) { material.ForceSetupLookupTable(targetName, lut); } } } } /* namespace res */ } /* namespace gfx */ } /* namespace nw */