/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     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: sgx/src/sgx/graphics/polygon/gfxpolygon.cpp

*/

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

void 
CSGXGraphicsEngine::drawPolygon(const sgxGfxPolygon &poly, const sgxMatrix43 &transform)
{
	m_RenderMode.apply(SGX_RENDERMODE_3D);

	if (isAlphaSortable(poly)) {
		addAlphaSorter(poly, transform);
	} else {
		drawPolygonImpl(poly, transform);
	}
}

void 
CSGXGraphicsEngine::convertPolygon(sgxGfxPolygon &poly)
{
	// Derived classes can create a driver-specific
	// data block which will get used by the platform-derived
	// class.
	poly.m_pPlatformData = NULL;
}

void 
CSGXGraphicsEngine::drawPolygonImpl(const sgxGfxPolygon &poly, const sgxMatrix43 &transform)
{
	SGX_UNUSED(transform);
	
	m_RenderMode.apply(SGX_RENDERMODE_3D);

	if (poly.pTexture) {
		CSGXTextureManager::get()->applyTexture(poly.pTexture);
	}
}

void 
CSGXGraphicsEngine::drawAlphaPolygonImpl(const sgxGfxPolygon &poly, const sgxMatrix43 &transform)
{
	m_RenderMode.apply(SGX_RENDERMODE_3D);
	drawPolygonImpl(poly, transform);
}
