/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ResLookupTable.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 namespace nw { namespace gfx { namespace res { typedef void (*ActivateFunc)(ResTexture resTex, RenderContext& context); typedef void (*CleanupFunc)(ResLookupTable resLut); typedef Result (*SetupFunc)(ResLookupTable resLut); static void ResImageLut_Cleanup(ResLookupTable resLut); static void ResReferenceLut_Cleanup(ResLookupTable resLut); static Result ResImageLut_Setup(ResLookupTable resLut); static Result ResReferenceLut_Setup(ResLookupTable resLut); static SetupFunc s_LutSetupTable[] = { ResImageLut_Setup, ResReferenceLut_Setup }; static CleanupFunc s_LutCleanupTable[] = { ResImageLut_Cleanup, ResReferenceLut_Cleanup }; //---------------------------------------- static Result ResImageLut_Setup(ResLookupTable resLut) { Result result = RESOURCE_RESULT_OK; NW_UNUSED_VARIABLE(resLut); return result; } //---------------------------------------- static Result ResReferenceLut_Setup(ResLookupTable resLut) { Result result = RESOURCE_RESULT_OK; result |= ResImageLut_Setup(resLut.Dereference()); return result; } //---------------------------------------- static void ResImageLut_Cleanup(ResLookupTable resLut) { ResImageLookupTable imageLut = ResStaticCast( resLut ); GraphicsDevice::InvalidateLookupTable(imageLut); } //---------------------------------------- static void ResReferenceLut_Cleanup(ResLookupTable resLut) { ResReferenceLookupTable referLut = ResStaticCast( resLut ); NW_ASSERT(resLut.IsValid()); referLut.ref().toTargetLut.set_ptr(NULL); } //---------------------------------------------------------------------------- Result ResLookupTable::Setup() { NW_ASSERT( this->IsValid() ); Result result = RESOURCE_RESULT_OK; switch ( this->ref().typeInfo ) { case ResImageLookupTable::TYPE_INFO: { result |= s_LutSetupTable[0]( *this ); } break; case ResReferenceLookupTable::TYPE_INFO: { result |= s_LutSetupTable[1]( *this ); } break; default: { NW_FATAL_ERROR("Unsupported lut type."); } } return result; } //---------------------------------------- void ResLookupTable::Cleanup() { switch ( this->ref().typeInfo ) { case ResImageLookupTable::TYPE_INFO: { s_LutCleanupTable[0]( *this ); } break; case ResReferenceLookupTable::TYPE_INFO: { s_LutCleanupTable[1]( *this ); } break; default: { NW_FATAL_ERROR("Unsupported lut type."); } } } //---------------------------------------- void ResReferenceLookupTable::ForceSetup(ResLookupTable lut) { NW_ASSERT(lut.IsValid()); ref().toTargetLut.set_ptr(lut.ptr()); ResReferenceLut_Setup(*this); } //---------------------------------------- void ResReferenceLookupTable::ForceSetup(const char* targetName, ResLookupTable lut) { NW_NULL_ASSERT(targetName); if (std::strcmp(targetName, this->GetPath()) == 0) { this->ForceSetup(lut); } } //---------------------------------------- Result ResLookupTableSet::Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile) { NW_UNUSED_VARIABLE(allocator); NW_UNUSED_VARIABLE(graphicsFile); NW_ASSERT( internal::ResCheckRevision( *this ) ); Result result = RESOURCE_RESULT_OK; s32 samplerNum = this->GetSamplersCount(); for ( int i = 0; i < samplerNum; ++i ) { result |= this->GetSamplers( i ).Setup(); } return result; } //---------------------------------------- void ResLookupTableSet::Cleanup() { ut::SafeCleanupAll(this->GetSamplers()); } } /* namespace res */ } /* namespace gfx */ } /* namespace nw */