/*
 =======================================================================================
  Name        : light.h
  Description : proto for light functions
 =======================================================================================
 */
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#ifndef LIGHT_H
#define LIGHT_H
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
struct GLI_tdstInternalGlobalValuesFor3dEngine_;
 
#include "cpa_expt.h"
 
#include "GLI\GLI_Defn.h"   /*pour ISI_tdstColor*/
 
#include "util.h"
#include "GEO.h"
#include "GLD.h"
 
#include "SAI.h"
 
#ifndef LIGHT_ST_H
typedef struct GLI_tdstLight_ GLI_tdstLight;
#endif
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
/*
 =======================================================================================
	Constants
 =======================================================================================
 */
 
/*
 * type of ligth
 */
#define GLI_C_lParallelLight				1
#define GLI_C_lSphericalLight				2
#define GLI_C_lHotSpotLight					3
#define GLI_C_lAmbientLight					4
#define GLI_C_lParallelLight_With_Limit		5
#define GLI_C_lFogLight						6
 
/*
 * what is Lighted
 */
#define GLI_C_LightMap		0x01
#define GLI_C_LightPerso	0x02
 
/*
 * state of ligth
 */
#define GLI_C_ActivateLight		1
#define GLI_C_DisactivateLight	0
 
/*
 *  number max of fog at same time
 */
#define GLI_C_lMaxFog			16
 
/*
 =======================================================================================
	Structure
 =======================================================================================
 */
 
/*
 * to store fog parameter
 */
typedef struct tdstFogParams_
{
	MTH_tdxReal		xDepthStart;
	MTH_tdxReal		xDepthEnd;
	MTH_tdxReal		xInfinite;
	MTH_tdxReal		xBlendStart;
	MTH_tdxReal		xBlendEnd;
	GEO_tdstColor	stColor;
} tdstFogParams;
 
 
 
/*
 =======================================================================================
	Globals
 =======================================================================================
 */
/*
 * for fog
 */
extern CPA_EXPORT char GLI_cGlobalFogIsOn;
 
extern CPA_EXPORT MTH_tdxReal GLI_xFogNear;
extern CPA_EXPORT MTH_tdxReal GLI_xFogFar;
extern CPA_EXPORT MTH_tdxReal GLI_xFogInfinite;
extern CPA_EXPORT MTH_tdxReal GLI_xFogBlendNear;
extern CPA_EXPORT MTH_tdxReal GLI_xFogBlendFar;
/*YLG*/
extern CPA_EXPORT GEO_tdstColor	GLI_stFogColor;
extern CPA_EXPORT ACP_tdxBool	GLI_g_bSaveFog;
 
extern CPA_EXPORT tdstFogParams	GLI_g_stSaveFog;
extern CPA_EXPORT tdstFogParams	GLI_g_stGlobalFog;
extern CPA_EXPORT tdstFogParams GLI_ga_stFogTable[ GLI_C_lMaxFog ];
extern CPA_EXPORT tdstFogParams *GLI_gp_stLastFog;
extern CPA_EXPORT tdstFogParams *GLI_gp_stActiveFog;
extern CPA_EXPORT tdstFogParams *GLI_gp_stLastComputedFog;
 
extern CPA_EXPORT GLI_tdstLight *GLI_pstCurrentFogLight ;
extern CPA_EXPORT long GLI_lUseGlobalFog ;
 
extern float xZDepthStart,xZDepthEnd;
extern ACP_tdxIndex xFogIsOn;
extern GEO_tdstColor stColorDepthCuing;
 
 
/*
 * for PLG files
 */
#ifdef ACTIVE_EDITOR
extern  ISI_tdstObjectColorStruct m_ObjectColorStruct;
#endif
 
/*
 =======================================================================================
	Manage with table of active light for charachter 
 =======================================================================================
 */
extern CPA_EXPORT void GLI_vResetTableOfActiveLightsForChar(char _cValue);
	
void GLI_vSetLightActivityForChar( int iNum, unsigned char ucState );
ACP_tdxBool GLI_bIsLightActiveForChar( int iNum );
ACP_tdxBool GLI_bDoesLightAffectBV( GLI_tdstLight * p_stLight, MTH3D_tdstVector * p_stCenter, MTH_tdxReal xRadius );
 
