/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ResFragmentShader.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: 14970 $ *---------------------------------------------------------------------------*/ #include "../precompiled.h" #include #include #include namespace nw { namespace gfx { namespace res { //---------------------------------------------------------------------------- Result ResFragmentShader::Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile) { NW_ASSERT( this->IsValid() ); Result result = RESOURCE_RESULT_OK; ResFragmentLightingTable resFragmentLightingTable = this->GetFragmentLightingTable(); result |= resFragmentLightingTable.Setup(allocator, graphicsFile); // FragmentLightingのEnableフラグとレイヤ・コンフィグに沿って参照テーブルが配置されているかチェックします。 if (!this->CheckFragmentShader()) { result |= RESOURCE_RESULT_IRRELEVANT_LOCATION_LUT; } return result; } //---------------------------------------------------------------------------- Result ResFragmentLightingTable::Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile) { NW_UNUSED_VARIABLE(allocator); NW_ASSERT( this->IsValid() ); Result result = RESOURCE_RESULT_OK; if (this->GetDistribution0Sampler().IsValid()) { ResReferenceLookupTable resReferenceLut = ResDynamicCast(this->GetDistribution0Sampler().GetSampler()); Result referenceResult = SetupReferenceLut(resReferenceLut, graphicsFile); if (referenceResult.IsSuccess()) { result |= this->GetDistribution0Sampler().GetSampler().Setup(); } result |= referenceResult; } if (this->GetDistribution1Sampler().IsValid()) { ResReferenceLookupTable resReferenceLut = ResDynamicCast(this->GetDistribution1Sampler().GetSampler()); Result referenceResult = SetupReferenceLut(resReferenceLut, graphicsFile); if (referenceResult.IsSuccess()) { result |= this->GetDistribution1Sampler().GetSampler().Setup(); } result |= referenceResult; } if (this->GetReflectanceRSampler().IsValid()) { ResReferenceLookupTable resReferenceLut = ResDynamicCast(this->GetReflectanceRSampler().GetSampler()); Result referenceResult = SetupReferenceLut(resReferenceLut, graphicsFile); if (referenceResult.IsSuccess()) { result |= this->GetReflectanceRSampler().GetSampler().Setup(); } result |= referenceResult; } if (this->GetReflectanceGSampler().IsValid()) { ResReferenceLookupTable resReferenceLut = ResDynamicCast(this->GetReflectanceGSampler().GetSampler()); Result referenceResult = SetupReferenceLut(resReferenceLut, graphicsFile); if (referenceResult.IsSuccess()) { result |= this->GetReflectanceGSampler().GetSampler().Setup(); } result |= referenceResult; } if (this->GetReflectanceBSampler().IsValid()) { ResReferenceLookupTable resReferenceLut = ResDynamicCast(this->GetReflectanceBSampler().GetSampler()); Result referenceResult = SetupReferenceLut(resReferenceLut, graphicsFile); if (referenceResult.IsSuccess()) { result |= this->GetReflectanceBSampler().GetSampler().Setup(); } result |= referenceResult; } if (this->GetFresnelSampler().IsValid()) { ResReferenceLookupTable resReferenceLut = ResDynamicCast(this->GetFresnelSampler().GetSampler()); Result referenceResult = SetupReferenceLut(resReferenceLut, graphicsFile); if (referenceResult.IsSuccess()) { result |= this->GetFresnelSampler().GetSampler().Setup(); } result |= referenceResult; } return result; } //---------------------------------------- bool ResFragmentShader::CheckFragmentShader() { bool isExisted = true; ResFragmentLighting fragmentLighting = this->GetFragmentLighting(); ResFragmentLightingTable fragmentLightingTable = this->GetFragmentLightingTable(); s32 flags = fragmentLighting.GetFlags(); if ( ut::CheckFlag(flags, ResFragmentLightingData::FLAG_DISTRIBUTION0_ENABLED) && (!fragmentLightingTable.GetDistribution0Sampler().IsValid() || !fragmentLightingTable.GetDistribution0Sampler().GetSampler().IsValid())) { flags = ut::DisableFlag(flags, ResFragmentLightingData::FLAG_DISTRIBUTION0_ENABLED); NW_WARNING(false, "Distribution0 is enable, but LUT is not found."); isExisted = false; } if ( ut::CheckFlag(flags, ResFragmentLightingData::FLAG_DISTRIBUTION1_ENABLED) && (!fragmentLightingTable.GetDistribution1Sampler().IsValid() || !fragmentLightingTable.GetDistribution1Sampler().GetSampler().IsValid())) { flags = ut::DisableFlag(flags, ResFragmentLightingData::FLAG_DISTRIBUTION1_ENABLED); NW_WARNING(false, "Distribution1 is enable, but LUT is not found."); isExisted = false; } if ( fragmentLighting.GetFresnelConfig() != ResFragmentLighting::CONFIG_NO_FRESNEL && (!fragmentLightingTable.GetFresnelSampler().IsValid() || !fragmentLightingTable.GetFresnelSampler().GetSampler().IsValid())) { fragmentLighting.SetFresnelConfig(ResFragmentLighting::CONFIG_NO_FRESNEL); NW_WARNING(false, "Fresnel is enable, but LUT is not found."); isExisted = false; } if ( ut::CheckFlag(flags, ResFragmentLightingData::FLAG_REFLECTION_ENABLED) ) { ResFragmentLighting::ConfigDetail config = ResFragmentLighting::ToConfigDetail(fragmentLighting.GetLayerConfig()); bool invalid = false; if ( ut::CheckFlag(config, ResFragmentLighting::LUT_RR) && (!fragmentLightingTable.GetReflectanceRSampler().IsValid() || !fragmentLightingTable.GetReflectanceRSampler().GetSampler().IsValid())) { invalid = true; } if ( ut::CheckFlag(config, ResFragmentLighting::LUT_RG) && (!fragmentLightingTable.GetReflectanceGSampler().IsValid() || !fragmentLightingTable.GetReflectanceGSampler().GetSampler().IsValid())) { invalid = true; } if ( ut::CheckFlag(config, ResFragmentLighting::LUT_RB) && (!fragmentLightingTable.GetReflectanceBSampler().IsValid() || !fragmentLightingTable.GetReflectanceBSampler().GetSampler().IsValid())) { invalid = true; } if ( invalid ) { flags = ut::DisableFlag(flags, ResFragmentLightingData::FLAG_REFLECTION_ENABLED); NW_WARNING(false, "Relection is enable, but LUT is not found.\n"); isExisted = false; } } fragmentLighting.SetFlags(flags); return isExisted; } //---------------------------------------------------------------------------- void ResFragmentShader::Cleanup() { ut::SafeCleanup(this->GetFragmentLightingTable()); } //---------------------------------------------------------------------------- void ResFragmentLightingTable::Cleanup() { ut::SafeCleanup(this->GetReflectanceRSampler()); ut::SafeCleanup(this->GetReflectanceGSampler()); ut::SafeCleanup(this->GetReflectanceBSampler()); ut::SafeCleanup(this->GetDistribution0Sampler()); ut::SafeCleanup(this->GetDistribution1Sampler()); ut::SafeCleanup(this->GetFresnelSampler()); } } /* namespace res */ } /* namespace gfx */ } /* namespace nw */