forked from ianyyin/artoolkit5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglStateCache2.h
140 lines (123 loc) · 4.65 KB
/
glStateCache2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* glStateCache2.h
* ARToolKit5
*
* This file is part of ARToolKit.
*
* ARToolKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARToolKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ARToolKit. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent modules, and to
* copy and distribute the resulting executable under terms of your choice,
* provided that you also meet, for each linked independent module, the terms and
* conditions of the license of that module. An independent module is a module
* which is neither derived from nor based on this library. If you modify this
* library, you may extend this exception to your version of the library, but you
* are not obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Copyright 2015 Daqri, LLC.
* Copyright 2009-2015 ARToolworks, Inc.
*
* Author(s): Philip Lamb
*
*/
// glStateCache optimises OpenGL ES on implementations where
// changes in GL state are expensive, by eliminating redundant
// changes to state.
#ifndef __glStateCache2_h__
#define __glStateCache2_h__
#ifndef DISABLE_GL_STATE_CACHE
#if defined ANDROID
# include <GLES2/gl2.h>
# include <GLES2/gl2ext.h>
#else
# include <OpenGLES/ES2/gl.h>
# include <OpenGLES/ES2/glext.h>
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
//
// Use of the state cache:
//
// Prior to drawing, a given piece of code should set the state
// it prefers using the calls below. All code that uses the state
// cache should refrain from querying state, and refrain from saving
// and restoring state. The state cache maintains track of the current
// state and no GL calls to make state changes will be made if the
// requested state is already set.
//
// One additional note: If you have some code in your application
// which does NOT use the state cache routines, then the state cache's
// record of the state of the GL machine may be erroneous. In this
// case you will have to call glStateCacheFlush() at the beginning
// of the section of your code which DOES cache state.
//
// Tells the state cache that changes to state have been made
// elsewhere, and that the cache should be emptied.
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCacheFlush()
#else
void glStateCacheFlush();
#endif
#define glStateCacheBeginAgain glStateCacheFlush // Deprecated name.
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCacheEnableDepthTest() glEnable(GL_DEPTH_TEST)
#define glStateCacheDisableDepthTest() glDisable(GL_DEPTH_TEST)
#define glStateCacheEnableBlend() glEnable(GL_BLEND)
#define glStateCacheDisableBlend() glDisable(GL_BLEND)
#else
void glStateCacheEnableDepthTest();
void glStateCacheDisableDepthTest();
void glStateCacheEnableBlend();
void glStateCacheDisableBlend();
#endif
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCacheActiveTexture(texture) glActiveTexture(texture)
#else
#define GLSTATECACHE_MAX_COMBINED_TEXTURE_IMAGE_UNITS 8 // Minimum value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS is 8
void glStateCacheActiveTexture(GLuint texture);
#endif
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCacheBindTexture2D(name) glBindTexture(GL_TEXTURE_2D, name)
#else
void glStateCacheBindTexture2D(GLuint name);
#endif
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCacheBlendFunc(sfactor, dfactor) glBlendFunc(sfactor, dfactor)
#else
void glStateCacheBlendFunc(GLenum sfactor, GLenum dfactor);
#endif
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCacheColorMask(red, green, blue, alpha) glColorMask(red, green, blue, alpha)
#else
void glStateCacheColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
#endif
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCacheDepthMask(flag) glDepthMask(flag)
#else
void glStateCacheDepthMask(GLboolean flag);
#endif
#ifdef DISABLE_GL_STATE_CACHE
#define glStateCachePixelStoreUnpackAlignment(param) glPixelStorei(GL_UNPACK_ALIGNMENT, param)
#else
void glStateCachePixelStoreUnpackAlignment(GLint param);
#endif
#ifdef __cplusplus
}
#endif
#endif // !__glStateCache2_h__