//
// Asura_GX_Environment.h
//
// Created by KOR - 09 October 2006
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __ASURA_GX_ENVIRONMENT_H__
#define __ASURA_GX_ENVIRONMENT_H__

#include "Core/Asura_Handle.h"
#include "Core/Asura_Maths.h"

class Asura_GX_Env_Tristrip
{
public:
	u_int m_uNumberOfIndices;
	u_int m_iMaterialID;
	u_int m_uStripFlags;
	u_char *m_pucDisplayList;
	u_int m_uDisplayListSize;
	
	// Constructor
	Asura_GX_Env_Tristrip()
	: m_uNumberOfIndices(0)
	, m_iMaterialID(0)
	, m_uStripFlags(0)
	, m_pucDisplayList(NULL)
	, m_uDisplayListSize(0)
	{
	}
	
	// Methods
	void BeginRender(u_int uBaseTevStages, u_int uBaseTexGens) const;
	void BeginRenderSimple() const;
	void Render(bool bAddToStats=true) const;
};

class Asura_GX_Env_Mesh
{
public:
	unsigned int			m_uNumberOfPositions;
	unsigned int			m_uNumberOfTexcoords;
	unsigned int			m_uNumberOfStrips;
	Asura_Bounding_Box		m_xBB;
	Asura_Vector_3*			m_pxPositions;
	short*					m_psTexCoords;
	Asura_GX_Env_Tristrip*	m_pxStrips;
	union
	{
		struct 
		{
			u_char   m_bMeshHasTransparentStrips:1;
		};
		u_char m_ucFlags;
	};
	
	// Constructor
	Asura_GX_Env_Mesh();
	// Destructor
	~Asura_GX_Env_Mesh();

	// Methods
	void Render() const;
	void RenderSimple() const;

	void SetupLighting() const;
	void SetupArrays() const;
};

class Asura_GX_Environment
{
public:
	// Static members
	static unsigned int			s_uNumberOfMeshes;
	static Asura_GX_Env_Mesh*	s_pxMeshStorage;
	static bool					s_bInitialised;
	static unsigned int			s_uNormalTableEntries;
	static Asura_Vector_3*		s_pxNormalTable;
	static Asura_Vector_3*		s_pxAllPositions;
	static short*				s_psAllTexCoords;
	static int					s_iAttenuationMap;
	static Asura_Vector_3		s_xMeshPos;
	static void *				s_pvDisplayListMem;
	static u_int				s_uDisplayListMaxSize;
	enum
	{
		EXPORT_FLAG_USE_DISPLAY_LISTS = 1,
		EXPORT_FLAG_NORMALS = 2,
		EXPORT_FLAG_VERTEXCOLOURRGBA6 = 4,
	};

	static unsigned int			s_uExportFlags;

	static bool Initialise(Asura_Handle xFileHandle);
	static void Reset();
	static void Update();
	static void Shutdown();

	static void RenderSetup(bool bInverted = false);
	static void Render(bool bInverted = false);

	static void ReadNewEnvironmentFormat(Asura_Handle xFileHandle);
};

#endif//__ASURA_GX_ENVIRONMENT_H__