//
// Tools_PSP_Export.h
//
// Created by KJFL - 05/02/2004 17:25:54
//
// Copyright (C) 2004 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif

#ifndef __TOOLS_PSP_EXPORT_H__
#define __TOOLS_PSP_EXPORT_H__

#include "Core/Asura_PlatformBasics.h"
#include "Core/Asura_Hash.h"

struct Asura_Botanicals_Template;
class Asura_Chunk_Stream;
template< class T > class Asura_LinkList;
class Asura_Mesh;
class Asura_Hierarchy_Skin;
struct TextureConversionData;
class Tools_BotanicalElementLOD;
class Tools_BotanicalShape;
class Asura_Shape; 

class Tools_PSP_Export
{
	public:
		
		// Enums for the flags field
		// Bit 1 should always be set (due to an old version of the chunk before proper versioning was implemented)
		enum CharacterFlagEnums {
			CharacterBitOne = 1,
			CharacterColoursReplaceNormals = 2,
		};		
		
		enum HierarchyFlagEnums {
			HierarchyColoursReplaceNormals = 1,
			HierarchyVerts_Shorts = 2,			
		};

		static void ExportEnvironment( HANDLE hOutput );

		static bool ExportTexture( const char* szInputName, const char* szOutputName, const int iTextureIndex, const TextureConversionData& xConvertData);

		static bool ExportCharacter( HANDLE hOutput, Asura_Hierarchy_Skin* pxSkin );
		
		static bool ExportObject( HANDLE hOutput, Asura_Mesh* pxMesh, const Asura_Hash_ID uHashID, const int iMaterialIndex );

		static bool ExportObjectHierarchy( HANDLE hOutput, const Asura_Hierarchy_Skin* pxSkin );
		
		#if defined ASURA_USE_BOTANICALS
				static bool ExportBotanicals( HANDLE hOutput, const int* const piMaterialConversionList );
		#endif //#if defined ASURA_USE_BOTANICALS
		
				// (SB - 18/01/07) Allow different vertex formats to be used
		static void SetEnvironmentVertexFormat(unsigned short uVertexFormat) { s_usEnvironmentVertexFormat = uVertexFormat; };
		static unsigned short GetEnvironmentVertexFormat() { return s_usEnvironmentVertexFormat; };

		static void SetSecondPassEnvironmentVertexFormat(unsigned short uVertexFormat) { s_usSecondPassEnvironmentVertexFormat = uVertexFormat; };
		static unsigned short GetSecondPassEnvironmentVertexFormat() { return s_usSecondPassEnvironmentVertexFormat; };
	
		static void SetCharacterColoursReplaceNormals(const bool bColoursReplaceNormals)
		{
			if (bColoursReplaceNormals)
			{
				s_uCharacterExportFlags |= CharacterColoursReplaceNormals;
			}
			else
			{
				s_uCharacterExportFlags &= ~CharacterColoursReplaceNormals;
			}
		}

		static void SetHierarchyColoursReplaceNormals(const bool bColoursReplaceNormals)
		{
			if (bColoursReplaceNormals)
			{
				s_uHierarchyExportFlags |= HierarchyColoursReplaceNormals;
			}
			else
			{
				s_uHierarchyExportFlags &= ~HierarchyColoursReplaceNormals;
			}
		}

		static void SetHierarchyVertsAsShorts(const bool bVertsAsShorts)
		{
			if (bVertsAsShorts)
			{
				s_uHierarchyExportFlags |= HierarchyVerts_Shorts;
			}
			else
			{
				s_uHierarchyExportFlags &= ~HierarchyVerts_Shorts;
			}
		}

	protected:

#if defined ASURA_USE_BOTANICALS

		// Botanicals export helper functions

		static void FindUsedBotanicalsTemplatesAndShapes( u_int& uNumUsedTemplates, Asura_LinkList< const Asura_Botanicals_Template* >& xUsedTemplateList,
														u_int& uNumUsedShapes, Asura_LinkList< const Asura_Shape* >& xUsedShapeList,
														u_int& uNumUsedBotanicalShapes, Asura_LinkList< const Tools_BotanicalShape* >& xUsedBotanicalShapeList,
														u_int& uFileSize);

		static void ExportShapes( Asura_Chunk_Stream& xStream, const Asura_LinkList< const Asura_Shape* >& xShapeList, const int* const piMaterialConversionList  );
		static void ExportBotanicalShapes( Asura_Chunk_Stream& xStream, const Asura_LinkList< const Tools_BotanicalShape* >& xShapeList, const int* const piMaterialConversionList  );
		static void ExportBotanicalsTemplates( Asura_Chunk_Stream& xStream, const Asura_LinkList< const Asura_Botanicals_Template* >& xTemplateList,
											const Asura_LinkList< const Asura_Shape* >& xShapeList,   // Standard shape list to find index
											const Asura_LinkList< const Tools_BotanicalShape* >& xBotanicalShapeList ); // Botanical shape list to find index

		static void IncrementExportSize_Geometry( u_int& uFileSize, Asura_Mesh* pxElementLOD );
		static void IncrementExportSize_Billboards( u_int& uFileSize, const Tools_BotanicalElementLOD& xElementLOD );
		static void IncrementExportSize_Imposter( u_int& uFileSize, const Tools_BotanicalElementLOD& xElementLOD );
		static void IncrementExportSize_Shape( u_int& uFileSize, const Asura_Shape& xShape );
		static void IncrementExportSize_BotanicalShape( u_int& uFileSize, const Tools_BotanicalShape& xBotanicalShape );

		static void ExportBotanicalsElementLOD_Geometry( Asura_Chunk_Stream& xStream, Asura_Mesh* pxElementLOD, const int* const piMaterialConversionList );
		static void ExportBotanicalsElementLOD_Billboards( Asura_Chunk_Stream& xStream, const Tools_BotanicalElementLOD& xElementLOD, const int* const piMaterialConversionList );
		static void ExportBotanicalsElementLOD_Imposter( Asura_Chunk_Stream& xStream, const Tools_BotanicalElementLOD& xElementLOD, const int* const piMaterialConversionList );

#endif // defined ASURA_USE_BOTANICALS

		// (SB - 18/01/07) Store vertex format for environment
		static unsigned short s_usEnvironmentVertexFormat;
		static unsigned short s_usSecondPassEnvironmentVertexFormat;

		static unsigned int s_uCharacterExportFlags;
		static unsigned int s_uHierarchyExportFlags;

	private:
		
};


#endif//__TOOLS_PSP_EXPORT_H__
