void GLContext::platform_init(const GLOptions &opts)
{
- priv = new Private;
-
vector<int> attribs;
-
+
attribs.push_back(GLX_RGBA);
attribs.push_back(GLX_DEPTH_SIZE);
attribs.push_back(1);
-
+
if(opts.alpha)
{
attribs.push_back(GLX_ALPHA_SIZE);
attribs.push_back(1);
}
-
+
if(opts.stencil)
{
attribs.push_back(GLX_STENCIL_SIZE);
attribs.push_back(1);
}
-
+
if(opts.doublebuffer)
attribs.push_back(GLX_DOUBLEBUFFER);
-
+
if(opts.multisample>0)
{
attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
attribs.push_back(GLX_SAMPLES_ARB);
attribs.push_back(opts.multisample);
}
-
+
attribs.push_back(0);
DisplayHandle dpy = display.get_private().display;
XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), &attribs.front());
if(!vi)
throw unsupported_gl_mode(opts);
+
+ priv = new Private;
priv->context = glXCreateContext(dpy, vi, 0, true);
XSetWindowAttributes attr;
delete priv;
}
+void GLContext::set_swap_interval(unsigned i)
+{
+ const GLubyte *name = reinterpret_cast<const GLubyte *>("glXSwapIntervalEXT");
+ PFNGLXSWAPINTERVALEXTPROC func = reinterpret_cast<PFNGLXSWAPINTERVALEXTPROC>(glXGetProcAddress(name));
+ if(!func)
+ throw runtime_error("glXSwapIntervalEXT not found");
+ func(display.get_private().display, priv->subwnd, i);
+}
+
void GLContext::swap_buffers()
{
glXSwapBuffers(display.get_private().display, priv->subwnd);
void GLContext::window_resized(unsigned w, unsigned h)
{
XMoveResizeWindow(display.get_private().display, priv->subwnd, 0, 0, w, h);
- glViewport(0, 0, w, h);
}
} // namespace Graphics