EGLplus (0.52.0) a C++ wrapper for EGL

context.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef EGLPLUS_CONTEXT_1305291005_HPP
14 #define EGLPLUS_CONTEXT_1305291005_HPP
15 
16 #include <eglplus/eglfunc.hpp>
17 #include <eglplus/error/basic.hpp>
18 #include <eglplus/display.hpp>
19 #include <eglplus/configs.hpp>
20 #include <eglplus/surface.hpp>
21 #include <eglplus/attrib_list.hpp>
23 #include <eglplus/context_flag.hpp>
25 #include <eglplus/opengl_rns.hpp>
26 
27 namespace eglplus {
28 
29 
30 struct ContextValueTypeToContextAttrib
31 {
32 #ifdef EGL_CONTEXT_FLAGS
33  static ContextFlag
34  ValueType(std::integral_constant<int, 0>);
35  ContextAttrib operator()(ContextFlag) const
36  {
37  return ContextAttrib::Flags;
38  }
39 #endif
40 
41 #ifdef EGL_CONTEXT_OPENGL_PROFILE_MASK
42  static OpenGLProfileBit
43  ValueType(std::integral_constant<int, 1>);
44  ContextAttrib operator()(OpenGLProfileBit) const
45  {
47  }
48 #endif
49 
50 #ifdef EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY
52  ValueType(std::integral_constant<int, 2>);
54  {
56  }
57 #endif
58 
59  static std::integral_constant<int, 2> MaxValueType(void);
60 };
61 
62 
64 typedef AttributeList<
66  ContextValueTypeToContextAttrib,
67  AttributeListTraits
69 
71 typedef FinishedAttributeList<
73  AttributeListTraits
75 
76 class Context;
77 ::EGLContext GetEGLHandle(const Context&);
78 
80 class Context
81 {
82 private:
83  Display _display;
84  ::EGLContext _handle;
85 
86  friend ::EGLContext GetEGLHandle(const Context&);
87 
88  Context(const Context&);
89 
90  Context(
91  Display display,
92  ::EGLContext handle
93  ): _display(display)
94  , _handle(handle)
95  { }
96 
97  static ::EGLContext _init(
98  const Display& display,
99  const Config& config,
100  ::EGLContext share_context,
101  const EGLint* attribs
102  )
103  {
104  ::EGLContext result = EGLPLUS_EGLFUNC(CreateContext)(
105  GetEGLHandle(display),
106  GetEGLHandle(config),
107  share_context,
108  attribs
109  );
110  EGLPLUS_VERIFY_SIMPLE(CreateContext);
111  return result;
112  }
113 public:
116  : _display(tmp._display)
117  , _handle(tmp._handle)
118  {
119  tmp._handle = EGL_NO_CONTEXT;
120  }
121 
123 
128  const Display& display,
129  const Config& config
130  ): _display(display)
131  , _handle(_init(display, config, EGL_NO_CONTEXT, nullptr))
132  { }
133 
135 
140  const Display& display,
141  const Config& config,
142  const Context& shared_context
143  ): _display(display)
144  , _handle(_init(display, config, shared_context._handle, nullptr))
145  { }
146 
148 
153  const Display& display,
154  const Config& config,
155  const FinishedContextAttribs& attribs
156  ): _display(display)
157  , _handle(_init(display, config, EGL_NO_CONTEXT, attribs.Get()))
158  { }
159 
161 
166  const Display& display,
167  const Config& config,
168  const Context& shared_context,
169  const FinishedContextAttribs& attribs
170  ): _display(display)
171  , _handle(_init(display, config, shared_context._handle, attribs.Get()))
172  { }
173 
175 
179  ~Context(void)
180  {
181  if(_handle != EGL_NO_CONTEXT)
182  {
183  EGLPLUS_EGLFUNC(DestroyContext)(
184  GetEGLHandle(_display),
185  _handle
186  );
187  EGLPLUS_VERIFY_SIMPLE(DestroyContext);
188  }
189  }
190 
192 
197  const Surface& draw_surface,
198  const Surface& read_surface
199  )
200  {
201  EGLBoolean result = EGLPLUS_EGLFUNC(MakeCurrent)(
202  GetEGLHandle(_display),
203  GetEGLHandle(draw_surface),
204  GetEGLHandle(read_surface),
205  _handle
206  );
207  EGLPLUS_CHECK_SIMPLE(MakeCurrent);
208  return result == EGL_TRUE;
209  }
210 
212 
216  bool MakeCurrent(const Surface& surface)
217  {
218  EGLBoolean result = EGLPLUS_EGLFUNC(MakeCurrent)(
219  GetEGLHandle(_display),
220  GetEGLHandle(surface),
221  GetEGLHandle(surface),
222  _handle
223  );
224  EGLPLUS_CHECK_SIMPLE(MakeCurrent);
225  return result == EGL_TRUE;
226  }
227 
229 
236  bool MakeCurrent(void)
237  {
238  EGLBoolean result = EGLPLUS_EGLFUNC(MakeCurrent)(
239  GetEGLHandle(_display),
240  EGL_NO_SURFACE,
241  EGL_NO_SURFACE,
242  _handle
243  );
244  EGLPLUS_CHECK_SIMPLE(MakeCurrent);
245  return result == EGL_TRUE;
246  }
247 
249 
253  bool Release(void)
254  {
255  EGLBoolean result = EGLPLUS_EGLFUNC(MakeCurrent)(
256  GetEGLHandle(_display),
257  EGL_NO_SURFACE,
258  EGL_NO_SURFACE,
259  EGL_NO_CONTEXT
260  );
261  EGLPLUS_CHECK_SIMPLE(MakeCurrent);
262  return result == EGL_TRUE;
263  }
264 
266 
270  bool Query(ContextAttrib attrib, EGLint& value) const
271  {
272  EGLBoolean result = EGLPLUS_EGLFUNC(QueryContext)(
273  GetEGLHandle(_display),
274  _handle,
275  EGLint(EGLenum(attrib)),
276  &value
277  );
278  EGLPLUS_CHECK_SIMPLE(QueryContext);
279  return result == EGL_TRUE;
280  }
281 
283 
287  EGLint ConfigId(void) const
288  {
289  EGLint result = 0;
290  EGLPLUS_EGLFUNC(QueryContext)(
291  GetEGLHandle(_display),
292  _handle,
293  EGLint(EGL_CONFIG_ID),
294  &result
295  );
296  EGLPLUS_CHECK_SIMPLE(QueryContext);
297  return result;
298  }
299 
301 
305  bool WaitClient(void) const
306  {
307  EGLBoolean result = EGLPLUS_EGLFUNC(WaitClient)();
308  EGLPLUS_VERIFY_SIMPLE(WaitClient);
309  return result == EGL_TRUE;
310  }
311 
313 
317  bool WaitGL(void) const
318  {
319  EGLBoolean result = EGLPLUS_EGLFUNC(WaitGL)();
320  EGLPLUS_VERIFY_SIMPLE(WaitGL);
321  return result == EGL_TRUE;
322  }
323 
325 
329  bool WaitNative(EGLint engine) const
330  {
331  EGLBoolean result = EGLPLUS_EGLFUNC(WaitNative)(engine);
332  EGLPLUS_VERIFY_SIMPLE(WaitNative);
333  return result == EGL_TRUE;
334  }
335 };
336 
337 inline ::EGLContext GetEGLHandle(const Context& context)
338 {
339  return context._handle;
340 }
341 
342 } // namespace eglplus
343 
344 #endif // include guard
~Context(void)
Destroys the wrapped context.
Definition: context.hpp:179
bool MakeCurrent(const Surface &surface)
Makes the context current.
Definition: context.hpp:216
bool Query(ContextAttrib attrib, EGLint &value) const
Queries a context attribute.
Definition: context.hpp:270
FinishedAttributeList< ContextAttrib, AttributeListTraits > FinishedContextAttribs
Finished list of context attribute values.
Definition: context.hpp:74
bool WaitGL(void) const
Wait for GL API commands to complete.
Definition: context.hpp:317
bool WaitNative(EGLint engine) const
Wait for native API commands to complete.
Definition: context.hpp:329
EGL OpenGL profile mask bits enumeration.
EGL configurations.
EGLint ConfigId(void) const
Returns the context framebuffer config id.
Definition: context.hpp:287
Context(Context &&tmp)
Contexts are move constructible.
Definition: context.hpp:115
Helper macro expanding into EGL function name.
Template for EGL surface and configuration attribute list.
EGL context attribute type enumeration.
CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY.
OpenGLProfileBit
EGL OpenGL profile mask bits enumeration.
Definition: opengl_profile_bit.hpp:25
Wrapper around EGLContext.
Definition: context.hpp:80
Declares and implements wrapper for EGLContext.
ContextFlag
EGL context flags enumeration.
Definition: context_flag.hpp:25
EGL OpenGL reset notification strategy enumeration.
Context(const Display &display, const Config &config, const Context &shared_context, const FinishedContextAttribs &attribs)
Construct a sharing context without any attributes.
Definition: context.hpp:165
Wrapper around EGLDisplay.
Definition: display.hpp:27
Context(const Display &display, const Config &config, const Context &shared_context)
Construct a sharing context without any attributes.
Definition: context.hpp:139
bool MakeCurrent(void)
Makes the context current without surfaces.
Definition: context.hpp:236
Declares and implements wrapper for EGLDisplay.
CONTEXT_OPENGL_PROFILE_MASK.
Context(const Display &display, const Config &config)
Construct a non-sharing context without any attributes.
Definition: context.hpp:127
ContextAttrib
bool MakeCurrent(const Surface &draw_surface, const Surface &read_surface)
Makes the context current.
Definition: context.hpp:196
bool Release(void)
Releases the current context without assigning a new one.
Definition: context.hpp:253
Context(const Display &display, const Config &config, const FinishedContextAttribs &attribs)
Construct a non-sharing context with attributes.
Definition: context.hpp:152
EGL context flags type enumeration.
AttributeList< ContextAttrib, ContextValueTypeToContextAttrib, AttributeListTraits > ContextAttribs
Attribute list for context attributes.
Definition: context.hpp:68
A wrapper for EGL configuration.
Definition: configs.hpp:34
Wrapper for EGLSurfaces.
Definition: surface.hpp:116
bool WaitClient(void) const
Wait for client API commands to complete.
Definition: context.hpp:305
ContextAttrib
EGL context attribute enumeration.
Definition: context_attrib.hpp:24

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).