Move SMaterial std::hash impl to its header
[minetest.git] / irr / src / COpenGLCacheHandler.cpp
blob577967c561c04c77a3e4f6994cf41944d2fd9629
1 // Copyright (C) 2015 Patryk Nadrowski
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in Irrlicht.h
5 #include "COpenGLCacheHandler.h"
7 #ifdef _IRR_COMPILE_WITH_OPENGL_
9 #include "COpenGLDriver.h"
11 namespace irr
13 namespace video
16 /* COpenGLCacheHandler */
18 COpenGLCacheHandler::COpenGLCacheHandler(COpenGLDriver *driver) :
19 COpenGLCoreCacheHandler<COpenGLDriver, COpenGLTexture>(driver), AlphaMode(GL_ALWAYS), AlphaRef(0.f), AlphaTest(false),
20 MatrixMode(GL_MODELVIEW), ClientActiveTexture(GL_TEXTURE0), ClientStateVertex(false),
21 ClientStateNormal(false), ClientStateColor(false), ClientStateTexCoord0(false)
23 // Initial OpenGL values from specification.
25 glAlphaFunc(AlphaMode, AlphaRef);
26 glDisable(GL_ALPHA_TEST);
28 glMatrixMode(MatrixMode);
30 Driver->irrGlClientActiveTexture(ClientActiveTexture);
32 glDisableClientState(GL_VERTEX_ARRAY);
33 glDisableClientState(GL_NORMAL_ARRAY);
34 glDisableClientState(GL_COLOR_ARRAY);
35 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
38 COpenGLCacheHandler::~COpenGLCacheHandler()
42 void COpenGLCacheHandler::setAlphaFunc(GLenum mode, GLclampf ref)
44 if (AlphaMode != mode || AlphaRef != ref) {
45 glAlphaFunc(mode, ref);
47 AlphaMode = mode;
48 AlphaRef = ref;
52 void COpenGLCacheHandler::setAlphaTest(bool enable)
54 if (AlphaTest != enable) {
55 if (enable)
56 glEnable(GL_ALPHA_TEST);
57 else
58 glDisable(GL_ALPHA_TEST);
59 AlphaTest = enable;
63 void COpenGLCacheHandler::setClientState(bool vertex, bool normal, bool color, bool texCoord0)
65 if (ClientStateVertex != vertex) {
66 if (vertex)
67 glEnableClientState(GL_VERTEX_ARRAY);
68 else
69 glDisableClientState(GL_VERTEX_ARRAY);
71 ClientStateVertex = vertex;
74 if (ClientStateNormal != normal) {
75 if (normal)
76 glEnableClientState(GL_NORMAL_ARRAY);
77 else
78 glDisableClientState(GL_NORMAL_ARRAY);
80 ClientStateNormal = normal;
83 if (ClientStateColor != color) {
84 if (color)
85 glEnableClientState(GL_COLOR_ARRAY);
86 else
87 glDisableClientState(GL_COLOR_ARRAY);
89 ClientStateColor = color;
92 if (ClientStateTexCoord0 != texCoord0) {
93 setClientActiveTexture(GL_TEXTURE0_ARB);
95 if (texCoord0)
96 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
97 else
98 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
100 ClientStateTexCoord0 = texCoord0;
104 void COpenGLCacheHandler::setMatrixMode(GLenum mode)
106 if (MatrixMode != mode) {
107 glMatrixMode(mode);
108 MatrixMode = mode;
112 void COpenGLCacheHandler::setClientActiveTexture(GLenum texture)
114 if (ClientActiveTexture != texture) {
115 Driver->irrGlClientActiveTexture(texture);
116 ClientActiveTexture = texture;
120 } // end namespace
121 } // end namespace
123 #endif // _IRR_COMPILE_WITH_OPENGL_