baseMatInstance.cpp
Engine/source/materials/baseMatInstance.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "materials/baseMatInstance.h" 26 27#include "core/util/safeDelete.h" 28 29 30BaseMatInstance::~BaseMatInstance() 31{ 32 deleteAllHooks(); 33} 34 35void BaseMatInstance::addHook( MatInstanceHook *hook ) 36{ 37 AssertFatal( hook, "BaseMatInstance::addHook() - Got null hook!" ); 38 39 const MatInstanceHookType &type = hook->getType(); 40 41 while ( mHooks.size() <= type ) 42 mHooks.push_back( NULL ); 43 44 delete mHooks[type]; 45 mHooks[type] = hook; 46} 47 48MatInstanceHook* BaseMatInstance::getHook( const MatInstanceHookType &type ) const 49{ 50 if ( type >= mHooks.size() ) 51 return NULL; 52 53 return mHooks[ type ]; 54} 55 56void BaseMatInstance::deleteHook( const MatInstanceHookType &type ) 57{ 58 if ( type >= mHooks.size() ) 59 return; 60 61 delete mHooks[ type ]; 62 mHooks[ type ] = NULL; 63} 64 65U32 BaseMatInstance::deleteAllHooks() 66{ 67 U32 deleteCount = 0; 68 69 Vector<MatInstanceHook*>::iterator iter = mHooks.begin(); 70 for ( ; iter != mHooks.end(); iter++ ) 71 { 72 if ( *iter ) 73 { 74 delete (*iter); 75 (*iter) = NULL; 76 ++deleteCount; 77 } 78 } 79 80 return deleteCount; 81} 82