/*=========================================================================
* DspFix.c : Display fix module
* This is a part of the Game project.
*
* Version              1.0
* Creation date        04/05/97
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1997
*=======================================================================*/

#include "ToolsCPA.h"

#include "Options/Options.h"
#include "Macros.h"

#include "Actions/AllActs.h"

#include "Structur/EngMode.h"
#include "Structur/Objects.h"
#include "Structur/ErrGame.h"

#include "MainChar.h"
#include "ChanList.h"
#include "PlayAnim\PlayAnim.h"

#include "DspFix.h"
#include "PRF.h"
/*#include "ago.h"*/
void AGO_vDisplayGAUGES(GLD_tdstViewportAttributes *p_stVpt);
/*extern ACP_tdxBool g_bUseBinaryData;*/

/**************************************************************************/
void fn_vDisplayFix(void)
{
	BOOL bEnabledWrite;

#if defined(GAM_VIGNETTE)
	if (g_stDisplayVignetteDuringPlaying.bAskToDisplayVignette) {
		VIG_fn_vCopyVignetteToBackBuffer(&g_stDisplayVignetteDuringPlaying.stVignette);
	}
#endif /* GAM_VIGNETTE */

	GLI_ClearZBufferRegion(g_stEngineStructure.stFixViewportAttr.dwLeftInPixForClip,g_stEngineStructure.stFixViewportAttr.dwRightInPixForClip,g_stEngineStructure.stFixViewportAttr.dwTopInPixForClip,g_stEngineStructure.stFixViewportAttr.dwBottomInPixForClip);
	GLI_xClearViewingList();

	if (!GLD_bRequestWriteToViewport(g_stEngineStructure.hGLDDevice,g_stEngineStructure.hGLDFixViewport, &g_stEngineStructure.stFixViewportAttr, &bEnabledWrite))
		M_GameFatalError(E_uwGameCantWriteToViewPort);

	PRF_fn_vStopChrono( PRF_C_ulFctDisplaySpecific, PRF_C_pvSendToList );
	PRF_fn_vStartChrono( PRF_C_ulFctDisplay, PRF_C_pvMisc );
	PRF_fn_vStartChrono( PRF_C_ulFctDisplayCommon, PRF_C_pvSendFix );

	GEO_fn_vComputeCameraParametersForCulling( &g_stEngineStructure.stFixViewportAttr, MTH_C_ZERO );

	PRF_fn_vStopChrono( PRF_C_ulFctDisplayCommon, PRF_C_pvSendFix );
	FPRF_fn_vStopChrono( PRF_C_ulFctDisplay, PRF_C_pvMisc );
	PRF_fn_vStartChrono( PRF_C_ulFctDisplaySpecific, PRF_C_pvSendToList );

	HIE_fn_bSendSPOToFixViewport ( &g_stEngineStructure.stFixViewportAttr, g_stEngineStructure.ulDisplayMode );
	AGO_vDisplayGAUGES( &g_stEngineStructure.stFixViewportAttr );

	GLI_xSendListToViewport(&g_stEngineStructure.stFixViewportAttr);

	if (!GLD_bWriteToViewportFinished(g_stEngineStructure.hGLDDevice, g_stEngineStructure.hGLDFixViewport))
		M_GameFatalError(E_uwGameCantWriteToViewPortFinished);
}

/*************************************************************************/
void fn_vAskToDisplayVignette(char *szName)
{
#if defined(GAM_VIGNETTE)
	if (szName) {
		g_stDisplayVignetteDuringPlaying.bAskToDisplayVignette = TRUE;
		VIG_fn_vPreLoadVignetteInStructure(&g_stDisplayVignetteDuringPlaying.stVignette,szName,GLI_EVF_BGR565_UL);
	}
	else {
		g_stDisplayVignetteDuringPlaying.bAskToDisplayVignette = FALSE;
		VIG_fn_vFreeVignette(&g_stDisplayVignetteDuringPlaying.stVignette);
	}
#else  /* GAM_VIGNETTE */
	g_stDisplayVignetteDuringPlaying.bAskToDisplayVignette = FALSE;
#endif /* GAM_VIGNETTE */
}
