/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ResLookupTable.cpp 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: 17861 $ *---------------------------------------------------------------------------*/ #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) { NW_UNUSED_VARIABLE(resLut); NW_ASSERT(resLut.IsValid()); } //---------------------------------------------------------------------------- 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."); } } } //---------------------------------------- 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 */