/*
 =======================================================================================
	ZBuffer
 =======================================================================================
 */
extern CPA_EXPORT long GLI_vIsLightZbufferLight(struct GLI_tdstLight_ *p_stLight);
extern CPA_EXPORT void GLI_vSetLightAsZBufferLight(struct GLI_tdstLight_ *p_stLight , long bEnbleDisable);
extern CPA_EXPORT long GLI_bAssignZBufferToLight(struct GLI_tdstLight_ *p_stLight , long lZBufferSizeX,long lZBufferSizeY,float *p_ZBuffer);
extern CPA_EXPORT long GLI_lCreateZBufferForLight(void **p_BufferToCreate, long lSizeX,long lSizeY,struct  GLI_tdstLight_ *p_stLight );
extern CPA_EXPORT BOOL GLI_bLightBufferisNotBuilding(struct GLI_tdstLight_ *p_stLight);
extern CPA_EXPORT float *GLI_p_GetPtrOfZBuffer(struct GLI_tdstLight_ *p_stLight , long lFaceNumberOfCubeForSphericalLight);
extern CPA_EXPORT long GLI_p_GetNumberOfIterationForBuildZBufferOfALight(struct GLI_tdstLight_ *p_stLight );
 
/*
 =======================================================================================
	List of ligth
 =======================================================================================
 */
extern CPA_EXPORT void GLI_vAddLightToViewport(struct GLD_tdstViewportAttributes_ *p_stVpt , struct GLI_tdstLight_ *p_stLight );
extern CPA_EXPORT void GLI_vPopLightsInViewport(struct GLD_tdstViewportAttributes_ *p_stVpt , unsigned long lNbLightsToPop);
extern CPA_EXPORT void GLI_xSetViewportLightsOnOff(unsigned char bOnOff);
extern CPA_EXPORT void GLI_vClearListOfLightInViewport (struct GLD_tdstViewportAttributes_ *p_stVpt);
 
/*
 =======================================================================================
	Creation of light 
 =======================================================================================
 */
extern CPA_EXPORT void GLI_xCreateLight ( struct GLI_tdstLight_ **h_stLight , long lTypeOfThis ) ;
extern CPA_EXPORT void GLI_vCopyLight(struct GLI_tdstLight_ *p_stLightDst,struct GLI_tdstLight_ *p_stLightSrc);
extern CPA_EXPORT unsigned long GLI_ulGetLightSize();
 
/*
 =======================================================================================
	Save light
 =======================================================================================
 */
extern CPA_EXPORT void GLI_vStoreLightForInit(struct GLI_tdstLight_ *p_stLight,SAI_tdeFlags eUserFlags);
extern CPA_EXPORT void GLI_vRemoveLightForInit(struct GLI_tdstLight_ *p_stLight,SAI_tdeFlags eUserFlags);
extern CPA_EXPORT void GLI_vReInitLight(struct GLI_tdstLight_ *p_stLight,SAI_tdeFlags eUserFlags);
 
/*
 =======================================================================================
	Ligth structure access function
 =======================================================================================
 */
 
extern CPA_EXPORT void	        GLI_vComputeLight_SphereBox (struct	GLI_tdstLight_ *p_stLight);
 
extern CPA_EXPORT void			GLI_xSetLightState ( struct GLI_tdstLight_ *p_stLight , long b_lOnOff ) ;
extern CPA_EXPORT void			GLI_xGetLightState ( struct GLI_tdstLight_ *p_stLight , long *pb_lOnOff ) ;
 
extern CPA_EXPORT void			GLI_xSetLightColor ( struct GLI_tdstLight_ *p_stLight , struct GEO_tdstColor_ *p_stColor ) ;
extern CPA_EXPORT void			GLI_xGetLightColor ( struct GLI_tdstLight_ *p_stLight , struct GEO_tdstColor_ *p_stColor ) ;
 
extern CPA_EXPORT void			GLI_xGetLightMatrix ( struct GLI_tdstLight_ *p_stLight , struct POS_stCompletePosition *p_stMatrix ) ;
extern CPA_EXPORT void			GLI_xSetLightMatrix ( struct GLI_tdstLight_ *p_stLight , struct POS_stCompletePosition *p_stMatrix ) ;
extern CPA_EXPORT MTH3D_tdstVector *GLI_p_stGetLightTranslation(struct GLI_tdstLight_ *p_stLight);
 
