/*
	Trig Wars.
	Copyright (c) 2008, 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 GAME_POST_FX_H
#define GAME_POST_FX_H

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

#include "Graphics\VertexFormat.h"
#include "Graphics\VertexShader.h"
#include "Graphics\PixelShader.h"

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

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================
	
	class Display;
	class RenderTarget;
	class DepthBuffer;

	//=================================================================================================================
	/// @brief		This class does post screen processing (the glow effect) for the game. It handles render targets
	///				and everything else.
	//=================================================================================================================

	class GamePostFX : public ObjectBase
	{
		public:		
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Creates the post processing fx unit
				
				GamePostFX( Display * display , VertexShaderManager * vs_mgr , PixelShaderManager * ps_mgr );
				
				/// Destroys the post processing fx unit
				
				~GamePostFX();
				
				/// Begins post processing effects. Routes all rendering into an internal render target.
				
				void BeginPostProcessing();
				
				/// Ends post processing effects. Displays output of render target output plus effects to the screen.
				
				void EndPostProcessing();
				
				/// Tells the object to announce it's type name: this is the type name without the Game:: namespace

				virtual const char * GetTypeName() const;				
				
		private:
		
			//=========================================================================================================
			// Structs
			//=========================================================================================================
			
				/// Vertex format the post processor uses
				
				struct Vertex
				{
					/// Position of the vertex
					
					Vec3f m_pos;
					
					/// Color of the vertex
					
					Color m_col;
					
					/// Texture coordinate of the vertex
					
					Vec2f m_tex;
				};
		
			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// Vertices used for rendering
				
				Vertex m_vertices[4];
			
				/// Render target that the game is rendered into
				
				RenderTarget * m_game_target;

				/// Render target that the glow effect is accumalted into: this is fairly small

				RenderTarget * m_glow_target;
				
				/// Depth buffer that the game uses when it's being rendererd into the render target
				
				DepthBuffer * m_game_depth_buffer;

				/// Depth buffer is used when the glow effect is being rendered

				DepthBuffer * m_glow_depth_buffer;
				
				/// Display that the post processor uses
				
				Display * m_display;
				
				/// Vertex format used by the post processor
				
				VertexFormat m_vf;				
				
				/// Pixel shader used to apply post processing
				
				PixelShader m_glow_ps;
				
				/// Vertex shader used to draw results to the screen
				
				VertexShader m_textured_vs;
				
				/// Pixel shader used to draw results to the screen
				
				PixelShader m_textured_ps;
				
				/// Transform uniform variable on the vertex shader
				
				ShaderUniform m_u_transform;
				
				/// Size of the glow kernel for the glow effect
				
				ShaderUniform m_u_glow_kernel;
				
				/// True if the resources used by this are valid
				
				bool m_valid_resources;
	};
}

#endif
