/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: src/drivers/common/opengl/oglstates.hpp

*/

#ifndef SGX_OPENGL_STATES_HPP
#define SGX_OPENGL_STATES_HPP	1


class sgxTexEnvState : public sgxStateTemplate<GLint> {
public:
	virtual tBOOL doApply() 
	{
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, state);
		return TRUE;
	}
};

class sgxBindTexState : public sgxStateTemplate<GLint> {
public:
	virtual tBOOL doApply() 
	{
		glBindTexture(GL_TEXTURE_2D, state);
		return TRUE;
	}
};

class oglBlend {
public:
	GLenum	src;
	GLenum	dest;

	oglBlend() { src = GL_SRC_ALPHA; dest = GL_ONE_MINUS_SRC_ALPHA; }
	oglBlend(GLenum s, GLenum d) { src = s; dest = d; }

	SGX_INLINE bool operator != (const oglBlend &rhs) const { return src!=rhs.src || dest!=rhs.dest; }
};

class sgxBlendFuncState : public sgxStateTemplate<oglBlend> {
public:
	virtual tBOOL doApply() 
	{
		glBlendFunc(state.src, state.dest);
		return TRUE;
	}
};

class oglMatrix
{
public:
	oglMatrix();	// identity
	oglMatrix(const sgxVector3 &pos);
	oglMatrix(const sgxMatrix43 &transform);
	~oglMatrix();

	static void convertToSgx(sgxMatrix43 &transform, const GLfloat *m44);
	static void convertToSgx(sgxMatrix44 &transform, const GLfloat *m44);
	static void convertToGL(GLfloat *m44, const sgxMatrix43 &transform);
	static void convertToGL(GLfloat *m44, const sgxMatrix44 &transform);
};

class sgxMatrixState : public sgxStateTemplate<GLenum> {
public:
	virtual tBOOL doApply() 
	{ 
		glMatrixMode(state); 
		return bDirty; 
	}
};

#endif /* SGX_OPENGL_STATES_HPP */
