
#ifndef LIBRARIES_CGX3DRAVE_H
#define LIBRARIES_CGX3DRAVE_H TRUE

/*
**	$VER: cgx3drave.h 1.0 (7-Mar-99)
**
**	include file for cgx3drave.library
**
**	Copyright © 1998-99 by Vision Factory Development
**      All Rights reserved.
**
*/

#ifdef __SASC_60
#define STDARGS		__stdargs
#else
#define STDARGS
#endif

#define	CGXR3DT_FrontMap	0x81080000
#define CGXR3DT_BackMap		0x81080001

#define kQAAmigaOS	4

typedef enum TQAVersion {
	kQAVersion_Prerelease = 0
} TQAVersion;

typedef enum TQAImagePixelType {
	kQAPixel_Alpha1		= 0,
	kQAPixel_RGB16		= 1,
	kQAPixel_ARGB16		= 2,
	kQAPixel_RGB32		= 3,
	kQAPixel_ARGB32		= 4,
	kQAPixel_CL4		= 5,
	kQAPixel_CL8		= 6,
	kQAPixel_RGB16_565	= 7,
	kQAPixel_RGB24		= 8
} TQAImagePixelType;

typedef enum TQAColorTableType {
	kQAColorTable_CL8_RGB32 = 0,
	kQAColorTable_CL4_RGB32 = 1
} TQAColorTableType;

typedef enum TQADeviceType {
	kQADeviceGHandle	= 4
} TQADeviceType;


typedef enum TQAClipType {
	kQAClipRgn		= 0
} TQAClipType;

typedef enum TQATagInt {
	kQATag_ZFunction		= 0,
	kQATag_Antialias		= 8,
	kQATag_Blend			= 9,
	kQATag_PerspectiveZ		= 10,
	kQATag_TextureFilter		= 11,
	kQATag_TextureOp		= 12,
	kQATag_CSGTag			= 14,
	kQATag_CSGEquation		= 15,
	kQATag_BufferComposite		= 16,
	kQATagGL_DrawBuffer		= 100,
	kQATagGL_TextureWrapU		= 101,
	kQATagGL_TextureWrapV		= 102,
	kQATagGL_TextureMagFilter	= 103,
	kQATagGL_TextureMinFilter	= 104,
	kQATagGL_ScissorXMin		= 105,
	kQATagGL_ScissorYMin		= 106,
	kQATagGL_ScissorXMax		= 107,
	kQATagGL_ScissorYMax		= 108,
	kQATagGL_BlendSrc		= 109,
	kQATagGL_BlendDst		= 110,
	kQATagGL_LinePattern		= 111,
	kQATagGL_AreaPattern0		= 117,
	kQATagGL_AreaPattern31		= 148,
	kQATag_EngineSpecificMinimum	= 1000
} TQATagInt;

typedef enum TQATagFloat {
	kQATag_ColorBG_a	= 1,
	kQATag_ColorBG_r	= 2,
	kQATag_ColorBG_g	= 3,
	kQATag_ColorBG_b	= 4,
	kQATag_Width		= 5,
	kQATag_ZMinOffset	= 6,
	kQATag_ZMinScale	= 7,
	kQATag_DepthBG		= 112,
	kQATag_TextureBorder_a	= 113,
	kQATag_TextureBorder_r	= 114,
	kQATag_TextureBorder_g	= 115,
	kQATag_TextureBorder_b	= 116
} TQATagFloat;

typedef enum TQATagPtr {
	kQATag_Texture		= 13
} TQATagPtr;

/* values for kQATag_ZFunction */
#define kQAZFunction_None	0
#define kQAZFunction_LT		1
#define kQAZFunction_EQ		2
#define kQAZFunction_LE		3
#define kQAZFunction_GT		4
#define kQAZFunction_NE		5
#define kQAZFunction_GE		6
#define kQAZFunction_True	7

/* values for kQATag_Antialias */
#define kQAAntiAlias_Off	0
#define kQAAntiAlias_Fast	1
#define kQAAntiAlias_Mid	2
#define kQAAntiAlias_Best	3

