//=============================================================================
//
// Copyright 1998 by Captivation Digital Laboratories, Inc.
// All Rights Reserved.
//
//=============================================================================
//
// "KRAD" -- Kamui Rendering/Animation Demonstration
//
// This file contains a C++ wrapper around the kamui API. It is lightweight
// and mostly done through inline operations.
//
// Much of the action is handled through global variables to ensure speedy
// operation.
//
//=============================================================================
//-----------------------------------------------------------------------------
// $Revision: 1 $
// $NoKeywords: $
//=============================================================================

#ifndef _KAMUIPP_H_
#define _KAMUIPP_H_

#include "krad.h"
#include "kamui.h"

//=============================================================================
//=============================================================================	KAMUI DIRECT MODE
//=============================================================================
#define	KAMUI_DIRECT

#ifdef KAMUI_DIRECT
	#define	KAMUI_RENDER					kmRenderDirect
	#define	KAMUI_RENDER_TEXTURE			kmRenderTextureDirect
	#define	KAMUI_SET_END_OF_LIST()			kmSetEndOfListDirect()
	#define	KAMUI_SET_VERTEX(ptr,type,size)	kmSetVertexDirect((ptr),(type),(size))
	#define	KAMUI_START_VERTEX_STRIP()		kmStartVertexStripDirect()
#else
	#define	KAMUI_RENDER					kmRender
	#define	KAMUI_RENDER_TEXTURE			kmRenderTexture
	#define	KAMUI_SET_END_OF_LIST()			(KMSTATUS_SUCCESS)
	#define	KAMUI_SET_VERTEX(ptr,type,size)	kmSetVertexDirect(theKamui->VertBuff(),(ptr),(type),(size))
	#define	KAMUI_START_VERTEX_STRIP()		kmStartVertexStrip(theKamui->VertBuff())
#endif

//=============================================================================
//=============================================================================	KAMUI ERROR HANDLING
//=============================================================================
#ifdef	_DEBUG
	#define KAMUI_TRY(exp)	CheckKamuiError (exp, #exp, __FILE__, __LINE__)
#else
	#define	KAMUI_TRY(exp)	exp
#endif

bool CheckKamuiError (KMSTATUS status, char* command, char* filename, int linenum);

//=============================================================================
//=============================================================================	CLASS KKamui
//=============================================================================
class KKamui
{
private:	// data values
	uint32				mEORCount;			// a render counter
	uint32				mVBLCount;			// a vbl counter
	int32				mEORLine;			// tracks last scanline for EOR callback
	int32				mEOVLine;			// tracks last scanline for EOV callback
	int32				mVBLLine;			// tracks last scanline for VBL callback
	KMVERTEXBUFFDESC	mVertBuff;
	KMSURFACEDESC		mFrontBuffer;
	KMSURFACEDESC		mBackBuffer;

public:		// data value access
	uint32&				EORCount	(void)	{	return(mEORCount);		}	// get reference of render counter
	uint32&				VBLCount	(void)	{	return(mVBLCount);		}	// get reference of vbl counter
	int32&				EORLine		(void)	{	return(mEORLine);		}	// get reference of last EOR callback line
	int32&				EOVLine		(void)	{	return(mEOVLine);		}	// get reference of last EOV callback line
	int32&				VBLLine		(void)	{	return(mVBLLine);		}	// get reference of last VBL callback line
	KMVERTEXBUFFDESC& 	VertBuff	(void)	{	return(mVertBuff);		}	// get reference of VertBuff (for non-Direct mode)

public:		// constructor / destructor
	KKamui			(	KMINT32			nKForOpaquePoly = 128,
						KMINT32			nKForOpaqueMod	= 128,
						KMINT32			nKForTransPoly	= 128,
						KMINT32			nKForTransMod	= 128,
						KMVIDEOMODE		nVideoMode		= KM_VGA,
						KMDISPLAYMODE	nDisplayMode	= KM_DSPMODE_VGA,
						KMBPPMODE		nBpp			= KM_DSPBPP_RGB565,
						KMBOOLEAN		nDither			= FALSE,
						KMBOOLEAN		nAntiAlias		= FALSE
					);
	~KKamui ();

public:		// misc methods
	void EnableCallbacks(void);

	int32 ReadScanline (void) const
	{
		int32 t;
		KAMUI_TRY (kmGetCurrentScanline(&t));
		return (t < -50) ? (-t) : (t);
	}
};


//=============================================================================
//=============================================================================
//=============================================================================

#endif  // Headerfile Guard

//=============================================================================	END-OF-INCLUDE
