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