extern CPA_EXPORT void			GLI_vSetLightNearFar ( struct GLI_tdstLight_ *p_stLight , MTH_tdxReal xNear, MTH_tdxReal xFar ) ;
extern CPA_EXPORT void			GLI_vGetLightNearFar ( struct GLI_tdstLight_ *p_stLight , MTH_tdxReal *p_xNear, MTH_tdxReal *p_xFar ) ;
 
extern CPA_EXPORT void			GLI_vSetLightAlphas ( struct GLI_tdstLight_ *p_stLight , MTH_tdxReal xLittleAlpha, MTH_tdxReal xBigAlpha);
extern CPA_EXPORT void			GLI_vGetLightAlphas ( struct GLI_tdstLight_ *p_stLight , MTH_tdxReal *p_xLittleAlpha, MTH_tdxReal *p_xBigAlpha);
 
extern CPA_EXPORT long			GLI_lGetLightType(struct GLI_tdstLight_ *p_stLight );
extern CPA_EXPORT void			GLI_vSetLightType (struct GLI_tdstLight_ *p_stLight ,long lNewType);
 
extern CPA_EXPORT void			GLI_vSetPaintingLightFlag (struct GLI_tdstLight_ *p_stLight, long bIsPainting) ;
extern CPA_EXPORT unsigned char GLI_ucGetPaintingLightFlag (struct GLI_tdstLight_ *p_stLight) ;
extern CPA_EXPORT void			GLI_vSetPaintLight( struct GLI_tdstLight_ *p_stLight);
 
extern CPA_EXPORT void			GLI_vSetAlphaLightFlag (struct GLI_tdstLight_ *p_stLight, long bIsAlpha) ;
extern CPA_EXPORT unsigned char GLI_ucGetAlphaLightFlag (struct GLI_tdstLight_ *p_stLight) ;
extern CPA_EXPORT void			GLI_vSetAlphaLight(struct GLI_tdstLight_ *p_stLight);
 
extern CPA_EXPORT void			GLI_xSetLightBackgroundColor ( struct GLI_tdstLight_ *p_stLight , struct GEO_tdstColor_ *p_stColor ) ;
extern CPA_EXPORT void			GLI_xGetLightBackgroundColor ( struct GLI_tdstLight_ *p_stLight , struct GEO_tdstColor_ *p_stColor ) ;
 
extern CPA_EXPORT void			GLI_vSetLight_Intensity_Min_Max (struct	GLI_tdstLight_ *p_stLight , MTH_tdxReal xIntensity_Min, MTH_tdxReal xIntensity_Max );
extern CPA_EXPORT void			GLI_vGetLight_Intensity_Min_Max (struct	GLI_tdstLight_ *p_stLight , MTH_tdxReal * xIntensity_Min, MTH_tdxReal * xIntensity_Max );
 
extern CPA_EXPORT void			GLI_vSetLight_Exter_Max_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector xExter_Max_Pos);
extern CPA_EXPORT void			GLI_vSetLight_Exter_Min_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector xExter_Min_Pos);
extern CPA_EXPORT void			GLI_vSetLight_Inter_Max_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector xInter_Max_Pos);
extern CPA_EXPORT void			GLI_vSetLight_Inter_Min_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector xInter_Min_Pos);
extern CPA_EXPORT void			GLI_vGetLight_Exter_Max_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector *xExter_Max_Pos);
extern CPA_EXPORT void			GLI_vGetLight_Exter_Min_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector *xExter_Min_Pos);
extern CPA_EXPORT void			GLI_vGetLight_Inter_Max_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector *xInter_Max_Pos);
extern CPA_EXPORT void			GLI_vGetLight_Inter_Min_Pos (struct	GLI_tdstLight_ *p_stLight , MTH3D_tdstVector *xInter_Min_Pos);
 
extern CPA_EXPORT unsigned char GLI_ucGetObjectLighted( struct GLI_tdstLight_ *p_stLight) ;
extern CPA_EXPORT void			GLI_vSetLightMap( struct GLI_tdstLight_ *p_stLight , unsigned char bLightMap) ;
extern CPA_EXPORT void			GLI_vSetLightPerso( struct GLI_tdstLight_ *p_stLight , unsigned char bLightPerso) ;
extern CPA_EXPORT void			GLI_vSetObjectLighted( struct GLI_tdstLight_ *p_stLight , unsigned char ucObjectLighted) ;
 
