 //===========================================================================//
// File:	MLRStuff.hpp                                                           //
// Project: Adept           Brick: ???                                       //
// Contents: ???                                                             //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 00/00/00  XXX  Initial coding.                                            //
//---------------------------------------------------------------------------//
// Copyright (C) 1995-1998, Virtual World Entertainment, Inc.                //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#pragma once
#define MLR_MLR_HPP

#if !defined(STUFF_STUFF_HPP)
	#include <Stuff\Stuff.hpp>
#endif

namespace MidLevelRenderer
{

	//
	//--------------
	// Stuff classes
	//--------------
	//
	enum
	{
		MLRStateClassID = Stuff::FirstMLRClassID,
		MLRClippingStateClassID,
		MLRClipperClassID,
		MLRSorterClassID,
		MLRSortByOrderClassID,
		MLRLightClassID,
		MLRTexturePoolClassID,
		MLRPrimitiveClassID,
		MLRIndexedPrimitiveClassID,
		MLRPolyMeshClassID,
		MLRIndexedPolyMeshClassID,
		MLRShapeClassID,
		MLREffectClassID,
		MLRPointCloudClassID,
		MLRTriangleCloudClassID,
		MLRAmbientLightClassID,
		MLRInfiniteLightClassID,
		MLRInfiniteLightWithFalloffClassID,
		MLRPointLightClassID,
		MLRSpotLightClassID,
		MLRLightMapClassID,

		MLRPrimitiveBaseClassID,
		MLRIndexedPrimitiveBaseClassID,
		MLR_I_PMeshClassID,
		MLR_I_C_PMeshClassID,
		MLR_I_L_PMeshClassID,
		MLR_I_DT_PMeshClassID,
		MLR_I_C_DT_PMeshClassID,
		MLR_I_L_DT_PMeshClassID,
		MLRNGonCloudClassID,
		MLRCardCloudClassID,

		MLR_I_MT_PMeshClassID,

		MLR_I_DeT_PMeshClassID,
		MLR_I_C_DeT_PMeshClassID,
		MLR_I_L_DeT_PMeshClassID,

		MLR_I_TMeshClassID,
		MLR_I_DeT_TMeshClassID,
		MLR_I_C_TMeshClassID,
		MLR_I_L_TMeshClassID,

		MLR_WaterClassID,
		MLR_Terrain2ClassID,

		MLRLineCloudClassID,

		MLRIndexedTriangleCloudClassID,

		MLR_I_DT_TMeshClassID,
		MLR_I_C_DT_TMeshClassID,
		MLR_I_L_DT_TMeshClassID,

		MLR_I_C_DeT_TMeshClassID,
		MLR_I_L_DeT_TMeshClassID,

		MLRLookUpLightClassID,
		MLRProjectLightClassID,

		MLRSpriteCloudClassID,

		MLRShadowLightClassID,

		MLRCulturShapeClassID,

		MLRCenterPointLightClassID,

		MLRFootSteplClassID,

		MLR_BumpyWaterClassID,

		MLRTextureClassID,
		MLRMovieTextureClassID,

		FirstFreeMLRClassID
	};

	enum {
		Current_MLR_Version = 18
	};

	struct Limits {
		static unsigned
			Max_Number_Vertices_Per_Frame,
			Max_Number_Primitives_Per_Frame,
			Max_Number_ScreenQuads_Per_Frame,
			Max_Size_Of_LightMap_MemoryStream;

		static Stuff::Scalar
			LightThreshold;

		enum {
			Max_Number_Vertices_Per_Mesh = 256,
			Max_Number_Vertices_Per_Effect = 1024,
			Max_Number_Vertices_Per_Polygon = 32,
			Max_Number_Of_Texture_Bits = 14,
			Max_Number_Textures = 1 << Max_Number_Of_Texture_Bits,
			Max_Number_Of_NGon_Vertices = 9,
			Max_Number_Of_Multitextures	= 8,
			Max_Number_Of_Lights_Per_Primitive = 8,
			Max_Number_Of_FogStates = 5,
			Max_Size_Of_Vertex_Buffer = 2*Max_Number_Vertices_Per_Effect,	// make sure this is the bigger one from
			Max_Size_Of_Index_Buffer = 2*Max_Number_Vertices_Per_Effect		// Max_Number_Vertices_Per_Mesh or
																			// Max_Number_Vertices_Per_Effect
		};
	};

