//Rouslan Dimitrov, Feb 2006
#pragma once

#include "thread.h"

void rInitFromGLThread();
void rDeInitFromGLThread();

class rRenderer : public rThread
{
public:
	rRenderer();
	~rRenderer();

	bool Create();
	void rThreadLoop();	
	void Update();
	bool Suspend();
	void Resume();	
	void Kill();
	void setAutoStop(bool);
	virtual void setFov(float fov) = 0;
	virtual bool CreateTexture(unsigned int &texture, char* strFileName, bool mipmaps) = 0;
	virtual void DeleteTextures(unsigned int n, unsigned int *textures) = 0;
	virtual void CalculateFrustum() = 0;
	virtual bool IsBoxInFrustum(float x1, float y1, float z1, float x2, float y2, float z2);
	virtual bool IsSphereInFrustum(float x, float y, float z, float g_Renderer) = 0;
	virtual void enableMotionBlur(float accum, float mul) = 0;
	virtual void disableMotionBlur() = 0;
	bool isRendering(){return bRender;}
protected:
	HANDLE hSuspended;
	virtual void OrthoMode() = 0;
	bool bRenderText;
	virtual bool initSubSystem() = 0;

	float clip[16];	//Frustum Culling
	float frustum[6][4];
	
	unsigned int numTextures;
	float accumFactor;
	float mulFactor;
	HDC hDC;
	bool bRender;	//Should be false during load
	bool bMotionBlur;
	bool bStopped;

	friend class rOGLText;
};

class rOpenGL : public rRenderer
{
public:
	~rOpenGL();
	void setFov(float fov);
	void releaseSubSytem();
	bool initSubSystem();
	void enableMotionBlur(float accum, float mul);
	void disableMotionBlur();
	bool CreateTexture(unsigned int &texture, char* strFileName, bool mipmaps);
	void DeleteTextures(unsigned int n, unsigned int *textures);
	bool IsSphereInFrustum(float x, float y, float z, float g_Renderer){return true;};
	void CalculateFrustum();
	void OrthoMode();
private:
	HGLRC hRC;
};
