
//**************************************************************************/
// 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>
#include <Mudbox/MudBoxGL.h>
#else
#include "../../include/Mudbox/mudbox.h"
#include "../../include/Mudbox/MudBoxGL.h"
#endif

#include <Cg/cg.h>
#include <Cg/cgGL.h>
using namespace mudbox;

class ToonMaterial : public Material
{
	// RTTI macro.
	DECLARE_CLASS;

public:
	/// <description>
	/// Constructor
	/// </desription>
	ToonMaterial( void );

	/// <description>
	/// Destructor
	/// </description>
	~ToonMaterial( void );

	// The following public functions are overrides

	/// <description>
	/// Sets material settings prior to actual render.
	/// </description>
	/// <remarks>
	/// If a shader is used this calls the necessary bind functions & sets
	/// shader parameters.
	/// </remarks>
	/// <param name="pMesh">Mesh to be rendered.</param>
	/// <param name="cUVArea">UV area to be rendered.  UV tiling works by having UVs > 1.</param>
	/// <param name="cColor"></param>
	/// <returns>Return true if success.</returns>
	bool Activate( const Mesh *pMesh, const AxisAlignedBoundingBox &cUVArea, const Color &cColor );

	/// <description>
	/// Calls any clean up functions that occur after the render but before the swap.
	/// </description>
	void Deactivate( void );

	/// <description>
	/// Attribute changed callback.
	/// </description>
	/// <remarks>
	/// Gets called when class attributes are modified.
	/// </remarks>
	/// <param name="cAttribute">Attribute modified.</param>
	/// <param name="cType">Event type.</param>
	void OnNodeEvent( const Attribute &cAttribute, NodeEventType cType );

	/// <description>
	/// Returns true or false if this material requires texture coordinates.
	/// </description>
	/// <remarks>
	/// If this returns true then Mudbox will provide texture coordinates for
	/// the mesh to be rendered.
	/// </remarks>
	bool IsTCNeeded( void ) const { return true; };

private:

	// Cg vertex & pixel shaders
    CGprogram m_VertexProgram;
    CGprogram m_FragmentProgram;

	// Cg context
    CGcontext m_CGContext;

	// Profiles used for this shader
    CGprofile m_FragmentProfile;
    CGprofile m_VertexProfile;

	// Cg shader parameters, used to set values on shader
	CGparameter m_LightPositionParam;
	CGparameter m_EyePositionParam;
	CGparameter m_ShininessParam;
	CGparameter m_ModelViewProjParam;

	CGparameter m_KdParam;
	CGparameter m_KsParam;
	CGparameter m_DiffuseRampParam;
	CGparameter m_SpecularRampParam;
	CGparameter m_EdgeRampParam;

	// OpenGL texture IDs
	GLuint m_iDiffuseRamp;
	GLuint m_iSpecularRamp;
	GLuint m_iEdgeRamp;

	// Any variables with 'a' in front of them indicate a Qt attribute.
	// They will automatically be added to the UI for this material.
	// Diffuse
	acolor m_aKd; // color picker
	// Specular
	acolor m_aKs; // color picker
	// Shininess
	afloatr m_aShininess; // range slider
};
