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 #include "OgreGLES2Exports.h"
37 #include "OgreGLES2Config.h"
38 
39 namespace Ogre {
40     class GLContext;
41     typedef GLContext GLES2Context;
42 }
43 
44 #include <GLES3/glesw.h>
45 
46 #if (OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS)
47 #   ifdef __OBJC__
48 #       include <OpenGLES/EAGL.h>
49 #   endif
50 #else
51 #   if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32)
52 #       if !defined( __MINGW32__ )
53 #           define __PRETTY_FUNCTION__ __FUNCTION__
54 #           ifndef WIN32_LEAN_AND_MEAN
55 #               define WIN32_LEAN_AND_MEAN 1
56 #           endif
57 #           ifndef NOMINMAX
58 #               define NOMINMAX // required to stop windows.h messing up std::min
59 #           endif
60 #       endif
61 #   endif
62 #endif
63 
64 #if (OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS)
65 namespace Ogre {
66 extern float EAGLCurrentOSVersion;
67 }
68 #define OGRE_IF_IOS_VERSION_IS_GREATER_THAN(vers) \
69     if(EAGLCurrentOSVersion >= vers)
70 #else
71 #define OGRE_IF_IOS_VERSION_IS_GREATER_THAN(vers)
72 #endif
73 
74 #define getGLES2RenderSystem() dynamic_cast<GLES2RenderSystem*>(Root::getSingleton().getRenderSystem())
75 
76 // Copy this definition from desktop GL.  Used for polygon modes.
77 #ifndef GL_FILL
78 #   define GL_FILL    0x1B02
79 #endif
80 
81 namespace Ogre {
82     class GLNativeSupport;
83     class GLES2GpuProgram;
84     class GLES2Texture;
85     typedef shared_ptr<GLES2GpuProgram> GLES2GpuProgramPtr;
86     typedef shared_ptr<GLES2Texture> GLES2TexturePtr;
87 };
88 
89 #if OGRE_NO_GLES3_SUPPORT == 0
90 #undef GL_DEPTH_COMPONENT32_OES
91 #define GL_DEPTH_COMPONENT32_OES GL_DEPTH_COMPONENT32F
92 #endif
93 
94 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32)
95 // an error in all windows gles sdks...
96 #   undef GL_OES_get_program_binary
97 #endif
98 
99 #define ENABLE_GL_CHECK 0
100 
101 #if ENABLE_GL_CHECK
102 #define OGRE_CHECK_GL_ERROR(glFunc) \
103 { \
104         glFunc; \
105         int e = glGetError(); \
106         if (e != 0) \
107         { \
108             const char * errorString = ""; \
109             switch(e) \
110             { \
111             case GL_INVALID_ENUM:       errorString = "GL_INVALID_ENUM";        break; \
112             case GL_INVALID_VALUE:      errorString = "GL_INVALID_VALUE";       break; \
113             case GL_INVALID_OPERATION:  errorString = "GL_INVALID_OPERATION";   break; \
114             case GL_OUT_OF_MEMORY:      errorString = "GL_OUT_OF_MEMORY";       break; \
115             default:                                                            break; \
116             } \
117             char msgBuf[4096]; \
118             StringVector tokens = StringUtil::split(#glFunc, "("); \
119             sprintf(msgBuf, "OpenGL error 0x%04X %s in %s at line %i for %s\n", e, errorString, __PRETTY_FUNCTION__, __LINE__, tokens[0].c_str()); \
120             LogManager::getSingleton().logMessage(msgBuf); \
121         } \
122     }
123 #else
124 #   define OGRE_CHECK_GL_ERROR(glFunc) { glFunc; }
125 #endif
126 
127 #endif
128