	int
		ReadMLRVersion(Stuff::MemoryStream *erf_stream);
	void
		WriteMLRVersion(Stuff::MemoryStream *erf_stream);

	void InitializeClasses(
		Stuff::NotationFile *startup_ini = NULL,
		unsigned Max_Number_Vertices_Per_Frame = 8192,
		unsigned Max_Number_Primitives_Per_Frame = 1024,
		unsigned Max_Number_ScreenQuads_Per_Frame = 512,
		unsigned Max_Size_Of_LightMap_MemoryStream = 32768,
		bool Convert_To_Triangle_Meshes = true
	);
	void TerminateClasses(Stuff::NotationFile *startup_ini=NULL);

	extern HGOSHEAP Heap;
	extern HGOSHEAP StaticHeap;
	extern HGOSHEAP TexturePoolHeap;
	extern HGOSHEAP StatesHeap;
	extern HGOSHEAP LightsHeap;
	extern HGOSHEAP MiscellaneousHeap;
	extern HGOSHEAP ShapeHeap;
	extern HGOSHEAP PrimitiveHeap;
	extern HGOSHEAP VertexPoolHeap;
	extern HGOSHEAP EffectHeap;
	extern HGOSHEAP ClipperHeap;
	extern HGOSHEAP SorterHeap;

	extern bool ConvertToTriangleMeshes;

	extern DWORD bucketColors[];

	extern int terrainTextureResolution;

	DECLARE_TIMER(extern, Scene_Draw_Time);

	DECLARE_TIMER(extern, Transform_Time);
	DECLARE_TIMER(extern, Clipping_Time);
	DECLARE_TIMER(extern, GOS_Draw_Time);
	DECLARE_TIMER(extern, Vertex_Light_Time);
	DECLARE_TIMER(extern, LightMap_Light_Time);
	DECLARE_TIMER(extern, Texture_Sorting_Time);
	DECLARE_TIMER(extern, Alpha_Sorting_Time);
	DECLARE_TIMER(extern, Unlock_Texture_Time);
	DECLARE_TIMER(extern, Shape_Setup_Time);
	DECLARE_TIMER(extern, Find_Backface_Time);
	DECLARE_TIMER(extern, Fog_Time);
	DECLARE_TIMER(extern, Shadow_Time);

	extern DWORD Number_Of_Primitives;
	extern DWORD NumAllIndices;
	extern DWORD NumAllVertices;
	extern float Index_Over_Vertex_Ratio;
	extern DWORD TransformedVertices;
	extern DWORD NumberOfAlphaSortedTriangles;
	extern DWORD LitVertices;
	extern DWORD NonClippedVertices;
	extern DWORD ClippedVertices;
	extern DWORD PolysClippedButOutside;
	extern DWORD PolysClippedButInside;
	extern DWORD PolysClippedButOnePlane;
	extern DWORD PolysClippedButGOnePlane;
	extern DWORD UsedGOSVertices;
	extern DWORD UsedGOSVertices2UV;
	extern DWORD UsedGOSVertices3UV;
	extern DWORD UsedGOSIndicies;

	#define COLOR_AS_DWORD	1
	#if COLOR_AS_DWORD>0
		typedef DWORD ColorType;
	#else
		typedef Stuff::RGBAColor ColorType;
	#endif

	extern DWORD paintMeColorDW;
	extern Stuff::RGBAColor paintMeColorF;

	typedef Stuff::Vector2DOf<Stuff::Scalar> Vector2DScalar;
}

#define	EFECT_CLIPPED	0

#undef UV_CHECK

#define FOG_HACK		0

#if FOG_HACK==0
	struct FogData {
		Stuff::Scalar near_fog;
		Stuff::Scalar far_fog;
		Stuff::Scalar one_over;

		Stuff::Scalar height_low_fog;
		Stuff::Scalar height_top_fog;
		Stuff::Scalar height_one_over;

		Stuff::Scalar height_fog_density0;

		BYTE height_fog_density;

		Stuff::Point3D cameraPos;
		Stuff::Point3D orgInShape;
		Stuff::Vector3D upInShape;

		BYTE FogVertex(const Stuff::Point3D*);
	};
#endif


#define	TO_DO	Abort_Program("Here has work to be done !");

#include <MLR\MLRState.hpp>
