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"
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
);
52 void COpenGLCacheHandler::setAlphaTest(bool enable
)
54 if (AlphaTest
!= enable
) {
56 glEnable(GL_ALPHA_TEST
);
58 glDisable(GL_ALPHA_TEST
);
63 void COpenGLCacheHandler::setClientState(bool vertex
, bool normal
, bool color
, bool texCoord0
)
65 if (ClientStateVertex
!= vertex
) {
67 glEnableClientState(GL_VERTEX_ARRAY
);
69 glDisableClientState(GL_VERTEX_ARRAY
);
71 ClientStateVertex
= vertex
;
74 if (ClientStateNormal
!= normal
) {
76 glEnableClientState(GL_NORMAL_ARRAY
);
78 glDisableClientState(GL_NORMAL_ARRAY
);
80 ClientStateNormal
= normal
;
83 if (ClientStateColor
!= color
) {
85 glEnableClientState(GL_COLOR_ARRAY
);
87 glDisableClientState(GL_COLOR_ARRAY
);
89 ClientStateColor
= color
;
92 if (ClientStateTexCoord0
!= texCoord0
) {
93 setClientActiveTexture(GL_TEXTURE0_ARB
);
96 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
98 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
100 ClientStateTexCoord0
= texCoord0
;
104 void COpenGLCacheHandler::setMatrixMode(GLenum mode
)
106 if (MatrixMode
!= mode
) {
112 void COpenGLCacheHandler::setClientActiveTexture(GLenum texture
)
114 if (ClientActiveTexture
!= texture
) {
115 Driver
->irrGlClientActiveTexture(texture
);
116 ClientActiveTexture
= texture
;
123 #endif // _IRR_COMPILE_WITH_OPENGL_