/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: src/sgx/graphics/primitives.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/graphics/graphics.hpp"

void 
CSGXGraphicsEngine::setPrimitiveMode(const tPrimitiveMode &mode)
{
	m_PrimitiveMode.setState(mode);
}

tPrimitiveMode 
CSGXGraphicsEngine::getPrimitiveMode() const 
{
	return m_PrimitiveMode.getState();
}

void 
CSGXGraphicsEngine::drawPrimitiveCuboid(const CSGXTexture **pTextures, const sgxMatrix43 &transform, const sgxVector3 &minpos, const sgxVector3 &maxpos)
{
	m_RenderMode.Apply(SGX_RENDERMODE_3D);

	SGX_UNUSED(pTextures);
	SGX_UNUSED(transform);
	SGX_UNUSED(minpos);
	SGX_UNUSED(maxpos);

}

void 
CSGXGraphicsEngine::drawPrimitiveCuboid(const sgxGfxCuboid &cuboid, const sgxMatrix43 &transform)
{
	m_RenderMode.Apply(SGX_RENDERMODE_3D);

	const sgxColorRGBA &col = m_PrimitiveColor.getState();
	if (isAlphaSortable(col)) {
		addAlphaSorter(cuboid, transform);
	} else {
		drawPrimitiveCuboidImpl(cuboid, transform);
	}
}

void 
CSGXGraphicsEngine::drawPrimitiveCuboidImpl(const sgxGfxCuboid &cuboid, const sgxMatrix43 &transform)
{
	SGX_UNUSED(cuboid);
	SGX_UNUSED(transform);
}

void 
CSGXGraphicsEngine::drawPrimitiveSphere(const sgxGfxSphere &sphere, const sgxMatrix43 &transform)
{
	m_RenderMode.Apply(SGX_RENDERMODE_3D);

	const sgxColorRGBA &col = m_PrimitiveColor.getState();

	if (isAlphaSortable(col)) {
		CSGXGraphicsEngine::get()->addAlphaSorter(sphere, transform);
	} else {
		drawPrimitiveSphereImpl(sphere, transform);
	}
}

void 
CSGXGraphicsEngine::drawPrimitiveSphereImpl(const sgxGfxSphere &sphere, const sgxMatrix43 &transform)
{
	m_RenderMode.Apply(SGX_RENDERMODE_3D);
	SGX_UNUSED(sphere);
	SGX_UNUSED(transform);
}

void 
CSGXGraphicsEngine::drawLine3D(const sgxVector3 &from, const sgxVector3 &to)
{
	m_RenderMode.Apply(SGX_RENDERMODE_3D);
	SGX_UNUSED(from);
	SGX_UNUSED(to);
}

void 
CSGXGraphicsEngine::drawTriStrip(const CSGXTexture	*pTexture, const sgxVector<sgxPolyVtx> &vtx)
{
	m_RenderMode.Apply(SGX_RENDERMODE_3D);
	SGX_UNUSED(pTexture);
	SGX_UNUSED(vtx);
}

void 
CSGXGraphicsEngine::drawQuadStrip(const CSGXTexture *pTexture, const sgxVector<sgxPolyVtx> &vtx)
{
	m_RenderMode.Apply(SGX_RENDERMODE_3D);

	SGX_UNUSED(pTexture);
	SGX_UNUSED(vtx);
}



void sgxGfxCuboid::setCuboidColor(const sgxColorRGB &col)
{
	for(int fl=0;fl<6*4;++fl) {
		face[fl/4].color[fl%4].r = col.r;
		face[fl/4].color[fl%4].g = col.g;
		face[fl/4].color[fl%4].b = col.b;
	}
}

void sgxGfxCuboid::setCuboidAlpha(const tREAL32 &alpha)
{
	for(int fl=0;fl<6*4;++fl) {
		face[fl/4].color[fl%4].a = alpha;
	}
}

void sgxGfxCuboid::setCuboidTexture(const CSGXTexture *pTexture)
{
	for(int f=0;f<6;++f) {
		face[f].pTexture = pTexture;
		// TODO: import textures through XML file which can
		// describe regions
		// TODO: Support regions textures for cuboid data
		//if (pTexture->GetNumRegions()
	}
}

void sgxGfxCuboid::setCuboidColor(const sgxColorRGBA &col)
{
	setCuboidColor(sgxColorRGB(col.r, col.g, col.b));
	setCuboidAlpha(col.a);
}

#if _TODO_
void
sgxPrimitive::getBoundingSphere(sgxVector3 &pos, tREAL32 &radius)
{
	// for each primitive
}

void
sgxPrimitive::getBoundingBox(sgxVector3 &minpos, sgxVector3 &maxpos)
{
}

#endif

