OGLplus  (0.59.0) a C++ wrapper for rendering APIs

fb_configs.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_INTEROP_GLX_FB_CONFIGS_HPP
10 #define EAGINE_INTEROP_GLX_FB_CONFIGS_HPP
11 
12 #include "../x11/display.hpp"
13 #include "../x11/visual_info.hpp"
14 #include "fb_config.hpp"
15 #include <eagine/assert.hpp>
16 
17 #include <GL/glx.h>
18 #include <stdexcept>
19 #include <utility>
20 
21 namespace eagine::glx {
22 
23 class fb_configs {
24 private:
25  int _count{0};
26  GLXFBConfig* _handle{nullptr};
27 
28 public:
29  fb_configs(const x11::display& dpy, const int* visual_attribs)
30  : _handle(::glXChooseFBConfig(
31  dpy,
32  DefaultScreen(dpy.get()),
33  visual_attribs,
34  &_count)) {
35  if(!_handle || (_count <= 0)) {
36  throw std::runtime_error(
37  "Failed to get matching framebuffer configs");
38  }
39  }
40 
41  fb_configs(fb_configs&& temp) noexcept
42  : _count(std::exchange(temp._count, 0))
43  , _handle(std::exchange(temp._handle, nullptr)) {}
44 
45  fb_configs(const fb_configs&) = delete;
46  auto operator=(fb_configs&&) = delete;
47  auto operator=(const fb_configs&) = delete;
48 
49  ~fb_configs() {
50  if(_handle) {
51  ::XFree(_handle);
52  }
53  }
54 
55  auto find_best(const x11::display& dpy) const -> fb_config {
56  int best = -1, best_num = -1;
57  EAGINE_ASSERT(_count > 0);
58  for(int i = 0; i != _count; ++i) {
59  int sample_buf, samples;
60 
61  ::glXGetFBConfigAttrib(
62  dpy, _handle[i], GLX_SAMPLE_BUFFERS, &sample_buf);
63  ::glXGetFBConfigAttrib(dpy, _handle[i], GLX_SAMPLES, &samples);
64  if((best < 0) || (sample_buf && (samples > best_num))) {
65  best = i;
66  best_num = samples;
67  }
68  }
69  EAGINE_ASSERT(best >= 0);
70  EAGINE_ASSERT(best < _count);
71  return fb_config(_handle[best]);
72  }
73 };
74 
75 } // namespace eagine::glx
76 
77 #endif
GLX wrapper code is placed in this namespace.
Definition: x11.hpp:14

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).