/* values for kQATag_Blend */
#define kQABlend_PreMultiply	0
#define kQABlend_Interpolate	1
#define kQABlend_OpenGL		2

/* values for kQATag_PerspectiveZ */
#define kQAPerspectiveZ_Off	0
#define kQAPerspectiveZ_On	1

/* values for kQATag_TextureFilter */
#define kQATextureFilter_Fast	0
#define kQATextureFilter_Mid	1
#define kQATextureFilter_Best	2

/* masks for kQATag_TextureOp */
#define kQATextureOp_None	0
#define kQATextureOp_Modulate	(1 << 0)
#define kQATextureOp_Highlight	(1 << 1)
#define kQATextureOp_Decal	(1 << 2)
#define kQATextureOp_Shrink	(1 << 3)

/* values for kQATag_CSGTag */
#define kQACSGTag_None	0xffffffffUL
#define kQACSGTag_0	0xffffffffUL
#define kQACSGTag_1	0xffffffffUL
#define kQACSGTag_2	0xffffffffUL
#define kQACSGTag_3	0xffffffffUL
#define kQACSGTag_4	0xffffffffUL

#define kQABufferComposite_None		0
#define kQABufferComposite_PreMultiply	1
#define kQABufferComposite_Interpolate	2

/* values for kQATagGL_TextureWrapU and kQATagGL_TextureWrapV */
#define kQAGL_Repeat		0
#define kQAGL_Clamp		1

/* values for kQATagGL_BlendSrc */
#define kQAGL_SourceBlend_XXX		0

/* values for kQATagGL_BlendDst */
#define kQAGL_DestBlend_XXX		0

/* masks for kQATagGL_DrawBuffer */
#define kQAGL_DrawBuffer_None		0
#define kQAGL_DrawBuffer_FrontLeft	(1 << 0)
#define kQAGL_DrawBuffer_FrontRight	(1 << 1)
#define kQAGL_DrawBuffer_BackLeft	(1 << 2)
#define kQAGL_DrawBuffer_BackRight	(1 << 3)
#define	kQAGL_DrawBuffer_Front		\
			(kQAGL_DrawBuffer_FrontLeft | kQAGL_DrawBuffer_FrontRight)
#define	kQAGL_DrawBuffer_Back		\
			(kQAGL_DrawBuffer_BackLeft | kQAGL_DrawBuffer_BackRight)

/* values for kQATag_Width */
#define kQAMaxWidth			128.0

typedef enum TQAVertexMode {
	kQAVertexMode_Point		= 0,
	kQAVertexMode_Line		= 1,
	kQAVertexMode_Polyline		= 2,
	kQAVertexMode_Tri		= 3,
	kQAVertexMode_Strip		= 4,
	kQAVertexMode_Fan		= 5,
	kQAVertexMode_NumModes		= 6,
} TQAVertexMode;

typedef enum TQAGestaltSelector {
	kQAGestalt_OptionalFeatures	= 0,
	kQAGestalt_FastFeatures		= 1,
	kQAGestalt_VendorID		= 2,
	kQAGestalt_EngineID		= 3,
	kQAGestalt_Revision		= 4,
	kQAGestalt_ASCIINameLength	= 5,
	kQAGestalt_ASCIIName		= 6,
	kQAGestalt_TextureMemory	= 7,
	kQAGestalt_FastTextureMemory	= 8,
	kQAGestalt_NumSelectors		= 9
} TQAGestaltSelector;

#define kQAOptional_None		0
#define kQAOptional_DeepZ		(1 << 0)
#define kQAOptional_Texture		(1 << 1)
#define kQAOptional_TextureHQ		(1 << 2)
#define kQAOptional_TextureColor	(1 << 3)
#define kQAOptional_Blend		(1 << 4)
#define kQAOptional_BlendAlpha		(1 << 5)
#define kQAOptional_Antialias		(1 << 6)
#define kQAOptional_ZSorted		(1 << 7)
#define kQAOptional_PerspectiveZ	(1 << 8)
#define kQAOptional_OpenGL		(1 << 9)
#define kQAOptional_NoClear		(1 << 10)
#define kQAOptional_CSG			(1 << 11)
#define kQAOptional_BoundToDevice	(1 << 12)
#define kQAOptional_CL4			(1 << 13)
#define kQAOptional_CL8			(1 << 14)
#define kQAOptional_BufferComposite	(1 << 15)


