/*********************************************************************//**
*	\brief Decal system
*	Tento modul tvori system, ktery dokaze vykreslovat ruzne napisy
*	na zed.
*
*	\author Michal Jirous
*	\date 13.02.2009
*	\file level_decals.h
**********************************************************************/

#ifndef __LEVEL_DECALS_H__
#define __LEVEL_DECALS_H__

#include "level_bspfile_def.h"
#include <list>
#include "level_structs.h"
#include "ent_baseentity.h"

struct Decal
{
	short first_element;	//do vertex a tex coord array
	Face *m_pMyFace;
	TextureElement *m_pTexture;
};

const int FRUSTUM_CULLING_DECAL_COUNT_TRESHOLD = 10;

struct DecalCluster
{
	int m_iDecalsCount;
	BoundingBox m_Bounds;
	std::list<Decal> m_Decals;
	void render( const RenderData &renderData );
};

const int MAX_STATIC_DECALS = 200;
const int MAX_DYNAMIC_DECALS = 200;

typedef std::list<DecalCluster> decCList_t;

//pro model 0 mozna udelame neco specialniho na dynamicky decals

class DecalSystem
{
	int m_iStaticDecalsCount;
	int m_iDynamicDecalsCount;

	int m_iElementsCount;

	Point vertex_array[MAX_STATIC_DECALS];
	TexCoord2f_t texture_coords_array[MAX_STATIC_DECALS];	//


	void generateDecal( Decal &decal, int angle, Point &origin );
public:
	DecalSystem();
	bool containDecals( size_t model );
	void renderDecalsForModel( size_t model, const RenderData &renderData  );
	void addStaticTexture( parameters_t &parameters );
	decCList_t m_DecalsPerModel[MAX_MAP_MODELS];	/*!< @brief Seznam clusteru, ktere mohou mit decals (index je ekvivalentni s indexem do pole modelu. */
	void destroy();
};

extern DecalSystem decalSystem;


#endif /*__LEVEL_DECALS_H__*/
