/*
 * Copyright (C) 2003-2004, 2012 Clemens Fuchslocher
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 */

#include <GL/gl.h>
#include <GL/glu.h>

#include <cstdlib>
#include <map>

#include "SceneGraphVisitor.h"
#include "VertexArray.h"
#include "Utility.h"


namespace nsSceneGraph {

VertexArray::VertexArray(void) : GraphNode(VERTEXARRAY, "VERTEXARRAY")
{
	DEBUG_MESSAGE("VertexArray::VertexArray()")

	this->normalPerVertex = false;
}


VertexArray::~VertexArray(void)
{
	DEBUG_MESSAGE("VertexArray::~VertexArray()")

	if (this->isNodeCompiled())
	{
		glDeleteLists(this->getCompiledDisplayList(), 1);
	}
}


void VertexArray::addVertexArrayEntry(double x, double y, double z)
{
	this->vertexArray.push_back(Vertex3F(x, y, z));
}


void VertexArray::addVertexIndexEntry(int a, int b, int c)
{
	this->vertexIndex.push_back(Index3I(a, b, c));
}


void VertexArray::addNormalArrayEntry(double x, double y, double z)
{
	this->normalArray.push_back(Vector3F(x, y, z));
}


void VertexArray::addNormalIndexEntry(int a, int b, int c)
{
	this->normalIndex.push_back(Index3I(a, b, c));
}


void VertexArray::setNormalPerVertex(bool status)
{
	this->normalPerVertex = status;
}


std::vector<Vertex3F> VertexArray::getVertexArray(void)
{
	return this->vertexArray;
}


std::vector<Index3I> VertexArray::getVertexIndex(void)
{
	return this->vertexIndex;
}


int VertexArray::action(SceneGraphVisitor *visitor)
{
	DEBUG_MESSAGE("VertexArray::accept()")

	visitor->visit(this);

	GraphNode::action(visitor);

	return SG_OK;
}


GraphNode *VertexArray::duplicate(void)
{
	std::cerr << __FILE__ << '[' << __LINE__ << "]: VertexArray::duplicate() isn't implemented yet." << std::endl;
	std::exit(SG_KO);

	return NULL;
}


}