#define kQAFast_None				0
#define kQAFast_Line				(1 << 0)
#define kQAFast_Gouraud				(1 << 1)
#define kQAFast_Texture				(1 << 2)
#define kQAFast_TextureHQ			(1 << 3)
#define kQAFast_Blend				(1 << 4)
#define kQAFast_Antialiasing 			(1 << 5)
#define kQAFast_ZSorted				(1 << 6)
#define kQAFast_CL4				(1 << 7)
#define kQAFast_CL8				(1 << 8)

#define kQAVendor_BestChoice		(-1)
#define kQAVendor_phase5		100
#define kQAVendor_Eyelight		101

#define kQATriFlags_None		0
#define kQATriFlags_Backfacing		(1 << 0)

#define kQATexture_None			0
#define kQATexture_Lock			(1 << 0)
#define kQATexture_Mipmap		(1 << 1)
#define kQATexture_NoCompression	(1 << 2)
#define kQATexture_HighCompression	(1 << 3)


#define kQABitmap_None			0
#define kQABitmap_Lock			(1 << 1)
#define kQABitmap_NoCompression		(1 << 2)
#define kQABitmap_HighCompression	(1 << 3)

#define kQAContext_None			0
#define kQAContext_NoZBuffer		(1 << 0)
#define kQAContext_DeepZ		(1 << 1)
#define kQAContext_DoubleBuffer		(1 << 2)
#define kQAContext_Cache		(1 << 3)

typedef enum TQAEngineMethodTag {
	kQADrawPrivateNew		= 0,
	kQADrawPrivateDelete		= 1,
	kQAEngineCheckDevice		= 2,
	kQAEngineGestalt		= 3,
	kQATextureNew			= 4,
	kQATextureDetach		= 5,
	kQATextureDelete		= 6,
	kQABitmapNew			= 7,
	kQABitmapDetach			= 8,
	kQABitmapDelete			= 9,
	kQAColorTableNew		= 10,
	kQAColorTableDelete		= 11,
	kQATextureBindColorTable	= 12,
	kQABitmapBindColorTable		= 13
} TQAEngineMethodTag;

typedef enum TQADrawMethodTag {
	kQASetFloat			= 0,
	kQASetInt			= 1,
	kQASetPtr			= 2,
	kQAGetFloat			= 3,
	kQAGetInt			= 4,
	kQAGetPtr			= 5,
	kQADrawPoint			= 6,
	kQADrawLine			= 7,
	kQADrawTriGouraud		= 8,
	kQADrawTriTexture		= 9,
	kQADrawVGouraud			= 10,
	kQADrawVTexture			= 11,
	kQADrawBitmap			= 12,
	kQARenderStart			= 13,
	kQARenderEnd			= 14,
	kQARenderAbort			= 15,
	kQAFlush			= 16,
	kQASync				= 17,
	kQASubmitVerticesGouraud	= 18,
	kQASubmitVerticesTextures	= 19,
	kQADrawTriMeshGouraud		= 20,
	kQADrawTriMeshTexture		= 21,
	kQASetNoticeMethod		= 22,
	kQAGetNoticeMethod		= 23
} TQADrawMethodTag;

typedef enum TQAMethodSelectors {
	kQAMethod_RenderCompletion	= 0,
	kQAMethod_DisplayModeChanged	= 1,
	kQAMethod_ReloadTextures	= 2,
	kQAMethod_BufferInitialize	= 3,
	kQAMethod_BufferComposite	= 4,
	kQAMethod_NumSelectors		= 5
} TQAMethodSelector;

