]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CEGLManager.h
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / CEGLManager.h
1 // Copyright (C) 2013 Patryk Nadrowski\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in Irrlicht.h\r
4 \r
5 #ifndef __C_EGL_MANAGER_H_INCLUDED__\r
6 #define __C_EGL_MANAGER_H_INCLUDED__\r
7 \r
8 \r
9 #ifdef _IRR_COMPILE_WITH_EGL_MANAGER_\r
10 \r
11 #include <EGL/egl.h>\r
12 \r
13 #include "SIrrCreationParameters.h"\r
14 #include "SExposedVideoData.h"\r
15 #include "IContextManager.h"\r
16 \r
17 namespace irr\r
18 {\r
19 namespace video\r
20 {\r
21         // EGL manager.\r
22         class CEGLManager : public IContextManager\r
23         {\r
24         public:\r
25                 //! Constructor.\r
26                 CEGLManager();\r
27 \r
28                 //! Destructor.\r
29                 virtual ~CEGLManager();\r
30 \r
31                 // Initialize EGL.\r
32                 /* This method initialize EGLand create EGL display, anyway surface and context\r
33                 aren't create. */\r
34                 bool initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& data) override;\r
35 \r
36                 // Terminate EGL.\r
37                 /* Terminate EGL context. This method break both existed surface and context. */\r
38                 void terminate() override;\r
39 \r
40                 // Create EGL surface.\r
41                 /* This method create EGL surface. On some platforms eg. Android, we must\r
42                 recreate surface on each resume, because WindowID may change, so existed\r
43                 surface may not be valid. If EGL context already exist, this method\r
44                 automatically activates it. */\r
45                 bool generateSurface() override;\r
46 \r
47                 // Destroy EGL surface.\r
48                 /* This method destroy EGL. On some platforms eg. Android, we should call\r
49                 this method on each pause, because after resume this surface may not be valid.\r
50                 Hovewer this method doesn'r break EGL context. */\r
51                 void destroySurface() override;\r
52 \r
53                 // Create EGL context.\r
54                 /* This method create and activate EGL context. */\r
55                 bool generateContext() override;\r
56 \r
57                 // Destroy EGL context.\r
58                 /* This method destroy EGL context. */\r
59                 void destroyContext() override;\r
60 \r
61                 const SExposedVideoData& getContext() const override;\r
62 \r
63                 bool activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero) override;\r
64 \r
65                 // Get procedure address.\r
66                 void* getProcAddress(const std::string &procName) override;\r
67 \r
68                 // Swap buffers.\r
69                 bool swapBuffers() override;\r
70 \r
71         protected:\r
72                 enum EConfigStyle\r
73                 {\r
74                         //! Get first result of eglChooseConfigs and if that fails try again by requesting simpler attributes\r
75                         ECS_EGL_CHOOSE_FIRST_LOWER_EXPECTATIONS,\r
76 \r
77                         //! We select our own best fit and avoid using eglChooseConfigs\r
78                         ECS_IRR_CHOOSE,\r
79                 };\r
80 \r
81                 EGLConfig chooseConfig(EConfigStyle confStyle);\r
82 \r
83                 //! Check how close this config is to the parameters we requested\r
84                 //! returns 0 is perfect, larger values are worse and < 0 is unusable.\r
85                 irr::s32 rateConfig(EGLConfig config, EGLint eglOpenGLBIT, bool log=false);\r
86 \r
87                 // Helper to sort EGLConfig's. (because we got no std::pair....)\r
88                 struct SConfigRating\r
89                 {\r
90                         EGLConfig config;\r
91                         irr::s32 rating;\r
92                         bool operator<(const SConfigRating& other) const\r
93                         {\r
94                                 return rating < other.rating;\r
95                         }\r
96                 };\r
97 \r
98         private:\r
99                 bool testEGLError();\r
100 \r
101                 NativeWindowType EglWindow;\r
102                 EGLDisplay EglDisplay;\r
103                 EGLSurface EglSurface;\r
104                 EGLContext EglContext;\r
105 \r
106                 EGLConfig EglConfig;\r
107 \r
108                 SIrrlichtCreationParameters Params;\r
109                 SExposedVideoData Data;\r
110 \r
111                 EGLint MajorVersion;\r
112                 EGLint MinorVersion;\r
113         };\r
114 }\r
115 }\r
116 #endif\r
117 #endif\r