/*
	Trampoline Sim.
	Copyright (c) 2009, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef DISPLAY_EVICTABLE_H
#define DISPLAY_EVICTABLE_H

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================

	class Display;
	
	//=================================================================================================================
	/// @brief		This is a base class for all graphics resources that can have their resources lost when the graphics
	///				device resets. These include render targets, vertex buffers, index buffers and state blocks.
	///				The display maintains an internal list of these resources and asks each evicted resource to 
	///				firstly release itself (before a device reset) and then to recreate it's resources after a device
	///				has successfully been regained.
	//=================================================================================================================

	class DisplayEvictable : public ObjectBase
	{
		public:	

			//=========================================================================================================
			// Functions
			//=========================================================================================================

				/// Creates the resource that can be evicted by the graphics display 
				
				DisplayEvictable( Display * parent_display );
				
				/// Destroys the evictable resource 
				
				virtual ~DisplayEvictable();

				/// Returns the display this graphics resource belongs to

				inline Display * GetDisplay(){ return m_display; }
				
				/// Tells the resource to release all it's resources upon the graphics device being lost: only the display should call this! 
				
				virtual void ReleaseEvictableResources() = 0;
				
				/// Tells the resource to recreate all it's resources upon the graphics device being recreated: only the display should call this! 
				
				virtual void RecreateEvictableResources() = 0;
				
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				/// Tells if this resource is valid and can be used. If not no attempt should be made to use the resource 
				/// or to release it's resources (since it has none to release) .. 
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				
				inline bool IsValid(){ return m_is_valid; }
				
		protected:				

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// True if the resource has been successfully created. If 
				
				bool m_is_valid;

		private:
		
			//=========================================================================================================
			// Friends
			//=========================================================================================================
			
				/// The display is a friend class of this and needs private access
			
				friend class Display;

			//=========================================================================================================
			// Functions
			//=========================================================================================================

				/// Copying is not allowed

				DisplayEvictable( Display & );

				/// Copying is not allowed

				DisplayEvictable & operator = ( DisplayEvictable & );

			//=============================================================================================================
			// Variables
			//=============================================================================================================

				/// Display this resource belongs to
				
				Display * m_display;
				
				/// Next evictable resource in the list of evictable resources in the display
				
				DisplayEvictable * m_evictable_next;
				
				/// Previous evictable resource in the list of evictable resources in the display
				
				DisplayEvictable * m_evictable_prev;	
	};

};

#endif 