EGLplus (0.52.0) a C++ wrapper for EGL

surface.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef EGLPLUS_SURFACE_1305291005_HPP
14 #define EGLPLUS_SURFACE_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/attrib_list.hpp>
22 
31 
32 namespace eglplus {
33 
34 struct SurfaceValueTypeToSurfaceAttrib
35 {
36  static RenderBuffer
37  ValueType(std::integral_constant<int, 0>);
38  SurfaceAttrib operator()(RenderBuffer) const
39  {
41  }
42 
43  static MultisampleResolve
44  ValueType(std::integral_constant<int, 1>);
45  SurfaceAttrib operator()(MultisampleResolve) const
46  {
48  }
49 
50  static SwapBehavior
51  ValueType(std::integral_constant<int, 2>);
52  SurfaceAttrib operator()(SwapBehavior) const
53  {
55  }
56 
57  static TextureTarget
58  ValueType(std::integral_constant<int, 3>);
59  SurfaceAttrib operator()(TextureTarget) const
60  {
62  }
63 
64  static TextureFormat
65  ValueType(std::integral_constant<int, 4>);
66  SurfaceAttrib operator()(TextureFormat) const
67  {
69  }
70 
71  static VGColorspace
72  ValueType(std::integral_constant<int, 5>);
73  SurfaceAttrib operator()(VGColorspace) const
74  {
76  }
77 
78  static VGAlphaFormat
79  ValueType(std::integral_constant<int, 6>);
80  SurfaceAttrib operator()(VGAlphaFormat) const
81  {
83  }
84 
85 #ifndef EGL_GL_COLORSPACE
86  static std::integral_constant<int, 6> MaxValueType(void);
87 #else
88  static GLColorspace
89  ValueType(std::integral_constant<int, 7>);
90  SurfaceAttrib operator()(GLColorspace) const
91  {
93  }
94 
95  static std::integral_constant<int, 7> MaxValueType(void);
96 #endif
97 };
98 
100 typedef AttributeList<
102  SurfaceValueTypeToSurfaceAttrib,
103  AttributeListTraits
105 
107 typedef FinishedAttributeList<
109  AttributeListTraits
111 
112 class Surface;
113 ::EGLSurface GetEGLHandle(const Surface&);
114 
116 class Surface
117 {
118 private:
119  Display _display;
120  ::EGLSurface _handle;
121 
122  friend ::EGLSurface GetEGLHandle(const Surface&);
123 
124  Surface(const Surface&);
125 
126  struct Pbuffer_ { };
127 
128  static ::EGLSurface _init(
129  Pbuffer_,
130  const Display& display,
131  const Config& config,
132  const FinishedSurfaceAttribs& attribs
133  )
134  {
135  ::EGLSurface result = EGLPLUS_EGLFUNC(CreatePbufferSurface)(
136  GetEGLHandle(display),
137  GetEGLHandle(config),
138  attribs.Get()
139  );
140  EGLPLUS_CHECK_SIMPLE(CreatePbufferSurface);
141  return result;
142  }
143 
144  Surface(
145  Pbuffer_ sel,
146  const Display& display,
147  const Config& config,
148  const FinishedSurfaceAttribs& attribs
149  ): _display(display)
150  , _handle(_init(sel, _display, config, attribs))
151  { }
152 
153  struct Pixmap_{ };
154 
155  static ::EGLSurface _init(
156  Pixmap_,
157  const Display& display,
158  const Config& config,
159  EGLNativePixmapType pixmap,
160  const FinishedSurfaceAttribs& attribs
161  )
162  {
163  ::EGLSurface result = EGLPLUS_EGLFUNC(CreatePixmapSurface)(
164  GetEGLHandle(display),
165  GetEGLHandle(config),
166  pixmap,
167  attribs.Get()
168  );
169  EGLPLUS_CHECK_SIMPLE(CreatePixmapSurface);
170  return result;
171  }
172 
173  Surface(
174  Pixmap_ sel,
175  const Display& display,
176  const Config& config,
177  EGLNativePixmapType pixmap,
178  const FinishedSurfaceAttribs& attribs
179  ): _display(display)
180  , _handle(_init(sel, _display, config, pixmap, attribs))
181  { }
182 
183  struct Window_ { };
184 
185  static ::EGLSurface _init(
186  Window_,
187  const Display& display,
188  const Config& config,
189  EGLNativeWindowType window,
190  const FinishedSurfaceAttribs& attribs
191  )
192  {
193  ::EGLSurface result = EGLPLUS_EGLFUNC(CreateWindowSurface)(
194  GetEGLHandle(display),
195  GetEGLHandle(config),
196  window,
197  attribs.Get()
198  );
199  EGLPLUS_CHECK_SIMPLE(CreateWindowSurface);
200  return result;
201  }
202 
203  Surface(
204  Window_ sel,
205  const Display& display,
206  const Config& config,
207  EGLNativeWindowType window,
208  const FinishedSurfaceAttribs& attribs
209  ): _display(display)
210  , _handle(_init(sel, _display, config, window, attribs))
211  { }
212 public:
215  : _display(tmp._display)
216  , _handle(tmp._handle)
217  {
218  tmp._handle = EGL_NO_SURFACE;
219  }
220 
222 
226  ~Surface(void)
227  {
228  if(_handle != EGL_NO_SURFACE)
229  {
230  EGLPLUS_EGLFUNC(DestroySurface)(
231  GetEGLHandle(_display),
232  _handle
233  );
234  EGLPLUS_VERIFY_SIMPLE(DestroySurface);
235  }
236  }
237 
239 
243  static Surface Pbuffer(
244  const Display& display,
245  const Config& config,
246  const FinishedSurfaceAttribs& attribs
247  )
248  {
249  return Surface(
250  Pbuffer_(),
251  display,
252  config,
253  attribs
254  );
255  }
256 
258 
262  static Surface Pixmap(
263  const Display& display,
264  const Config& config,
265  EGLNativePixmapType pixmap,
266  const FinishedSurfaceAttribs& attribs
267  )
268  {
269  return Surface(
270  Pixmap_(),
271  display,
272  config,
273  pixmap,
274  attribs
275  );
276  }
277 
279 
283  static Surface Window(
284  const Display& display,
285  const Config& config,
286  EGLNativeWindowType window,
287  const FinishedSurfaceAttribs& attribs
288  )
289  {
290  return Surface(
291  Window_(),
292  display,
293  config,
294  window,
295  attribs
296  );
297  }
298 
300 
304  bool SwapBuffers(void)
305  {
306  bool result = EGLPLUS_EGLFUNC(SwapBuffers)(
307  GetEGLHandle(_display),
308  _handle
309  );
310  EGLPLUS_VERIFY_SIMPLE(SwapBuffers);
311  return result;
312  }
313 
315 
319  bool CopyBuffers(EGLNativePixmapType target)
320  {
321  bool result = EGLPLUS_EGLFUNC(CopyBuffers)(
322  GetEGLHandle(_display),
323  _handle,
324  target
325  );
326  EGLPLUS_VERIFY_SIMPLE(CopyBuffers);
327  return result;
328  }
329 
331 
335  bool Attrib(SurfaceAttrib attrib, EGLint value)
336  {
337  bool result = EGLPLUS_EGLFUNC(SurfaceAttrib)(
338  GetEGLHandle(_display),
339  _handle,
340  EGLint(EGLenum(attrib)),
341  value
342  );
343  EGLPLUS_VERIFY_SIMPLE(SurfaceAttrib);
344  return result;
345  }
346 
348 
352  bool QueryAttrib(SurfaceAttrib attrib, EGLint& value) const
353  {
354  bool result = EGLPLUS_EGLFUNC(QuerySurface)(
355  GetEGLHandle(_display),
356  _handle,
357  EGLint(EGLenum(attrib)),
358  &value
359  );
360  EGLPLUS_VERIFY_SIMPLE(QuerySurface);
361  return result;
362  }
363 
365 
369  EGLint GetAttrib(SurfaceAttrib attrib) const
370  {
371  EGLint result = EGL_UNKNOWN;
372  QueryAttrib(attrib, result);
373  return result;
374  }
375 
377 
382  EGLint Width(void) const
383  {
385  }
386 
388 
393  EGLint Height(void) const
394  {
396  }
397 
399 
405  {
406  return eglplus::RenderBuffer(
408  );
409  }
410 
412 
418  {
419  Attrib(
421  EGLint(render_buffer)
422  );
423  }
424 
426 
432  {
435  );
436  }
437 
439 
445  {
446  Attrib(
448  EGLint(value)
449  );
450  }
451 
453 
459  {
460  return eglplus::SwapBehavior(
462  );
463  }
464 
466 
472  {
473  Attrib(
475  EGLint(value)
476  );
477  }
478 
480 
486  {
487  return eglplus::TextureTarget(
489  );
490  }
491 
493 
499  {
500  return eglplus::TextureFormat(
502  );
503  }
504 
505 #if EGLPLUS_DOCUMENTATION_ONLY || defined(EGL_GL_COLORSPACE)
506 
513  {
514  return eglplus::GLColorspace(
516  );
517  }
518 #endif
519 
521 
527  {
528  return eglplus::VGColorspace(
530  );
531  }
532 
534 
540  {
541  return eglplus::VGAlphaFormat(
543  );
544  }
545 };
546 
547 inline ::EGLSurface GetEGLHandle(const Surface& surface)
548 {
549  return surface._handle;
550 }
551 
552 } // namespace eglplus
553 
554 #endif // include guard
void SwapBehavior(eglplus::SwapBehavior value)
Sets the buffer swap behavior setting of the surface.
Definition: surface.hpp:471
EGL render buffer enumeration.
AttributeList< SurfaceAttrib, SurfaceValueTypeToSurfaceAttrib, AttributeListTraits > SurfaceAttribs
Attribute list for surface attributes.
Definition: surface.hpp:104
eglplus::RenderBuffer RenderBuffer(void) const
Returns the render buffer setting of the surface.
Definition: surface.hpp:404
eglplus::TextureFormat TextureFormat(void) const
Returns the texture format setting of the surface.
Definition: surface.hpp:498
static Surface Pbuffer(const Display &display, const Config &config, const FinishedSurfaceAttribs &attribs)
Creates a Pbuffer surface.
Definition: surface.hpp:243
void RenderBuffer(eglplus::RenderBuffer render_buffer)
Sets the render buffer setting of the surface.
Definition: surface.hpp:417
EGL buffer swap behavior enumeration.
bool CopyBuffers(EGLNativePixmapType target)
Copy buffer to native pixmap.
Definition: surface.hpp:319
static Surface Pixmap(const Display &display, const Config &config, EGLNativePixmapType pixmap, const FinishedSurfaceAttribs &attribs)
Creates a Pixmap surface.
Definition: surface.hpp:262
EGL configurations.
bool SwapBuffers(void)
Swap buffers.
Definition: surface.hpp:304
VGColorspace
OpenVG colorspace enumeration.
Definition: vg_colorspace.hpp:24
bool QueryAttrib(SurfaceAttrib attrib, EGLint &value) const
Queries the specified surface attribute value.
Definition: surface.hpp:352
eglplus::SwapBehavior SwapBehavior(void) const
Returns the buffer swap behavior setting of the surface.
Definition: surface.hpp:458
Helper macro expanding into EGL function name.
Template for EGL surface and configuration attribute list.
EGLint Height(void) const
Returns the height of the surface.
Definition: surface.hpp:393
EGLint GetAttrib(SurfaceAttrib attrib) const
Gets the specified surface attribute value.
Definition: surface.hpp:369
EGL OpenVG colorspace enumeration.
EGL Multisample resolve enumeration.
SurfaceAttrib
EGL surface attribute enumeration.
Definition: surface_attrib.hpp:24
TextureTarget
EGL texture target enumeration.
Definition: texture_target.hpp:24
~Surface(void)
Destroys the wrapped surface.
Definition: surface.hpp:226
EGL OpenVG alpha format enumeration.
EGL surface attribute enumeration.
eglplus::MultisampleResolve MultisampleResolve(void) const
Returns the multisample resolve setting of the surface.
Definition: surface.hpp:431
Wrapper around EGLDisplay.
Definition: display.hpp:27
EGLint Width(void) const
Returns the Width of the surface.
Definition: surface.hpp:382
Declares and implements wrapper for EGLDisplay.
RenderBuffer
EGL render buffer enumeration.
Definition: render_buffer.hpp:24
TextureTarget
bool Attrib(SurfaceAttrib attrib, EGLint value)
Sets the value of the specified attribute.
Definition: surface.hpp:335
eglplus::GLColorspace GLColorspace(void) const
Returns the OpenGL colorspace setting of the surface.
Definition: surface.hpp:512
EGL texture format enumeration.
static Surface Window(const Display &display, const Config &config, EGLNativeWindowType window, const FinishedSurfaceAttribs &attribs)
Creates a Window surface.
Definition: surface.hpp:283
SwapBehavior
EGL buffer swap behavior enumeration.
Definition: swap_behavior.hpp:24
VGAlphaFormat
OpenVG alpha format enumeration.
Definition: vg_alpha_format.hpp:24
GLColorspace
OpenGL colorspace enumeration.
Definition: gl_colorspace.hpp:24
eglplus::TextureTarget TextureTarget(void) const
Returns the texture target setting of the surface.
Definition: surface.hpp:485
void MultisampleResolve(eglplus::MultisampleResolve value)
Sets the multisample resolve setting of the surface.
Definition: surface.hpp:444
Surface(Surface &&tmp)
Surfaces are move-constructible.
Definition: surface.hpp:214
FinishedAttributeList< SurfaceAttrib, AttributeListTraits > FinishedSurfaceAttribs
Finished list of surface attribute values.
Definition: surface.hpp:110
TextureFormat
EGL texture format enumeration.
Definition: texture_format.hpp:24
A wrapper for EGL configuration.
Definition: configs.hpp:34
Wrapper for EGLSurfaces.
Definition: surface.hpp:116
MultisampleResolve
Multisample resolve enumeration.
Definition: multisample_resolve.hpp:24
eglplus::VGAlphaFormat VGAlphaFormat(void) const
Returns the OpenVG alpha format of the surface.
Definition: surface.hpp:539
EGL texture target enumeration.
EGL OpenGL colorspace enumeration.
eglplus::VGColorspace VGColorspace(void) const
Returns the OpenVG colorspace setting of the surface.
Definition: surface.hpp:526

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).