/*
 *  ltopengl.h
 *  lt
 *
 *  Created by Shane Saxon on 4/4/05.
 *  Copyright 2005-2006 Shane Saxon. All rights reserved.
 *
 */

#ifndef _ltopengl_h_
#define _ltopengl_h_

#include <OpenGL/gl.h>
#include <AGL/agl.h>



#define kTimeLimit 3000000
#define kMaximumPlots 17
#define kGridCount 10
#define kDefaultScale 0.1
#define kColorIndexSize 20
#define kMaximumSampleInterval 65536

enum {
	kFSAAOff = 0,
	kFSAAFast = 1,
	kFSAANice = 2,
	kSamples = 4
};

enum {
	kRawSample = 0,
	kAverage,
	kRootMeanSquare,
	kSmoothed
};

enum {
	kLeftJustify = 0,
	kRightJustify,
	kCenterJustify
};

enum {
	kSmallFont = 0,
	kMediumFont,
	kLargeFont
};

typedef struct {
   GLdouble x,y,z;
} recVec;

typedef struct {
	GLfloat x,y,z;
} GLfloatXYZ;

typedef struct {
	GLfloat angle,x,y,z;
} GLfloatAngleXYZ;

typedef struct {
	GLfloat r,g,b,a;
} GLfloatRGBA;

typedef struct {
	int x,y,z;
} IntegerXYZ;

typedef struct {
	GLubyte r,g,b,a;
} GLubyteRGBA;

typedef struct {
	Boolean x,y,z;
} BooleanXYZ;

typedef struct {
	Boolean angle,x,y,z;
} BooleanAXYZ;

// camera context info
typedef struct {
	recVec viewPos;		// View position
	recVec viewDir;		// View direction vector
	recVec viewUp;			// View up direction
	recVec rotPoint;		// Point to rotate about
	GLfloat aperture;		// camera aperture
	GLint viewWidth,viewHeight;		// current window/screen height and width
	GLfloat viewOriginX, viewOriginY; // always 0 
} recCamera;

struct recPlot
{
	void* pWnd;								//videogl data, contains QT data types,		debug

	int vertexCount;
	int arrayIndex;
	GLfloat *vertexArray;
	GLubyte *colorArray;
	GLubyteRGBA color;					//the current color to assign to new data
	int colorIndex;
	Boolean colorFade;
	Boolean altColorUpdate;
	int previousRecentIndex;

	IntegerXYZ channel;					//data number to use for x,y,z and scale
	
	int sampleInterval;					//number of cycles per sample
	int averageType;
	
	GLfloatXYZ screenPosition;			//screen position of the plot center

	GLfloatAngleXYZ rotate;				//possible use of angling the scale axes
	GLfloatXYZ scale;						//amount to scale plot by
	GLfloatXYZ translate;				//pans the location of the plot

	GLfloatAngleXYZ rotateRate;		//possible use of angling the scale axes
	GLfloatXYZ scaleRate;				//amount to scale plot by
	GLfloatXYZ translateRate;			//pans the location of the plot, pronunciar en Espanol, lol
	
	Boolean hide;							//hides the plot, but still collects data
	Boolean freeze;						//freezes current state of plot 
	Boolean center;						//center with current value at origin
	Boolean centerPerGridSpace;		//when center is on use gridSpace increments
	Boolean scroll;						//scroll with current value on right edge
	Boolean triggerOn;
	Boolean triggerOneShot;
	GLfloat triggerLevel;
	BooleanXYZ autoZoom;
	
	int drawSurface;
	int drawPolygons;
	GLfloat lineWidth;
	GLfloat pointSize;
	GLfloat circle;

	Boolean drawVideo;
	GLfloat bias;
	GLfloat gain;
	
	BooleanXYZ	drawCurrentValue;		//draw the current values
	BooleanXYZ	drawTranslate;			//draw the translate
	BooleanXYZ	drawScale;				//draw the scales for the axes
	BooleanAXYZ drawRotate;
	Boolean		drawPullLimits;
};
typedef struct recPlot recPlot;
typedef struct recPlot *pRecPlot;

// per window view data
struct recContext
{
	int graphType;
	
	pData data;
	
	pRecPlot plotArray[kMaximumPlots];
	int plotIndex;						//the currently active plot
	int plotCount;
	
	AbsoluteTime time;
	
	int gridCount;
	GLfloat gridSpace;
	
	GLfloatXYZ rateVector;
	
	Boolean enableZ;
	BooleanXYZ axes;
	
	Boolean selectAll;
	Boolean lockPlots;
	
	Boolean drawMenu;
	Boolean drawIndicators;
	
	Boolean clearFrameBuffer;
	Boolean clearFrameBufferOnce;
	
	recCamera camera;
	
	// generic OpenGL stuff
	AGLPixelFormat aglPixFmt;
	AGLContext aglContext;
	GLuint bigBoldFontList;
	GLuint boldFontList;
	GLuint regFontList;
	GLint currentVS;
	
	EventLoopTimerRef timer;

	char message[256]; // buffer for message output
	float msgTime; // message posting time for expiration
	
	long modeFSAA;
};
typedef struct recContext recContext;
typedef struct recContext * pRecContext;


void getCurrentCaps (void);
void SetIndexColor (GLubyteRGBA *color, int *colorIndex);
void updateProjection (GLdouble width, GLdouble height, GLdouble zPos, GLdouble aperture);
void DrawGL (WindowRef window, Boolean swap);
pRecContext GetCurrentContextInfo (WindowRef window);

#endif