/** 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/scene.cpp

*/

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

//
// Main render trigger
//
void 
CSGXGraphicsEngine::renderScene()
{
	beginScene();
	drawScene();
	endScene();
}

//
// Basic scene order
//
void 
CSGXGraphicsEngine::beginScene()
{
	preBeginScene();
	doBeginScene();
	postBeginScene();
}

void 
CSGXGraphicsEngine::drawScene()
{
	m_CurrentScene = 0;
	while(m_CurrentScene < m_Viewport.size()) {
		preDrawScene();
		doDrawScene();
		postDrawScene();
		++m_CurrentScene;
	}
}

tUINT32	
CSGXGraphicsEngine::getCurrentScene() const
{
	return m_CurrentScene;
}

void 
CSGXGraphicsEngine::endScene()
{
	preEndScene();
	doEndScene();
	postEndScene();
}

//
// Typical intialization sequence
//
void 
CSGXGraphicsEngine::preBeginScene()
{
	m_EngineStats.reset();
	m_pFrameBlock->reset();
}

void 
CSGXGraphicsEngine::doBeginScene()
{
	// Usually Z-buffer clear
}

void 
CSGXGraphicsEngine::postBeginScene()
{
}

//
// Typical render sequence
//
void 
CSGXGraphicsEngine::preDrawScene()
{
	preDrawObjectsInWorld();
}

void 
CSGXGraphicsEngine::doDrawScene()
{
    drawSky();
    drawWorldSceneGraph();
    drawObjectsInWorld();
    drawOverlays();
}

void 
CSGXGraphicsEngine::postDrawScene()
{
	postDrawObjectsInWorld();
}

//
// Typical blit sequence
//
void 
CSGXGraphicsEngine::preEndScene()
{
}

void 
CSGXGraphicsEngine::doEndScene()
{
//	drawAlphaFaces();
}

void 
CSGXGraphicsEngine::postEndScene()
{
	if (CConfiguration::get()->getOption("stats")) {
		m_EngineStats.reportAll();
	}
}

void
CSGXGraphicsEngine::blit()
{
}