typedef struct TQAEngine		TQAEngine;
typedef struct TQATexture		TQATexture;
typedef struct TQABitmap		TQABitmap;
typedef struct TQAColorTable		TQAColorTable;
typedef struct TQADrawPrivate		TQADrawPrivate;
typedef APTR	GHandle;
typedef long	TQAError;
typedef APTR	RgnHandle;

typedef struct TQARect {
	long	left;
	long	right;
	long	top;
	long	bottom;
} TQARect;

typedef struct TQAPlatformDevice {
	GHandle	gHandle;
} TQAPlatformDevice;

typedef union TQAPlatformClip {
	RgnHandle	clipRgn;
} TQAPlatformClip;

typedef struct TQADevice {
	TQADeviceType		deviceType;
	TQAPlatformDevice	device;
} TQADevice;

typedef struct TQAClip {
	TQAClipType		clipType;
	TQAPlatformClip		clip;
} TQAClip;

struct TQAImage {
	long	width;
	long	height;
	long	rowBytes;
	void	*pixmap;
};

typedef struct TQAImage TQAImage;

typedef struct TQAVGouraud {
	float	x;
	float	y;
	float	z;
	float	invW;
	float	r;
	float	g;
	float	b;
	float	a;
} TQAVGouraud;

typedef struct TQAVTexture {
	float	x;
	float	y;
	float	z;
	float	invW;
	float	r;
	float	g;
	float	b;
	float	a;
	float	uOverW;
	float	vOverW;
	float	kd_r;
	float	kd_g;
	float	kd_b;
	float	ks_r;
	float	ks_g;
	float	ks_b;
} TQAVTexture;

typedef struct TQAIndexedTriangle {
	unsigned long	triangleFlags;
	unsigned long	vertices[3];
} TQAIndexedTriangle;


typedef struct TQADrawContext TQADrawContext;

typedef	float STDARGS (*TQAGetFloat)(	const TQADrawContext *drawContext, TQATagFloat tag);

typedef	void STDARGS (*TQASetFloat)(	const TQADrawContext *drawContext,
				TQATagFloat tag,
				float newValue); 


typedef	unsigned long STDARGS (*TQAGetInt)(const TQADrawContext *drawContext, TQATagFloat tag);

typedef	void STDARGS (*TQASetInt)(	const TQADrawContext *drawContext,
				TQATagInt tag,
				unsigned long newValue); 


typedef	void STDARGS *(*TQAGetPtr)(	const TQADrawContext *drawContext, TQATagFloat tag);

typedef	void STDARGS (*TQASetPtr)(	const TQADrawContext *drawContext,
				TQATagPtr tag,
				const void *newValue); 

typedef	void STDARGS (*TQADrawPoint)(	const TQADrawContext *drawContext,
				const TQAVGouraud *v); 

typedef	void STDARGS (*TQADrawLine)(	const TQADrawContext *drawContext,
				const TQAVGouraud *v0,
                                const TQAVGouraud *v1); 

typedef	void STDARGS (*TQADrawTriGouraud)(	const TQADrawContext *drawContext,
        				const TQAVGouraud *v0,
                                        const TQAVGouraud *v1,
        				const TQAVGouraud *v2,
                                        unsigned long flags); 

typedef	void STDARGS (*TQADrawTriTexture)(	const TQADrawContext *drawContext,
        				const TQAVTexture *v0,
                                        const TQAVTexture *v1,
        				const TQAVTexture *v2,
                                        unsigned long flags); 

typedef	void STDARGS (*TQASubmitVerticesGouraud)(const TQADrawContext *drawContext,
        				unsigned long nVertices,
                                        const TQAVGouraud *vertices); 

typedef	void STDARGS (*TQASubmitVerticesTexture)(const TQADrawContext *drawContext,
        				unsigned long nVertices,
                                        const TQAVTexture *vertices); 

typedef	void STDARGS (*TQADrawTriMeshGouraud)(	const TQADrawContext *drawContext,
        				unsigned long nTriangles,
                                        const TQAIndexedTriangle *triangles); 

