9 #ifndef EAGINE_INTEROP_GLX_CONTEXT_HPP
10 #define EAGINE_INTEROP_GLX_CONTEXT_HPP
12 #include "../x11/display.hpp"
13 #include "../x11/window.hpp"
24 :
public x11::display_object<::GLXContext, void(::Display*, ::GLXContext)> {
26 static auto make_context(
27 const x11::display& dpy,
33 ::GLXContext share_context = ::GLXContext(
nullptr)) -> ::GLXContext {
34 using glXCreateContextAttribsARBProc = GLXContext (*)(
35 ::Display*, ::GLXFBConfig, ::GLXContext, Bool,
const int*);
37 glXCreateContextAttribsARBProc glXCreateContextAttribsARB =
nullptr;
38 glXCreateContextAttribsARB =
39 reinterpret_cast<glXCreateContextAttribsARBProc
>(glXGetProcAddressARB(
40 reinterpret_cast<const GLubyte*
>(
"glXCreateContextAttribsARB")));
42 const int CONTEXT_MAJOR_VERSION_ARB = 0x2091;
43 const int CONTEXT_MINOR_VERSION_ARB = 0x2092;
44 const int CONTEXT_FLAGS_ARB = 0x2094;
45 const int CONTEXT_PROFILE_MASK_ARB = 0x9126;
46 const int CONTEXT_DEBUG_BIT_ARB = 0x0001;
47 const int CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
48 const int CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002;
53 int context_attribs[] = {
54 CONTEXT_MAJOR_VERSION_ARB,
56 CONTEXT_MINOR_VERSION_ARB,
59 (debugging ? CONTEXT_DEBUG_BIT_ARB : 0),
60 CONTEXT_PROFILE_MASK_ARB,
61 (compatibility ? CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
62 : CONTEXT_CORE_PROFILE_BIT_ARB),
64 res = glXCreateContextAttribsARB(
69 static_cast<const int*
>(context_attribs));
71 int context_attribs[] = {
72 CONTEXT_MAJOR_VERSION_ARB,
74 CONTEXT_MINOR_VERSION_ARB,
77 (debugging ? CONTEXT_DEBUG_BIT_ARB : 0),
79 res = glXCreateContextAttribsARB(
84 static_cast<const int*
>(context_attribs));
92 const x11::display& dpy,
96 bool debugging =
true,
97 bool compatibility =
false)
98 : x11::display_object<::GLXContext, void(::Display*, ::GLXContext)>(
108 "Error creating glX context") {}
111 const x11::display& dpy,
112 const fb_config& fbc,
113 const context& share_context,
116 bool debugging =
true,
117 bool compatibility =
false)
118 : x11::display_object<::GLXContext, void(::Display*, ::GLXContext)>(
127 share_context.handle()),
129 "Error creating sharing glX context") {}
131 void make_current(
const drawable& surface)
const {
132 ::glXMakeCurrent(this->display_ref(), surface, this->handle());
135 static void release(
const x11::display& dpy) {
136 ::glXMakeCurrent(dpy, 0,
nullptr);
139 void swap_buffers(
const drawable& surface)
const {
140 ::glXSwapBuffers(this->display_ref(), surface);