extern CPA_EXPORT void			GLI_fn_vFogSetNear(struct GLI_tdstLight_ *p_stLight, MTH_tdxReal);
extern CPA_EXPORT MTH_tdxReal	GLI_fn_xFogGetNear(struct GLI_tdstLight_ *p_stLight);
extern CPA_EXPORT void			GLI_fn_vFogSetFar(struct GLI_tdstLight_ *p_stLight, MTH_tdxReal);
extern CPA_EXPORT MTH_tdxReal	GLI_fn_xFogGetFar(struct GLI_tdstLight_ *p_stLight);
extern CPA_EXPORT void			GLI_fn_vFogSetInfinite(struct GLI_tdstLight_ *p_stLight, MTH_tdxReal);
extern CPA_EXPORT MTH_tdxReal	GLI_fn_xFogGetInfinite(struct GLI_tdstLight_ *p_stLight);
extern CPA_EXPORT void			GLI_fn_vFogSetBlendNear(struct GLI_tdstLight_ *p_stLight, MTH_tdxReal);
extern CPA_EXPORT MTH_tdxReal	GLI_fn_xFogGetBlendNear(struct GLI_tdstLight_ *p_stLight);
extern CPA_EXPORT void			GLI_fn_vFogSetBlendFar(struct GLI_tdstLight_ *p_stLight, MTH_tdxReal);
extern CPA_EXPORT MTH_tdxReal	GLI_fn_xFogGetBlendFar(struct GLI_tdstLight_ *p_stLight);
 
 
/*
 =======================================================================================
	compute light 
 =======================================================================================
 */
 
extern CPA_EXPORT void GLI_vSendObjectToLights
							(
								struct GLI_tdstLight_ **p_stLight ,
								struct GEO_tdstGeometricObject_ *p_stObject ,
								struct GEO_tdstColor_ *p_stColorRLID ,
								struct GEO_tdstColor_ *p_stColorRLIS ,
								struct GEO_tdstColor_ *p_stColorRLIA ,
								long lNumberOfLights,
								struct GLI_tdstInternalGlobalValuesFor3dEngine_ *p_stGlobaleMT
							);
 
/*
 =======================================================================================
	Other (RLI buffer, Init) 
 =======================================================================================
 */
extern CPA_EXPORT void GLI_vSpecularOn();
extern CPA_EXPORT void GLI_vSpecularOff();
 
void GLI_vCopyRLI2ComputeBuffer(struct GLI_tdstInternalGlobalValuesFor3dEngine_ *p_stGlobalsParrameters, GEO_tdstColor *p_stColorRLID , long xStart , long lNumber);
void GLI_vCopyRLI2ComputeBufferISI(struct GLI_tdstInternalGlobalValuesFor3dEngine_ *p_stGlobalsParrameters, ISI_tdstColor *p_stColorRLID , long xStart , long lNumber);
void GLI_vInitSpecularAndAmbiamt(struct GLI_tdstInternalGlobalValuesFor3dEngine_ *p_stGlobaleMT );
 
 
/*
 =======================================================================================
	fog ( in fog.c )
 =======================================================================================
 */
 
extern CPA_EXPORT void GLI_vSetFog (GLI_tdxValue xDepthStart, GLI_tdxValue xDepthEnd, GLI_tdxValue xInfinite , GEO_tdstColor *p_stFogColor);
extern CPA_EXPORT void GLI_vSetFog2(GLI_tdxValue xBlendStart, GLI_tdxValue xDepthStart, GLI_tdxValue xBlendEnd, GLI_tdxValue xDepthEnd, GLI_tdxValue xInfinite, GEO_tdstColor *p_stFogColor);
 
extern CPA_EXPORT void GLI_vGetFog(GLI_tdxValue *p_xDepthStart, GLI_tdxValue *p_xDepthEnd, GEO_tdstColor *p_stFogColor);
 
extern CPA_EXPORT void GLI_vFogOn();
extern CPA_EXPORT void GLI_vFogOff();
 
#ifdef __cplusplus
};
#endif /* __cplusplus */
 
#endif /* LIGHT_H*/
