#include "stdafx.h"
#include "OGLState.h"
#include "assert.h"

// Class variables
OGLState* OGLState::gState = 0;

/*******************************************************
 * Constructor
 */
OGLState::OGLState()
: mBlendEnableCurrent(0), mBlendFuncCurrent(0), mBGColorCurrent(0), mDepthEnableCurrent(0),
  mTexture2DEnableCurrent(0), mTexture2DCurrent(0), mColorMaskCurrent(0), mMatrixModeCurrent(0),
  mShadeModelCurrent(0)
{	
	// Constructor should NOT change the hardware state yet!
	// Wait until we are set as active state
	mBlendEnable[0] = false;
	mBlendSourceFunc[0] = 0;
	mBlendDestFunc[0] = 0;
	mBGColor[0] = 0;
	mDepthEnable[0] = false;
	mTexture2DEnable[0] = false;
	mTexture2D[0] = 0;
	mColorMask[0] = 0xF;
	mMatrixMode[0] = GL_MODELVIEW;
	mShadeModel[0] = GL_SMOOTH;
}

/*******************************************************
 * Destructor
 */
OGLState::~OGLState()
{
	assert(mColorMaskCurrent == 0);
	assert(mTexture2DCurrent == 0);
	assert(mTexture2DEnableCurrent == 0);
	assert(mDepthEnableCurrent == 0);
	assert(mBlendFuncCurrent == 0);
	assert(mBlendEnableCurrent == 0);
	assert(mMatrixModeCurrent == 0);
	assert(mShadeModelCurrent == 0);
}

/*******************************************************
 * SetState
 *
 * Takes ownership of inState, deletes old state
 */
void 
OGLState::SetState(OGLState* inState)
{
	OGLState* theOld = gState;
	gState = inState;
	if (gState)
	{
		// Set the current top of every stack if it differs from the old state
		if (! theOld || ( theOld->mBlendEnable[theOld->mBlendEnableCurrent] !=
						  gState->mBlendEnable[gState->mBlendEnableCurrent]) )
			if (gState->mBlendEnable[gState->mBlendEnableCurrent])
				glEnable(GL_BLEND);
			else
				glDisable(GL_BLEND);

		if (! theOld || ( theOld->mBlendSourceFunc[theOld->mBlendFuncCurrent] !=
						  gState->mBlendSourceFunc[gState->mBlendFuncCurrent]) ||
						( theOld->mBlendDestFunc[theOld->mBlendFuncCurrent] !=
						  gState->mBlendDestFunc[gState->mBlendFuncCurrent]) )
			glBlendFunc( gState->mBlendSourceFunc[gState->mBlendFuncCurrent],
						 gState->mBlendDestFunc[gState->mBlendFuncCurrent]);

		if (! theOld || ( theOld->mBGColor[theOld->mBGColorCurrent] !=
						  gState->mBGColor[gState->mBGColorCurrent]) )			
		{
			int theRed = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF000000) >> 24;
			int theGreen = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF0000) >> 16;
			int theBlue = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF00) >> 8;
			int theAlpha = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF);
			glClearColor( theRed/255.0, theGreen/255.0, theBlue/255.0, theAlpha/255.0 );
		}

		if (! theOld || ( theOld->mDepthEnable[theOld->mDepthEnableCurrent] !=
						  gState->mDepthEnable[gState->mDepthEnableCurrent]) )
			if (gState->mDepthEnable[gState->mDepthEnableCurrent])
				glEnable(GL_DEPTH);
			else
				glDisable(GL_DEPTH);

		if (! theOld || ( theOld->mTexture2DEnable[theOld->mTexture2DEnableCurrent] !=
						  gState->mTexture2DEnable[gState->mTexture2DEnableCurrent]) )
			if (gState->mTexture2DEnable[gState->mTexture2DEnableCurrent])
				glEnable(GL_TEXTURE_2D);
			else
				glDisable(GL_TEXTURE_2D);

		if (! theOld || ( theOld->mTexture2D[theOld->mTexture2DCurrent] !=
						  gState->mTexture2D[gState->mTexture2DCurrent]) )
			glBindTexture(GL_TEXTURE_2D, gState->mTexture2D[gState->mTexture2DCurrent]);

		if (! theOld || ( theOld->mColorMask[theOld->mColorMaskCurrent] !=
						  gState->mColorMask[gState->mColorMaskCurrent]) )			
			glColorMask( gState->mColorMask[gState->mColorMaskCurrent] & 0x1, 
			             (gState->mColorMask[gState->mColorMaskCurrent] & 0x2) >> 1,
						 (gState->mColorMask[gState->mColorMaskCurrent] & 0x4) >> 2,
						 (gState->mColorMask[gState->mColorMaskCurrent] & 0x8) >> 3);			

		if (! theOld || ( theOld->mMatrixMode[theOld->mMatrixModeCurrent] !=
						  gState->mMatrixMode[gState->mMatrixModeCurrent]) )
			glMatrixMode( gState->mMatrixMode[gState->mMatrixModeCurrent]);

		if (! theOld || ( theOld->mShadeModel[theOld->mShadeModelCurrent] !=
						  gState->mShadeModel[gState->mShadeModelCurrent]) )
			glShadeModel( gState->mShadeModel[gState->mShadeModelCurrent]);
	}
	delete theOld;
}

