Ocean
EGLContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_GLES_EGL_CONTEXT_H
9 #define META_OCEAN_PLATFORM_GLES_EGL_CONTEXT_H
10 
12 
13 #ifndef __APPLE__
14  #include <EGL/egl.h>
15  #include <EGL/eglext.h>
16 #endif // __APPLE__
17 
18 namespace Ocean
19 {
20 
21 namespace Platform
22 {
23 
24 namespace GLES
25 {
26 
27 /**
28  * This class encapsulates an EGL context.
29  * @ingroup platformgles
30  */
31 class OCEAN_PLATFORM_GLES_EXPORT EGLContext
32 {
33  public:
34 
35 #ifndef __APPLE__
36 
37  /**
38  * Definition of a configuration attribute pair combining attribute (first) and value (second).
39  */
40  typedef std::pair<EGLint, EGLint> ConfigAttributePair;
41 
42  /**
43  * Definition of a vector holding configuration pairs.
44  */
45  typedef std::vector<ConfigAttributePair> ConfigAttributePairs;
46 
47  public:
48 
49  /**
50  * Creates a new uninitialized context object.
51  * @see initialize().
52  */
54 
55  /**
56  * Move constructor.
57  * @param context The context to be moved
58  */
59  EGLContext(EGLContext&& context);
60 
61  /**
62  * Disabled copy consturctor.
63  * @param context The context which whould be copied
64  */
65  EGLContext(const EGLContext& context) = delete;
66 
67  /**
68  * Destructs the context object and releases all remaining EGL resources.
69  * @see release().
70  */
72 
73  /**
74  * Returns the major version of this egl context.
75  * @return The context's major version
76  */
77  inline EGLint majorVersion() const;
78 
79  /**
80  * Returns the minor version of this egl context.
81  * @return The context's minor version
82  */
83  inline EGLint minorVersion() const;
84 
85  /**
86  * Returns the display id of this egl context.
87  * @return The context's display id
88  */
89  inline const EGLDisplay& display() const;
90 
91  /**
92  * Returns the configuration of the egl context.
93  * @return The context's configuration
94  */
95  inline const EGLConfig& config() const;
96 
97  /**
98  * Returns the context id of this egl context.
99  * @return The context's context id
100  */
101  inline const ::EGLContext& context() const;
102 
103  /**
104  * Initializes this context object.
105  * @param configAttributePairs The configuration attributes the resulting context must support.
106  * @param shareContext Optional share context
107  * @see release().
108  */
109  bool initialize(const ConfigAttributePairs& configAttributePairs = ConfigAttributePairs(), EGLContext* shareContext = nullptr);
110 
111  /**
112  * Releases this context.
113  * @see initialize().
114  */
115  void release();
116 
117  /**
118  * Returns whether this context is valid (whether the context is initialized) and whether it can be used.
119  * @return True, if so
120  */
121  bool isValid() const;
122 
123  /**
124  * Returns whether this context is valid (whether the context is initialized) and whether it can be used.
125  * @return True, if so
126  */
127  explicit inline operator bool() const;
128 
129  /**
130  * Move operator.
131  * @param context The context to be moved
132  */
134 
135  /**
136  * Disabled copy operator.
137  * @param context The context which would be copied
138  */
139  EGLContext& operator=(const EGLContext& context) = delete;
140 
141  /**
142  * Translates an EGL error to a string.
143  * @param errorValue The error value to translate
144  * @return The translated error value
145  */
146  static const char* translateError(const EGLint errorValue);
147 
148  protected:
149 
150  /// The major EGL version.
152 
153  /// The minor EGL version.
155 
156  /// The EGL display.
157  EGLDisplay display_;
158 
159  /// The EGL config.
160  EGLConfig config_;
161 
162  /// The EGL context.
164 
165  /// The dummy surface.
166  EGLSurface dummySurface_;
167 
168 #endif // __APPLE__
169 
170 };
171 
172 #ifndef __APPLE__
173 
174 inline EGLint EGLContext::majorVersion() const
175 {
176  return majorVersion_;
177 }
178 
179 inline EGLint EGLContext::minorVersion() const
180 {
181  return minorVersion_;
182 }
183 
184 inline const EGLDisplay& EGLContext::display() const
185 {
186  return display_;
187 }
188 
189 inline const EGLConfig& EGLContext::config() const
190 {
191  return config_;
192 }
193 
194 inline const ::EGLContext& EGLContext::context() const
195 {
196  return context_;
197 }
198 
199 inline EGLContext::operator bool() const
200 {
201 return isValid();
202 }
203 
204 #endif // __APPLE__
205 
206 }
207 
208 }
209 
210 }
211 
212 #endif // META_OCEAN_PLATFORM_GLES_EGL_CONTEXT_H
This class encapsulates an EGL context.
Definition: EGLContext.h:32
~EGLContext()
Destructs the context object and releases all remaining EGL resources.
::EGLContext context_
The EGL context.
Definition: EGLContext.h:163
EGLConfig config_
The EGL config.
Definition: EGLContext.h:160
EGLContext(const EGLContext &context)=delete
Disabled copy consturctor.
const EGLDisplay & display() const
Returns the display id of this egl context.
Definition: EGLContext.h:184
EGLContext & operator=(const EGLContext &context)=delete
Disabled copy operator.
void release()
Releases this context.
EGLint majorVersion_
The major EGL version.
Definition: EGLContext.h:151
EGLint minorVersion_
The minor EGL version.
Definition: EGLContext.h:154
EGLContext()
Creates a new uninitialized context object.
const ::EGLContext & context() const
Returns the context id of this egl context.
Definition: EGLContext.h:194
EGLint majorVersion() const
Returns the major version of this egl context.
Definition: EGLContext.h:174
bool initialize(const ConfigAttributePairs &configAttributePairs=ConfigAttributePairs(), EGLContext *shareContext=nullptr)
Initializes this context object.
const EGLConfig & config() const
Returns the configuration of the egl context.
Definition: EGLContext.h:189
static const char * translateError(const EGLint errorValue)
Translates an EGL error to a string.
bool isValid() const
Returns whether this context is valid (whether the context is initialized) and whether it can be used...
EGLDisplay display_
The EGL display.
Definition: EGLContext.h:157
std::vector< ConfigAttributePair > ConfigAttributePairs
Definition of a vector holding configuration pairs.
Definition: EGLContext.h:45
EGLint minorVersion() const
Returns the minor version of this egl context.
Definition: EGLContext.h:179
EGLSurface dummySurface_
The dummy surface.
Definition: EGLContext.h:166
EGLContext(EGLContext &&context)
Move constructor.
std::pair< EGLint, EGLint > ConfigAttributePair
Definition of a configuration attribute pair combining attribute (first) and value (second).
Definition: EGLContext.h:40
EGLContext & operator=(EGLContext &&context)
Move operator.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15