1 // Copyright (C) 2015 Patryk Nadrowski
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in Irrlicht.h
\r
5 #include "COpenGLCacheHandler.h"
\r
7 #ifdef _IRR_COMPILE_WITH_OPENGL_
\r
9 #include "COpenGLDriver.h"
\r
16 /* COpenGLCacheHandler */
\r
18 COpenGLCacheHandler::COpenGLCacheHandler(COpenGLDriver* driver) :
\r
19 COpenGLCoreCacheHandler<COpenGLDriver, COpenGLTexture>(driver), AlphaMode(GL_ALWAYS), AlphaRef(0.f), AlphaTest(false),
\r
20 MatrixMode(GL_MODELVIEW), ClientActiveTexture(GL_TEXTURE0), ClientStateVertex(false),
\r
21 ClientStateNormal(false), ClientStateColor(false), ClientStateTexCoord0(false)
\r
23 // Initial OpenGL values from specification.
\r
25 glAlphaFunc(AlphaMode, AlphaRef);
\r
26 glDisable(GL_ALPHA_TEST);
\r
28 glMatrixMode(MatrixMode);
\r
30 Driver->irrGlClientActiveTexture(ClientActiveTexture);
\r
32 glDisableClientState(GL_VERTEX_ARRAY);
\r
33 glDisableClientState(GL_NORMAL_ARRAY);
\r
34 glDisableClientState(GL_COLOR_ARRAY);
\r
35 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
\r
38 COpenGLCacheHandler::~COpenGLCacheHandler()
\r
42 void COpenGLCacheHandler::setAlphaFunc(GLenum mode, GLclampf ref)
\r
44 if (AlphaMode != mode || AlphaRef != ref)
\r
46 glAlphaFunc(mode, ref);
\r
53 void COpenGLCacheHandler::setAlphaTest(bool enable)
\r
55 if (AlphaTest != enable)
\r
58 glEnable(GL_ALPHA_TEST);
\r
60 glDisable(GL_ALPHA_TEST);
\r
65 void COpenGLCacheHandler::setClientState(bool vertex, bool normal, bool color, bool texCoord0)
\r
67 if (ClientStateVertex != vertex)
\r
70 glEnableClientState(GL_VERTEX_ARRAY);
\r
72 glDisableClientState(GL_VERTEX_ARRAY);
\r
74 ClientStateVertex = vertex;
\r
77 if (ClientStateNormal != normal)
\r
80 glEnableClientState(GL_NORMAL_ARRAY);
\r
82 glDisableClientState(GL_NORMAL_ARRAY);
\r
84 ClientStateNormal = normal;
\r
87 if (ClientStateColor != color)
\r
90 glEnableClientState(GL_COLOR_ARRAY);
\r
92 glDisableClientState(GL_COLOR_ARRAY);
\r
94 ClientStateColor = color;
\r
97 if (ClientStateTexCoord0 != texCoord0)
\r
99 setClientActiveTexture(GL_TEXTURE0_ARB);
\r
102 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
\r
104 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
\r
106 ClientStateTexCoord0 = texCoord0;
\r
110 void COpenGLCacheHandler::setMatrixMode(GLenum mode)
\r
112 if (MatrixMode != mode)
\r
114 glMatrixMode(mode);
\r
119 void COpenGLCacheHandler::setClientActiveTexture(GLenum texture)
\r
121 if (ClientActiveTexture != texture)
\r
123 Driver->irrGlClientActiveTexture(texture);
\r
124 ClientActiveTexture = texture;
\r
131 #endif // _IRR_COMPILE_WITH_OPENGL_
\r