OGRE  1.8
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-2013 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 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32)
37 # if !defined( __MINGW32__ )
38 # define __PRETTY_FUNCTION__ __FUNCTION__
39 # ifndef WIN32_LEAN_AND_MEAN
40 # define WIN32_LEAN_AND_MEAN 1
41 # endif
42 # ifndef NOMINMAX
43 # define NOMINMAX // required to stop windows.h messing up std::min
44 # endif
45 # endif
46 #endif
47 
48 #ifndef GL_GLEXT_PROTOTYPES
49 # define GL_GLEXT_PROTOTYPES
50 #endif
51 
52 #if (OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS)
53 # include <OpenGLES/ES2/gl.h>
54 # include <OpenGLES/ES2/glext.h>
55 # ifdef __OBJC__
56 # include <OpenGLES/EAGL.h>
57 # endif
58 #elif (OGRE_PLATFORM == OGRE_PLATFORM_ANDROID) || (OGRE_PLATFORM == OGRE_PLATFORM_NACL)
59 # ifndef GL_GLEXT_PROTOTYPES
60 # define GL_GLEXT_PROTOTYPES
61 # endif
62 # include <GLES2/gl2platform.h>
63 # include <GLES2/gl2.h>
64 # include <GLES2/gl2ext.h>
65 # if (OGRE_PLATFORM == OGRE_PLATFORM_NACL)
66 # include "ppapi/cpp/completion_callback.h"
67 # include "ppapi/cpp/instance.h"
68 # include "ppapi/c/ppp_graphics_3d.h"
69 # include "ppapi/cpp/graphics_3d.h"
70 # include "ppapi/cpp/graphics_3d_client.h"
71 # include "ppapi/gles2/gl2ext_ppapi.h"
72 # undef GL_OES_get_program_binary
73 # undef GL_OES_mapbuffer
74 # endif
75 #else
76 # include <GLES2/gl2.h>
77 # include <GLES2/gl2ext.h>
78 # include <EGL/egl.h>
79 
80 // Function pointers for FBO extension methods
81 // Declare them here since we don't have GLEW to do it for us
82 
83 # ifndef GL_GLEXT_PROTOTYPES
84 extern PFNGLMAPBUFFEROESPROC glMapBufferOES;
85 extern PFNGLUNMAPBUFFEROESPROC glUnmapBufferOES;
86 extern PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB;
87 extern PFNGLREADBUFFERNVPROC glReadBufferNV;
88 extern PFNGLGETCOMPRESSEDTEXIMAGENVPROC glGetCompressedTexImageNV;
89 extern PFNGLGETTEXIMAGENVPROC glGetTexImageNV;
90 extern PFNGLGETTEXLEVELPARAMETERFVNVPROC glGetTexLevelParameterfvNV;
91 extern PFNGLGETTEXLEVELPARAMETERiVNVPROC glGetTexLevelParameterivNV;
92 # endif
93 
94 // If we are going to use the PVRTC_CODEC make sure we
95 // setup the needed constants
96 #if (OGRE_NO_PVRTC_CODEC == 0)
97 # ifndef GL_IMG_texture_compression_pvrtc
98 # define GL_IMG_texture_compression_pvrtc 1
99 # define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
100 # define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
101 # define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
102 # define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
103 # endif
104 #endif
105 
106 #endif
107 
108 
109 // Define GL_NONE for convenience
110 #define GL_NONE 0
111 
112 #if !defined(GL_BGRA) && OGRE_PLATFORM != OGRE_PLATFORM_NACL
113 # define GL_BGRA 0x80E1
114 #endif
115 
116 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32)
117 // an error in all windows gles sdks...
118 # undef GL_OES_get_program_binary
119 #endif
120 
121 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(__MINGW32__) && !defined(OGRE_STATIC_LIB)
122 # ifdef OGRE_GLES2PLUGIN_EXPORTS
123 # define _OgreGLES2Export __declspec(dllexport)
124 # else
125 # if defined( __MINGW32__ )
126 # define _OgreGLES2Export
127 # else
128 # define _OgreGLES2Export __declspec(dllimport)
129 # endif
130 # endif
131 #elif defined ( OGRE_GCC_VISIBILITY )
132 # define _OgreGLES2Export __attribute__ ((visibility("default")))
133 #else
134 # define _OgreGLES2Export
135 #endif
136 
137 #define DEBUG_(text) \
138  {\
139  fprintf(stderr, "%s:%d: %s\n", __FUNCTION__, __LINE__, text); \
140  }
141 
142 #define ENABLE_GL_CHECK 0
143 
144 #if ENABLE_GL_CHECK
145 #define GL_CHECK_ERROR \
146  { \
147  int e = glGetError(); \
148  if (e != 0) \
149  { \
150  const char * errorString = ""; \
151  switch(e) \
152  { \
153  case GL_INVALID_ENUM: errorString = "GL_INVALID_ENUM"; break; \
154  case GL_INVALID_VALUE: errorString = "GL_INVALID_VALUE"; break; \
155  case GL_INVALID_OPERATION: errorString = "GL_INVALID_OPERATION"; break; \
156  case GL_OUT_OF_MEMORY: errorString = "GL_OUT_OF_MEMORY"; break; \
157  default: break; \
158  } \
159  char msgBuf[10000]; \
160  sprintf(msgBuf, "OpenGL ES2 error 0x%04X %s in %s at line %i\n", e, errorString, __PRETTY_FUNCTION__, __LINE__); \
161  LogManager::getSingleton().logMessage(msgBuf); \
162  } \
163  }
164 #else
165  #define GL_CHECK_ERROR {}
166 #endif
167 
168 #if ENABLE_GL_CHECK
169  #define EGL_CHECK_ERROR \
170  { \
171  int e = eglGetError(); \
172  if ((e != 0) && (e != EGL_SUCCESS))\
173  { \
174  char msgBuf[10000]; \
175  sprintf(msgBuf, "EGL error 0x%04X in %s at line %i\n", e, __PRETTY_FUNCTION__, __LINE__); \
176  LogManager::getSingleton().logMessage(msgBuf); \
177  OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msgBuf, __PRETTY_FUNCTION__); \
178  } \
179  }
180 #else
181  #define EGL_CHECK_ERROR {}
182 #endif
183 
184 #endif