/////////////////////////////////////////////////////////////////////////////////////////////
//			Blending
/////////////////////////////////////////////////////////////////////////////////////////////

void 
OGLState::SetBlend(bool inEnable)
{
	assert( gState && "SetBlend: No state!\n" );
	if (inEnable != gState->mBlendEnable[gState->mBlendEnableCurrent])
	{
		gState->mBlendEnable[gState->mBlendEnableCurrent] = inEnable;
		if (inEnable)		
			glEnable(GL_BLEND);
		else
			glDisable(GL_BLEND);
	}
}

bool 
OGLState::GetBlend()
{
	assert( gState && "GetBlend: No state!\n" );
	return gState->mBlendEnable[gState->mBlendEnableCurrent];
}

void 
OGLState::PushBlend(bool inEnable)
{
	assert( gState && "PushBlend: No state!\n" );
	if ( ++gState->mBlendEnableCurrent >= MAX_STACK)
	{
		assert("PushBlend stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if (inEnable != gState->mBlendEnable[gState->mBlendEnableCurrent-1])
			if (inEnable)
				glEnable(GL_BLEND);
			else
				glDisable(GL_BLEND);
		
	gState->mBlendEnable[gState->mBlendEnableCurrent] = inEnable;
}

void 
OGLState::PopBlend()
{
	assert( gState && "PopBlend: No state!\n" );
	if (--gState->mBlendEnableCurrent < 0)
	{
		assert("PopBlend stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if (gState->mBlendEnable[gState->mBlendEnableCurrent] != 
			gState->mBlendEnable[gState->mBlendEnableCurrent+1])
			if (gState->mBlendEnable[gState->mBlendEnableCurrent])
				glEnable(GL_BLEND);
			else
				glDisable(GL_BLEND);
}

void 
OGLState::SetBlendFunc(GLenum inBlendSource, GLenum inBlendDest)
{
	assert( gState && "SetBlendFunc: No state!\n" );
	if ( inBlendSource != gState->mBlendSourceFunc[gState->mBlendFuncCurrent] ||
		 inBlendDest != gState->mBlendDestFunc[gState->mBlendFuncCurrent] )
	{
		glBlendFunc(inBlendSource,inBlendDest);
		gState->mBlendSourceFunc[gState->mBlendFuncCurrent] = inBlendSource;
		gState->mBlendDestFunc[gState->mBlendFuncCurrent] = inBlendDest;
	}		
}

void 
OGLState::GetBlendFunc(GLenum& outBlendSource, GLenum& outBlendDest)
{
	assert( gState && "GetBlendFunc: No state!\n" );
	outBlendSource = gState->mBlendSourceFunc[gState->mBlendFuncCurrent];
	outBlendDest = gState->mBlendDestFunc[gState->mBlendFuncCurrent];
}

void 
OGLState::PushBlendFunc(GLenum inBlendSource, GLenum inBlendDest)
{
	assert( gState && "PushBlendFunc: No state!\n" );
	if ( ++gState->mBlendFuncCurrent >= MAX_STACK)
	{
		assert("PushBlendFunc stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if ( inBlendSource != gState->mBlendSourceFunc[gState->mBlendFuncCurrent - 1] ||
			 inBlendDest != gState->mBlendDestFunc[gState->mBlendFuncCurrent - 1] )
			glBlendFunc(inBlendSource,inBlendDest);
		
	gState->mBlendSourceFunc[gState->mBlendFuncCurrent] = inBlendSource;
	gState->mBlendDestFunc[gState->mBlendFuncCurrent] = inBlendDest;
}

void 
OGLState::PopBlendFunc()
{
	assert( gState && "PopBlendFunc: No state!\n" );
	if (--gState->mBlendFuncCurrent < 0)
	{
		assert("PopBlendFunc stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if ( gState->mBlendSourceFunc[gState->mBlendFuncCurrent] != 
			 gState->mBlendSourceFunc[gState->mBlendFuncCurrent + 1] ||
			 gState->mBlendDestFunc[gState->mBlendFuncCurrent] != 
			 gState->mBlendDestFunc[gState->mBlendFuncCurrent + 1] )
			glBlendFunc(gState->mBlendSourceFunc[gState->mBlendFuncCurrent],
						gState->mBlendDestFunc[gState->mBlendFuncCurrent]);
}

/////////////////////////////////////////////////////////////////////////////////////////////
//			BGColor
/////////////////////////////////////////////////////////////////////////////////////////////

void 
OGLState::SetBGColor(int inAlpha, int inRed, int inGreen, int inBlue)
{
	assert( gState && "SetBGColor: No state!\n" );
	inAlpha &= 0xFF;
	inRed &= 0xFF;
	inGreen &= 0xFF;
	inBlue &= 0xFF;
	if ( (inRed<<24) + (inGreen<<16) + (inBlue<<8) + inAlpha != 
		gState->mBGColor[gState->mBGColorCurrent]  )
	{
		glClearColor( inRed/255.0, inGreen/255.0, inBlue/255.0, inAlpha/255.0);
		gState->mBGColor[gState->mBGColorCurrent] = (inRed<<24) + (inGreen<<16) + (inBlue<<8) + inAlpha;
	}
}

void 
OGLState::GetBGColor(int& outAlpha, int& outRed, int& outGreen, int& outBlue)
{
	assert( gState && "GetBGColor: No state!\n" );
	outRed = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF000000) >> 24;
	outGreen = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF0000) >> 16;
	outBlue = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF00) >> 8;
	outAlpha = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF);
}

void 
OGLState::PushBGColor(int inAlpha, int inRed, int inGreen, int inBlue)
{
	assert( gState && "PushBGColor: No state!\n" );
	inAlpha &= 0xFF;
	inRed &= 0xFF;
	inGreen &= 0xFF;
	inBlue &= 0xFF;
	if ( ++gState->mBGColorCurrent >= MAX_STACK)
	{
		assert("PushBGColor stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if ( (inRed<<24) + (inGreen<<16) + (inBlue<<8) + inAlpha != 
			 gState->mBGColor[gState->mBGColorCurrent-1] )
			glClearColor( inRed/255.0, inGreen/255.0, inBlue/255.0, inAlpha/255.0);
		
	gState->mBGColor[gState->mBGColorCurrent] = (inRed<<24) + (inGreen<<16) + (inBlue<<8) + inAlpha;
}

void 
OGLState::PopBGColor()
{
	assert( gState && "PopBGColor: No state!\n" );
	if (--gState->mBGColorCurrent < 0)
	{
		assert("PopBGColor stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if ( gState->mBGColor[gState->mBGColorCurrent] !=
			 gState->mBGColor[gState->mBGColorCurrent+1] )
		{
			int theRed = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF000000) >> 24;
			int theGreen = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF0000) >> 16;
			int theBlue = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF00) >> 8;
			int theAlpha = (gState->mBGColor[gState->mBGColorCurrent] & 0xFF);
			glClearColor( theRed/255.0, theGreen/255.0, theBlue/255.0, theAlpha/255.0 );
		}
}