typedef	void STDARGS (*TQADrawTriMeshTexture)(	const TQADrawContext *drawContext,
        				unsigned long nTriangles,
                                        const TQAIndexedTriangle *triangles); 

typedef	void STDARGS (*TQADrawVGouraud)(	const TQADrawContext *drawContext,
        				unsigned long nVertices,
					TQAVertexMode vertexMode,
					const TQAVGouraud vertices[],
					const unsigned long flags[]);

typedef	void STDARGS (*TQADrawVTexture)(	const TQADrawContext *drawContext,
        				unsigned long nVertices,
					TQAVertexMode vertexMode,
					const TQAVTexture vertices[],
					const unsigned long flags[]);

typedef	void STDARGS (*TQADrawBitmap)(		const TQADrawContext *drawContext,
					const TQAVGouraud *v,
					TQABitmap *bitmap);

typedef void STDARGS (*TQARenderStart)(		const TQADrawContext *drawContext,
					const TQARect *dirtyRect,
					const TQADrawContext *initialContext);

typedef void STDARGS (*TQARenderEnd)(		const TQADrawContext *drawContext,
					const TQARect *modifiedRect);

typedef TQAError STDARGS (*TQARenderAbort)(const TQADrawContext *drawContext);

typedef TQAError STDARGS (*TQAFlush)(const TQADrawContext *drawContext);

typedef TQAError STDARGS (*TQASync)(const TQADrawContext *drawContext);


typedef void STDARGS (*TQAStandardNoticeMethod)(
				const TQADrawContext *drawContext, void *refCon);

typedef void STDARGS (*TQABufferNoticeMethod)(
				const TQADrawContext *drawContext,
				const TQADevice *buffer,
				const TQARect *dirtyRect,
				void *refCon);


typedef union TQANoticeMethod {
	TQAStandardNoticeMethod	standardNoticeMethod;
	TQABufferNoticeMethod	bufferNoticeMethod;
} TQANoticeMethod;

typedef TQAError STDARGS (*TQAGetNoticeMethod)(	const TQADrawContext *drawContext,
					TQAMethodSelector method,
					TQANoticeMethod *completionCallBack,
					void **refCon);

typedef TQAError STDARGS (*TQASetNoticeMethod)(	const TQADrawContext *drawContext,
					TQAMethodSelector method,
					TQANoticeMethod *completionCallBack,
					void **refCon);

typedef TQAError STDARGS (*TQADrawPrivateNew)(	TQADrawContext *newDrawContext,
					const TQADevice *device,
					const TQARect *rect,
					const TQAClip *clip,
					unsigned long flags);

typedef void STDARGS (*TQADrawPrivateDelete)(	TQADrawPrivate *drawPrivate);

typedef TQAError (*TQAEngineCheckDevice)(const TQADevice *device);

typedef TQAError (*TQAEngineGestalt)(TQAGestaltSelector selector, void *response);


typedef TQAError (*TQAColorTableNew)(	TQAColorTableType tableType,
					void *pixelData,
					long transparentIndexFlag,
					TQAColorTable **newTable);

typedef void (*TQAColorTableDelete)(TQAColorTable *colorTable);


typedef TQAError (*TQATextureNew)(	unsigned long flags,
					TQAImagePixelType pixelType,
					const TQAImage images[],
					TQATexture **newTexture);

typedef TQAError (*TQATextureDetach)(TQATexture *texture);

typedef TQAError (*TQATextureBindColorTable)(
				TQATexture *texture,
				TQAColorTable *colorTable);

typedef void (*TQATextureDelete)(TQATexture *texture);

typedef TQAError (*TQABitmapNew)(	unsigned long flags,
				TQAImagePixelType pixelType,
				const TQAImage *image,
				TQABitmap **newBitmap);

typedef TQAError (*TQABitmapBindColorTable)(
				TQABitmap *bitmap,
				TQAColorTable *colorTable);

typedef TQAError (*TQABitmapDetach)(TQABitmap *bitmap);


