// ======================================================================
//
// Gl.def
// jeff grills
//
// copyright 1998 origin systems inc
//
// ======================================================================

#ifndef GL_DEF
#define GL_DEF

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

// transformed (screen space) vertex
struct TVertex
{
	real x;
	real y;
	real z;
	real ooz;

	real u;
	real v;

	real r;
	real g;
	real b;
	real m;
	real a;
};

// untransformed (object space) vertex
struct UVertex
{
	int  vertexIndex;
	int  normalIndex;

	real u;
	real v;

	real r;
	real g;
	real b;
	real m;
	real a;
};

// ======================================================================
// clipping flags

// **** WARNING WARNING WARNING ****
// Do not change these values without good reason.  These constants are hard-coded into inline assembly in Xform.cpp

const int CLIP_NEAR         = BINARY2(0000,0001);
const int CLIP_FAR          = BINARY2(0000,0010);
const int CLIP_ABOVE        = BINARY2(0000,0100);
const int CLIP_RIGHT        = BINARY2(0000,1000);
const int CLIP_BELOW        = BINARY2(0001,0000);
const int CLIP_LEFT         = BINARY2(0010,0000);
const int CLIP_ALL          = BINARY2(0011,1111);

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

class ClipInfo
{
public:

	int   x0;
	int   y0;
	int   x1;
	int   y1;
	bool  on;

public:

	bool testVisibility(int x, int y) const;
	void set(int newX0, int newY0, int newX1, int newY1, bool newOn);
	int  clipFlags(int x, int y) const;
};

// ----------------------------------------------------------------------

inline bool ClipInfo::testVisibility(int x, int y) const
{
	return (!on || (x >= x0 && y >= y0 && x <= x1 && y <= y1));
}

// ----------------------------------------------------------------------

inline void ClipInfo::set(int newX0, int newY0, int newX1, int newY1, bool newOn)
{
	x0 = newX0;
	y0 = newY0;
	x1 = newX1;
	y1 = newY1;
	on = newOn;
}

// ----------------------------------------------------------------------

inline int ClipInfo::clipFlags(int x, int y) const
{
	int flags = 0;

	if (on)
	{
		if (x > x1)
			flags |= CLIP_RIGHT;
		else
			if (x < x0)
				flags |= CLIP_LEFT;

		if (y < y0)
			flags |= CLIP_ABOVE;
		else
			if (y > y1)
				flags |= CLIP_BELOW;
	}

	return flags;
}

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

enum PrimitiveProcessing
{
	PP_PassAll,
	PP_QueueAll,
	PP_CheckMaterial,
	PP_CheckVertices,
	PP_CheckMaterialAndVertices
};

enum AlphaBlendFunction
{
	ABF_Zero,
	ABF_One,
	ABF_SourceColor,
	ABF_InverseSourceColor,
	ABF_SourceAlpha,
	ABF_InverseSourceAlpha,
	ABF_DestinationAlpha,
	ABF_InverseDestinationAlpha,
	ABF_DestinationColor,
	ABF_InverseDestinationColor,
	ABF_SourceAlphaSaturate
};

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

#endif