/////////////////////////////////////////////////////////////////////////////////////////////
//			Depth
/////////////////////////////////////////////////////////////////////////////////////////////
void 
OGLState::SetDepth(bool inEnable)
{
	assert( gState && "SetDepth: No state!\n" );
	if (inEnable != gState->mDepthEnable[gState->mDepthEnableCurrent])
    {
		gState->mDepthEnable[gState->mDepthEnableCurrent] = inEnable;
		if (inEnable)
			glEnable(GL_DEPTH);
		else
			glDisable(GL_DEPTH);
	}
}

bool 
OGLState::GetDepth()
{
	assert( gState && "GetDepth: No state!\n" );
	return gState->mDepthEnable[gState->mDepthEnableCurrent];
}

void 
OGLState::PushDepth(bool inEnable)
{
	assert( gState && "PushDepth: No state!\n" );
	if ( ++gState->mDepthEnableCurrent >= MAX_STACK)
	{
		assert("PushDepth stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if (inEnable != gState->mDepthEnable[gState->mDepthEnableCurrent-1])
			if (inEnable)
				glEnable(GL_DEPTH);
			else
				glDisable(GL_DEPTH);
		
	gState->mDepthEnable[gState->mDepthEnableCurrent] = inEnable;
}

void 
OGLState::PopDepth()
{
	assert( gState && "PopDepth: No state!\n" );
	if (--gState->mDepthEnableCurrent < 0)
	{
		assert("PopDepth stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if (gState->mDepthEnable[gState->mDepthEnableCurrent] != 
			gState->mDepthEnable[gState->mDepthEnableCurrent+1])
			if (gState->mBlendEnable[gState->mBlendEnableCurrent])
				glEnable(GL_DEPTH);
			else
				glDisable(GL_DEPTH);

}

/////////////////////////////////////////////////////////////////////////////////////////////
//			Texture 2D
/////////////////////////////////////////////////////////////////////////////////////////////

void 
OGLState::SetTexture2D(bool inEnable)
{
	assert( gState && "SetTexture2D: No state!\n" );
	if (inEnable != gState->mTexture2DEnable[gState->mTexture2DEnableCurrent])
    {
		gState->mTexture2DEnable[gState->mTexture2DEnableCurrent] = inEnable;
		if (inEnable)
			glEnable(GL_TEXTURE_2D);
		else
			glDisable(GL_TEXTURE_2D);
	}
}

bool 
OGLState::GetTexture2D()
{
	assert( gState && "GetTexture2D: No state!\n" );
	return gState->mTexture2DEnable[gState->mTexture2DEnableCurrent];
}

void 
OGLState::PushTexture2D(bool inEnable)
{
	assert( gState && "PushTexture2D: No state!\n" );
	if ( ++gState->mTexture2DEnableCurrent >= MAX_STACK)
	{
		assert("PushTexture2D stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if (inEnable != gState->mTexture2DEnable[gState->mTexture2DEnableCurrent-1])
			if (inEnable)
				glEnable(GL_TEXTURE_2D);
			else
				glDisable(GL_TEXTURE_2D);
		
	gState->mTexture2DEnable[gState->mTexture2DEnableCurrent] = inEnable;
}

void 
OGLState::PopTexture2D()
{
	assert( gState && "PopTexture2D: No state!\n" );
	if (--gState->mTexture2DEnableCurrent < 0)
	{
		assert("PopTexture2D stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if (gState->mTexture2DEnable[gState->mTexture2DEnableCurrent] != 
			gState->mTexture2DEnable[gState->mTexture2DEnableCurrent+1])
			if (gState->mTexture2DEnable[gState->mTexture2DEnableCurrent])
				glEnable(GL_TEXTURE_2D);
			else
				glDisable(GL_TEXTURE_2D);
}

void 
OGLState::SetTextureUsed(GLuint inTexture)
{
	assert( gState && "SetTextureUsed: No state!\n" );
	if ( inTexture != gState->mTexture2D[gState->mTexture2DCurrent] )
	{
		glBindTexture(GL_TEXTURE_2D, inTexture);
		gState->mTexture2D[gState->mTexture2DCurrent] = inTexture;
	}		
}

GLuint 
OGLState::GetTextureUsed()
{
	assert( gState && "GetTextureUsed: No state!\n" );
	return gState->mTexture2D[gState->mTexture2DCurrent];
}

void 
OGLState::PushTextureUsed(GLuint inTexture)
{
	assert( gState && "PushTextureUsed: No state!\n" );
	if ( ++gState->mTexture2DCurrent >= MAX_STACK)
	{
		assert("PushTextureUsed stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if ( inTexture != gState->mTexture2D[gState->mTexture2DCurrent - 1]  )
			glBindTexture(GL_TEXTURE_2D, inTexture);
		
	gState->mTexture2D[gState->mTexture2DCurrent] = inTexture;
}

void 
OGLState::PopTextureUsed()
{
	assert( gState && "PopTextureUsed: No state!\n" );
	if (--gState->mTexture2DCurrent < 0)
	{
		assert("PopTextureUsed stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if ( gState->mTexture2D[gState->mTexture2DCurrent] != 
			 gState->mTexture2D[gState->mTexture2DCurrent + 1] )
			glBindTexture(GL_TEXTURE_2D, gState->mTexture2D[gState->mTexture2DCurrent]);
}

/////////////////////////////////////////////////////////////////////////////////////////////
//			ColorMask
/////////////////////////////////////////////////////////////////////////////////////////////

void 
OGLState::SetColorMask(bool inAlpha, bool inRed, bool inGreen, bool inBlue )
{
	assert( gState && "SetColorMask: No state!\n" );
	if ( inRed + inGreen*2 + inBlue*4 + inAlpha*8 != 
		gState->mColorMask[gState->mColorMaskCurrent]  )
	{
		glColorMask( inRed, inGreen, inBlue, inAlpha);
		gState->mColorMask[gState->mColorMaskCurrent] = inRed + 2*inGreen + 4*inBlue + 8*inAlpha;
	}
}

void 
OGLState::GetColorMask(bool& outAlpha, bool& outRed, bool& outGreen, bool& outBlue)
{
	assert( gState && "GetColorMask: No state!\n" );
	outRed = gState->mColorMask[gState->mColorMaskCurrent] & 0x1;
	outGreen = (gState->mColorMask[gState->mColorMaskCurrent] & 0x2) >> 1;
	outBlue = (gState->mColorMask[gState->mColorMaskCurrent] & 0x4) >> 2;
	outAlpha = (gState->mColorMask[gState->mColorMaskCurrent] & 0x8) >> 3;
}

void 
OGLState::PushColorMask(bool inAlpha, bool inRed, bool inGreen, bool inBlue)
{
	assert( gState && "PushColorMask: No state!\n" );
	if ( ++gState->mColorMaskCurrent >= MAX_STACK)
	{
		assert("PushColorMask stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if ( inRed + inGreen*2 + inBlue*4 + inAlpha*8 != 
			 gState->mColorMask[gState->mColorMaskCurrent-1] )
			glColorMask( inRed, inGreen, inBlue, inAlpha);
		
	gState->mColorMask[gState->mColorMaskCurrent] = inRed + 2*inGreen + 4*inBlue + 8*inAlpha;
}

void 
OGLState::PopColorMask()
{
	assert( gState && "PopColorMask: No state!\n" );
	if (--gState->mColorMaskCurrent < 0)
	{
		assert("PopColorMask stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if ( gState->mColorMask[gState->mColorMaskCurrent] !=
			 gState->mColorMask[gState->mColorMaskCurrent+1] )
			glColorMask( gState->mColorMask[gState->mColorMaskCurrent] & 0x1, 
			             (gState->mColorMask[gState->mColorMaskCurrent] & 0x2) >> 1,
						 (gState->mColorMask[gState->mColorMaskCurrent] & 0x4) >> 2,
						 (gState->mColorMask[gState->mColorMaskCurrent] & 0x8) >> 3);
}

/////////////////////////////////////////////////////////////////////////////////////////////
//			MatrixMode
/////////////////////////////////////////////////////////////////////////////////////////////

void 
OGLState::SetMatrixMode(GLenum inMatrixMode)
{
	assert( gState && "SetMatrixMode: No state!\n" );
	if ( inMatrixMode != gState->mMatrixMode[gState->mMatrixModeCurrent] )
	{
		glMatrixMode(inMatrixMode);
		gState->mMatrixMode[gState->mMatrixModeCurrent] = inMatrixMode;
	}		
}

GLenum 
OGLState::GetMatrixMode()
{
	assert( gState && "GetMatrixMode: No state!\n" );
	return gState->mMatrixMode[gState->mMatrixModeCurrent];
}

void 
OGLState::PushMatrixMode(GLenum inMatrixMode)
{
	assert( gState && "PushMatrixMode: No state!\n" );
	if ( ++gState->mMatrixModeCurrent >= MAX_STACK)
	{
		assert("PushMatrixMode stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if ( inMatrixMode != gState->mMatrixMode[gState->mMatrixModeCurrent - 1]  )
			glMatrixMode( inMatrixMode );
		
	gState->mMatrixMode[gState->mMatrixModeCurrent] = inMatrixMode;
}

void 
OGLState::PopMatrixMode()
{
	assert( gState && "PopMatrixMode: No state!\n" );
	if (--gState->mMatrixModeCurrent < 0)
	{
		assert("PopMatrixMode stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if ( gState->mMatrixMode[gState->mMatrixModeCurrent] != 
			 gState->mMatrixMode[gState->mMatrixModeCurrent + 1] )
			glMatrixMode( gState->mMatrixMode[gState->mMatrixModeCurrent]);
}

/////////////////////////////////////////////////////////////////////////////////////////////
//			ShadeModel
/////////////////////////////////////////////////////////////////////////////////////////////

void 
OGLState::SetShadeModel(GLenum inShadeModel)
{
	assert( gState && "SetShadeModel: No state!\n" );
	if ( inShadeModel != gState->mShadeModel[gState->mShadeModelCurrent] )
	{
		glShadeModel(inShadeModel);
		gState->mShadeModel[gState->mShadeModelCurrent] = inShadeModel;
	}		
}

GLenum 
OGLState::GetShadeModel()
{
	assert( gState && "GetShadeModel: No state!\n" );
	return gState->mShadeModel[gState->mShadeModelCurrent];
}

void 
OGLState::PushShadeModel(GLenum inShadeModel)
{
	assert( gState && "PushShadeModel: No state!\n" );
	if ( ++gState->mShadeModelCurrent >= MAX_STACK)
	{
		assert("PushShadeModel stack overflow!" == 0);
	}
	else  // only send OpenGL command if necessary
		if ( inShadeModel != gState->mShadeModel[gState->mShadeModelCurrent - 1]  )
			glShadeModel( inShadeModel );
		
	gState->mShadeModel[gState->mShadeModelCurrent] = inShadeModel;
}

void 
OGLState::PopShadeModel()
{
	assert( gState && "PopShadeModel: No state!\n" );
	if (--gState->mShadeModelCurrent < 0)
	{
		assert("PopShadeModel stack underflow!" == 0);
	}
	else // only send OpenGL command if necessary
		if ( gState->mShadeModel[gState->mShadeModelCurrent] != 
			 gState->mShadeModel[gState->mShadeModelCurrent + 1] )
			glShadeModel( gState->mShadeModel[gState->mShadeModelCurrent]);
}