typedef void (*TQABitmapDelete)(TQABitmap *bitmap);


struct TQADrawContext {
	TQADrawPrivate			*drawPrivate;
	const TQAVersion		version;
	TQASetFloat			setFloat;
	TQASetInt			setInt;
	TQASetPtr			setPtr;
	TQAGetFloat			getFloat;
	TQAGetInt			getInt;
	TQAGetPtr			getPtr;
	TQADrawPoint			drawPoint;
	TQADrawLine			drawLine;
	TQADrawTriGouraud		drawTriGouraud;
	TQADrawTriTexture		drawTriTexture;
	TQADrawVGouraud			drawVGouraud;
	TQADrawVTexture			drawVTexture;
	TQADrawBitmap			drawBitmap;
	TQARenderStart			renderStart;
	TQARenderEnd			renderEnd;
	TQARenderAbort			renderAbort;
	TQAFlush			flush;
	TQASync				sync;
	TQASubmitVerticesGouraud	submitVerticesGouraud;
	TQASubmitVerticesTexture	submitVerticesTexture;
	TQADrawTriMeshGouraud		drawTriMeshGouraud;
	TQADrawTriMeshTexture		drawTriMeshTexture;
	TQASetNoticeMethod		setNoticeMethod;
	TQAGetNoticeMethod		getNoticeMethod;
};

typedef union TQAEngineMethod {
	TQADrawPrivateNew		drawPrivateNew;
	TQADrawPrivateDelete		drawPrivateDelete;
	TQAEngineCheckDevice		engineCheckDevice;
	TQAEngineGestalt		engineGestalt;
	TQATextureNew			textureNew;
	TQATextureDetach		textureDetach;
	TQATextureDelete		textureDelete;
	TQABitmapNew			bitmapNew;
	TQABitmapDetach			bitmapDetach;
	TQABitmapDelete			bitmapDelete;
	TQAColorTableNew		colorTableNew;
	TQAColorTableDelete		colorTableDelete;
	TQATextureBindColorTable	textureBindColorTable;
	TQABitmapBindColorTable		bitmapBindColorTable;
} TQAEngineMethod;

typedef TQAError (*TQAEngineGetMethod)(
				TQAEngineMethodTag methodTag,
				TQAEngineMethod *method);

typedef union TQADrawMethod {
	TQASetFloat			setFloat;
	TQASetInt			setInt;
	TQASetPtr			setPtr;
	TQAGetFloat			getFloat;
	TQAGetInt			getInt;
	TQAGetPtr			getPtr;
	TQADrawPoint			drawPoint;
	TQADrawLine			drawLine;
	TQADrawTriGouraud		drawTriGouraud;
	TQADrawTriTexture		drawTriTexture;
	TQADrawVGouraud			drawVGouraud;
	TQADrawVTexture			drawVTexture;
	TQADrawBitmap			drawBitmap;
	TQARenderStart			renderStart;
	TQARenderEnd			renderEnd;
	TQARenderAbort			renderAbort;
	TQAFlush			flush;
	TQASync				sync;
	TQASubmitVerticesGouraud	submitVerticesGouraud;
	TQASubmitVerticesTexture	submitVerticesTexture;
	TQADrawTriMeshGouraud		drawTriMeshGouraud;
	TQADrawTriMeshTexture		drawTriMeshTexture;
	TQASetNoticeMethod		setNoticeMethod;
	TQAGetNoticeMethod		getNoticeMethod;
} TQADrawMethod;


#define kQANoErr			0	// no error
#define kQAError			1	// generic error code
#define kQAOutOfMemory			2	// Insufficient memory for requested operation
#define kQANotSupported			3	// Requested feature is not supported
#define kQAOutOfDate			4	// A newer drawing engine was registered
#define kQAParamErr			5	// Invalid parameter
#define kQAGestaltUnknown		6	// Requested Gestalt type isn't available
#define KQADisplayModeUnsupported	7	// Engine cannot render to the display
						// in it's current mode

#endif
