
//**************************************************************************/
// Copyright (c) 2008 Autodesk, Inc.
// All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk license
// agreement provided at the time of installation or download, or which
// otherwise accompanies this software in either electronic or hard copy form.
//
//**************************************************************************/
// DESCRIPTION:
// CREATED: October 2008
//**************************************************************************/

#if defined(JAMBUILD)
#include <Mudbox/mudbox.h>
#else
#include "../../include/Mudbox/mudbox.h"
#endif

#include <Cg/cg.h>
#include <Cg/cgGL.h>

#include <vector>

using namespace mudbox;

class SampleViewPortFilter : public ViewPortFilter 
{
public:

	DECLARE_CLASS;

	/// <description>
	/// Constructor
	/// </desription>
	SampleViewPortFilter();

	/// <description>
	/// Destructor
	/// </description>
	~SampleViewPortFilter();

	/// <description>
	/// Mudbox calls this to enable/disable filter.
	/// </description>
	/// <remarks>
	/// </remarks>
	/// <param name="bVisible">True = On, False = off.</param>
	void SetVisible( bool bVisible );

	/// <description>
	/// Mudbox call to check filter requirements.
	/// </description>
	/// <remarks>
	/// ePosition = position texture is created
	/// eNormal = normal texture is created
	/// eHDR = 32 bit float buffer required
	/// </remarks>
	RequirementValue Requirement( void ) const { return eHDR | ePosition32 | eNormal16; };

	/// <description>
	/// Activation call.
	/// </description>
	/// <remarks>
	/// Called after the main render but prior to the show buffer.
	/// ViewportState contains the following buffers (filled based on requirements)
	/// Texture *m_pColor;
	/// Texture *m_pDepth;
	/// Texture *m_pPosition;
	/// Texture *m_pNormal;
	/// </remarks>
	void Process( ViewPortState & );

	/// <description>
	/// Returns filter name.
	/// </description>
	/// <remarks>
	/// </remarks>
	virtual QString Name( const ClassDesc * ) const { return "Sample Filter"; };
	
	/// <description>
	/// Event callback.  Generally called when UI attributes are changed.
	/// </description>
	/// <remarks>
	/// </remarks>
	void OnNodeEvent(const Attribute &cAttribute, NodeEventType eType);

private:
	CGcontext m_CGContext;

	Texture* m_pResultTexture;

	CGprogram m_BlurProgram;

	CGprofile m_FragmentProfile;

	CGparameter m_BlurColorTextureParam;
	CGparameter m_BlurWidthParam;
	CGparameter m_GaussianBlurParam;

	abool m_aGaussianBlur;
	afloatr m_aBlurWidth;
};
