//********************************************************************
// Ninfa3D Engine 
// copyright 2008-2009
// By Viz_Fuerte
// VC: 9.0
// CShaderSceneNode.cpp
//********************************************************************

/*--------------------------------------------------------------------
Includos*/

	#include "CShaderSceneNode.h"

/*--------------------------------------------------------------------
Variables externas*/

	extern IrrlichtDevice* device;
	extern IVideoDriver* driver;
	extern ISceneManager* SceneManager;

/*--------------------------------------------------------------------
Declaracion global de funciones*/

	CShaderCallBack::CShaderCallBack()
	{
		VertexConstantList = NULL;
		PixelConstantList = NULL;
	}

	CShaderCallBack::~CShaderCallBack()
	{
		tConstant *delete_object;

		// delete all of the vertex constants;
		tConstant *current_object = VertexConstantList;
		while ( current_object )
		{
			delete_object = current_object;
			current_object = current_object->next;
			delete delete_object;
		}

		// delete all of the pixel constants
		current_object = PixelConstantList;
		while ( current_object )
		{
			delete_object = current_object;
			current_object = current_object->next;
			delete delete_object;
		}
	}

	void CShaderCallBack::OnSetConstants(IMaterialRendererServices* services,s32 id)
	{
		const char* name = "";
		const float* values = NULL;
		int count = 0;

		tConstant* current_constant = VertexConstantList;

		while(current_constant)
		{
			values = current_constant->data;
			count  = current_constant->count;
			name   = current_constant->name;

			services->setVertexShaderConstant(name,values,count);

			current_constant = current_constant->next;
		}

		current_constant = PixelConstantList;

		while(current_constant)
		{
			values = current_constant->data;
			count  = current_constant->count;
			name   = current_constant->name;

			services->setPixelShaderConstant(name,values,count);

			current_constant = current_constant->next;
		}
	}