5 #include "display_private.h"
6 #include "window_private.h"
13 typedef GLXContext ContextHandle;
15 struct GLContext::Private
17 ContextHandle context;
18 // We need to create a window with the chosen visual
23 void GLContext::platform_init(const GLOptions &opts)
27 attribs.push_back(GLX_RGBA);
28 attribs.push_back(GLX_DEPTH_SIZE);
33 attribs.push_back(GLX_ALPHA_SIZE);
39 attribs.push_back(GLX_STENCIL_SIZE);
44 attribs.push_back(GLX_DOUBLEBUFFER);
46 if(opts.multisample>0)
48 attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
50 attribs.push_back(GLX_SAMPLES_ARB);
51 attribs.push_back(opts.multisample);
56 DisplayHandle dpy = display.get_private().display;
58 XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), &attribs.front());
60 throw unsupported_gl_mode(opts);
63 priv->context = glXCreateContext(dpy, vi, 0, true);
65 XSetWindowAttributes attr;
66 attr.colormap = XCreateColormap(dpy, DefaultRootWindow(dpy), vi->visual, AllocNone);
68 priv->subwnd = XCreateWindow(dpy, window.get_private().window, 0, 0, window.get_width(), window.get_height(), 0, vi->depth, InputOutput, vi->visual, CWColormap, &attr);
69 XMapWindow(dpy, priv->subwnd);
73 glXMakeCurrent(dpy, priv->subwnd, priv->context);
76 GLContext::~GLContext()
78 DisplayHandle dpy = display.get_private().display;
80 glXMakeCurrent(dpy, 0, 0);
81 glXDestroyContext(dpy, priv->context);
82 XDestroyWindow(dpy, priv->subwnd);
87 void GLContext::swap_buffers()
89 glXSwapBuffers(display.get_private().display, priv->subwnd);
92 void GLContext::window_resized(unsigned w, unsigned h)
94 XMoveResizeWindow(display.get_private().display, priv->subwnd, 0, 0, w, h);
95 glViewport(0, 0, w, h);
98 } // namespace Graphics