
//**************************************************************************/
// 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

using namespace mudbox;

// Fixed function material plugin.  Uses the hardware's fixed function pipeline
// to render lighting & materials.  This is derived off the 'Material' base class
// that is used by Mudbox to manipulate materials.

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

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

	/// <description>
	/// Destructor
	/// </description>
	~FixedFunctionMaterial( 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:
	/// <description>
	/// Texture filename attribute.
	/// </description>
	atexturefilename m_sTexture;

	/// <description>
	/// Diffuse component.
	/// </description>
	acolor m_cDiffuse;

	/// <description>
	/// Specular component.
	/// </description>
	acolor m_cSpecular;

	/// <description>
	/// Emissive component.
	/// </description>
	acolor m_cEmissive;

	/// <description>
	/// Shiny.
	/// </description>
	afloatr m_fShiny;

	/// <description>
	/// Mudbox texture container.
	/// </description>
	TexturePool *m_pTexturePool;

	/// <description>
	/// Diffuse texture ID.
	/// </description>
	GLuint m_iDiffuseTexture;

	/// <description>
	/// Small diffuse texture.
	/// </description>
	GLubyte m_pDiffuseTexture[3];
};
