OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreGLES2Prerequisites.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __GLES2Prerequisites_H__
30 #define __GLES2Prerequisites_H__
31 
32 #include "OgrePrerequisites.h"
33 #include "OgreLogManager.h"
34 #include "OgreMath.h"
35 
36 #ifndef GL_GLEXT_PROTOTYPES
37 # define GL_GLEXT_PROTOTYPES
38 #endif
39 
40 #if OGRE_NO_GLES3_SUPPORT == 0
41 # include <GLES3/gles3w.h>
42 #else
43 # include <GLES2/gles2w.h>
44 #endif
45 
46 #if (OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS)
47 # ifdef __OBJC__
48 # include <OpenGLES/EAGL.h>
49 # if OGRE_NO_GLES3_SUPPORT == 0
50 # define __gl_es20_h_
51 # define __gl_es20ext_h_
52 # ifndef GL_GLEXT_PROTOTYPES
53 # define GL_GLEXT_PROTOTYPES
54 # endif
55 # endif
56 # endif
57 #elif (OGRE_PLATFORM == OGRE_PLATFORM_ANDROID) || (OGRE_PLATFORM == OGRE_PLATFORM_NACL)
58 # ifndef GL_GLEXT_PROTOTYPES
59 # define GL_GLEXT_PROTOTYPES
60 # endif
61 # if OGRE_NO_GLES3_SUPPORT == 0
62 # include <GLES3/gl3platform.h>
63 # include <GLES3/gl3.h>
64 # else
65 # include <GLES2/gl2platform.h>
66 # include <GLES2/gl2.h>
67 # include <GLES2/gl2ext.h>
68 # endif
69 # if (OGRE_PLATFORM == OGRE_PLATFORM_NACL)
70 # include "ppapi/cpp/completion_callback.h"
71 # include "ppapi/cpp/instance.h"
72 # include "ppapi/c/ppp_graphics_3d.h"
73 # include "ppapi/cpp/graphics_3d.h"
74 # include "ppapi/cpp/graphics_3d_client.h"
75 # include "ppapi/gles2/gl2ext_ppapi.h"
76 # undef GL_OES_get_program_binary
77 # undef GL_OES_mapbuffer
78 # undef GL_OES_vertex_array_object
79 # endif
80 #else
81 # if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32)
82 # if !defined( __MINGW32__ )
83 # define __PRETTY_FUNCTION__ __FUNCTION__
84 # ifndef WIN32_LEAN_AND_MEAN
85 # define WIN32_LEAN_AND_MEAN 1
86 # endif
87 # ifndef NOMINMAX
88 # define NOMINMAX // required to stop windows.h messing up std::min
89 # endif
90 # endif
91 # endif
92 # undef GL_GLEXT_PROTOTYPES
93 # if OGRE_NO_GLES3_SUPPORT == 0
94 # include <GLES3/gl3platform.h>
95 # include <GLES3/gl3.h>
96 # else
97 # include <GLES2/gl2.h>
98 # include <GLES2/gl2ext.h>
99 # endif
100 # include <EGL/egl.h>
101 #endif
102 
103 #if (OGRE_NO_ETC_CODEC == 0)
104 # ifndef GL_OES_compressed_ETC1_RGB8_texture
105 # define GL_OES_compressed_ETC1_RGB8_texture 1
106 # define GL_ETC1_RGB8_OES 0x8D64
107 # endif
108 # define GL_COMPRESSED_RGB8_ETC2 0x9274
109 # define GL_COMPRESSED_SRGB8_ETC2 0x9275
110 # define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276
111 # define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277
112 # define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
113 # define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279
114 #endif
115 
116 #if (OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS)
117 #define OGRE_IF_IOS_VERSION_IS_GREATER_THAN(vers) \
118  if(static_cast<EAGL2Support*>(dynamic_cast<GLES2RenderSystem*>(Root::getSingleton().getRenderSystem())->getGLSupportRef())->getCurrentOSVersion() >= vers)
119 #else
120 #define OGRE_IF_IOS_VERSION_IS_GREATER_THAN(vers)
121 #endif
122 
123 #define getGLES2SupportRef() dynamic_cast<GLES2RenderSystem*>(Root::getSingleton().getRenderSystem())->getGLSupportRef()
124 
125 // Copy this definition from desktop GL. Used for polygon modes.
126 #ifndef GL_FILL
127 # define GL_FILL 0x1B02
128 #endif
129 
130 namespace Ogre {
131  class GLES2GpuProgram;
135 };
136 
137 // Apple doesn't define this in their extension. We'll do it just for convenience.
138 // Using the value from desktop GL
139 #ifndef GL_SAMPLER_2D_SHADOW_EXT
140 # define GL_SAMPLER_2D_SHADOW_EXT 0x8B62
141 #endif
142 
143 #ifndef GL_EXT_texture_filter_anisotropic
144 # define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
145 # define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
146 #endif
147 
148 // Defines for extensions that were made core in OpenGL ES 3
149 #if OGRE_NO_GLES3_SUPPORT == 0
150 #ifndef GL_OES_mapbuffer
151 #define GL_WRITE_ONLY_OES GL_MAP_WRITE_BIT
152 #define glUnmapBufferOES glUnmapBuffer
153 #endif
154 
155 #ifndef GL_OES_texture_half_float
156 #define GL_HALF_FLOAT_OES GL_HALF_FLOAT
157 #endif
158 
159 #ifndef GL_OES_rgb8_rgba8
160 #define GL_RGB8_OES GL_RGB8
161 #define GL_RGBA8_OES GL_RGBA8
162 #endif
163 
164 #ifndef GL_EXT_texture_rg
165 #define GL_RG8_EXT GL_RG8
166 #define GL_RED_EXT GL_RED
167 #define GL_RG_EXT GL_RG
168 #define GL_R8_EXT GL_R8
169 #endif
170 
171 #ifndef GL_EXT_texture_storage
172 #define GL_R16F_EXT GL_R16F
173 #define GL_R32F_EXT GL_R32F
174 #define GL_RG16F_EXT GL_RG16F
175 #define GL_RG32F_EXT GL_RG32F
176 #define GL_RGB16F_EXT GL_RGB16F
177 #define GL_RGB32F_EXT GL_RGB32F
178 #define GL_RGBA16F_EXT GL_RGBA16F
179 #define GL_RGBA32F_EXT GL_RGBA32F
180 #define GL_DEPTH_COMPONENT32_OES GL_DEPTH_COMPONENT32F
181 #endif
182 
183 #ifndef GL_EXT_blend_minmax
184 #define GL_MIN_EXT GL_MIN
185 #define GL_MAX_EXT GL_MAX
186 #endif
187 
188 #ifndef GL_OES_depth24
189 #define GL_DEPTH_COMPONENT24_OES GL_DEPTH_COMPONENT24
190 #endif
191 
192 #ifndef GL_OES_packed_depth_stencil
193 #define GL_DEPTH24_STENCIL8_OES GL_DEPTH24_STENCIL8
194 #endif
195 
196 #ifndef GL_APPLE_texture_max_level
197 #define GL_TEXTURE_MAX_LEVEL_APPLE GL_TEXTURE_MAX_LEVEL
198 #endif
199 
200 #ifndef GL_APPLE_framebuffer_multisample
201 #define GL_MAX_SAMPLES_APPLE GL_MAX_SAMPLES
202 #define glRenderbufferStorageMultisampleAPPLE glRenderbufferStorageMultisample
203 #endif
204 
205 #ifndef GL_EXT_occlusion_query_boolean
206 #define GL_ANY_SAMPLES_PASSED_EXT GL_ANY_SAMPLES_PASSED
207 #define GL_QUERY_RESULT_EXT GL_QUERY_RESULT
208 #define GL_QUERY_RESULT_AVAILABLE_EXT GL_QUERY_RESULT_AVAILABLE
209 #define glGenQueriesEXT glGenQueries
210 #define glDeleteQueriesEXT glDeleteQueries
211 #define glBeginQueryEXT glBeginQuery
212 #define glEndQueryEXT glEndQuery
213 #define glGetQueryObjectuivEXT glGetQueryObjectuiv
214 #endif
215 
216 #ifndef GL_EXT_map_buffer_range
217 #define GL_MAP_WRITE_BIT_EXT GL_MAP_WRITE_BIT
218 #define GL_MAP_FLUSH_EXPLICIT_BIT_EXT GL_MAP_FLUSH_EXPLICIT_BIT
219 #define GL_MAP_INVALIDATE_RANGE_BIT_EXT GL_MAP_INVALIDATE_RANGE_BIT
220 #define GL_MAP_UNSYNCHRONIZED_BIT_EXT GL_MAP_UNSYNCHRONIZED_BIT
221 #define GL_MAP_READ_BIT_EXT GL_MAP_READ_BIT
222 #define glMapBufferRangeEXT glMapBufferRange
223 #define glFlushMappedBufferRangeEXT glFlushMappedBufferRange
224 #endif
225 
226 #ifndef GL_APPLE_sync
227 #define GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE GL_SYNC_GPU_COMMANDS_COMPLETE
228 #define GL_SYNC_FLUSH_COMMANDS_BIT_APPLE GL_SYNC_FLUSH_COMMANDS_BIT
229 #define GL_TIMEOUT_IGNORED_APPLE GL_TIMEOUT_IGNORED
230 #define GL_WAIT_FAILED_APPLE GL_WAIT_FAILED
231 #define glFenceSyncAPPLE glFenceSync
232 #define glClientWaitSyncAPPLE glClientWaitSync
233 #define glDeleteSyncAPPLE glDeleteSync
234 #endif
235 
236 #define GL_PROGRAM_BINARY_LENGTH_OES GL_PROGRAM_BINARY_LENGTH
237 #define glProgramBinaryOES glProgramBinary
238 #define glGetProgramBinaryOES glGetProgramBinary
239 
240 #define glDrawElementsInstancedEXT glDrawElementsInstanced
241 #define glDrawArraysInstancedEXT glDrawArraysInstanced
242 #define glVertexAttribDivisorEXT glVertexAttribDivisor
243 #define glBindVertexArrayOES glBindVertexArray
244 #define glGenVertexArraysOES glGenVertexArrays
245 #define glDeleteVertexArraysOES glDeleteVertexArrays
246 #endif
247 
248 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32)
249 // an error in all windows gles sdks...
250 # undef GL_OES_get_program_binary
251 #endif
252 
253 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(__MINGW32__) && !defined(OGRE_STATIC_LIB)
254 # ifdef OGRE_GLES2PLUGIN_EXPORTS
255 # define _OgreGLES2Export __declspec(dllexport)
256 # else
257 # if defined( __MINGW32__ )
258 # define _OgreGLES2Export
259 # else
260 # define _OgreGLES2Export __declspec(dllimport)
261 # endif
262 # endif
263 #elif defined ( OGRE_GCC_VISIBILITY )
264 # define _OgreGLES2Export __attribute__ ((visibility("default")))
265 #else
266 # define _OgreGLES2Export
267 #endif
268 
269 #define DEBUG_(text) \
270  {\
271  fprintf(stderr, "%s:%d: %s\n", __FUNCTION__, __LINE__, text); \
272  }
273 
274 #define ENABLE_GL_CHECK 0
275 
276 #if ENABLE_GL_CHECK
277 #define OGRE_CHECK_GL_ERROR(glFunc) \
278 { \
279  glFunc; \
280  int e = glGetError(); \
281  if (e != 0) \
282  { \
283  const char * errorString = ""; \
284  switch(e) \
285  { \
286  case GL_INVALID_ENUM: errorString = "GL_INVALID_ENUM"; break; \
287  case GL_INVALID_VALUE: errorString = "GL_INVALID_VALUE"; break; \
288  case GL_INVALID_OPERATION: errorString = "GL_INVALID_OPERATION"; break; \
289  case GL_OUT_OF_MEMORY: errorString = "GL_OUT_OF_MEMORY"; break; \
290  default: break; \
291  } \
292  char msgBuf[4096]; \
293  StringVector tokens = StringUtil::split(#glFunc, "("); \
294  sprintf(msgBuf, "OpenGL error 0x%04X %s in %s at line %i for %s\n", e, errorString, __PRETTY_FUNCTION__, __LINE__, tokens[0].c_str()); \
295  LogManager::getSingleton().logMessage(msgBuf); \
296  } \
297  }
298 #else
299 # define OGRE_CHECK_GL_ERROR(glFunc) { glFunc; }
300 #endif
301 
302 #if ENABLE_GL_CHECK
303  #define EGL_CHECK_ERROR \
304  { \
305  int e = eglGetError(); \
306  if ((e != 0) && (e != EGL_SUCCESS))\
307  { \
308  char msgBuf[4096]; \
309  sprintf(msgBuf, "EGL error 0x%04X in %s at line %i\n", e, __PRETTY_FUNCTION__, __LINE__); \
310  LogManager::getSingleton().logMessage(msgBuf); \
311  OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msgBuf, __PRETTY_FUNCTION__); \
312  } \
313  }
314 #else
315  #define EGL_CHECK_ERROR {}
316 #endif
317 
318 #endif
SharedPtr< GLES2GpuProgram > GLES2GpuProgramPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
SharedPtr< GLES2Texture > GLES2TexturePtr