5 #include "window_private.h"
12 typedef HGLRC ContextHandle;
14 struct GLContext::Private
16 ContextHandle context;
20 void GLContext::platform_init(const GLOptions &opts)
22 HDC dc = GetDC(window.get_private().window);
24 PIXELFORMATDESCRIPTOR pfd;
25 memset(&pfd, 0, sizeof(pfd));
27 pfd.nSize = sizeof(pfd);
29 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
31 pfd.dwFlags |= PFD_DOUBLEBUFFER;
32 pfd.iPixelType = PFD_TYPE_RGBA;
39 int pf_index = ChoosePixelFormat(dc, &pfd);
41 throw unsupported_gl_mode(opts);
42 SetPixelFormat(dc, pf_index, &pfd);
45 if(opts.forward_compatible || opts.gl_version_major)
47 PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribs"));
48 if(!wglCreateContextAttribs)
49 throw unsupported_gl_mode(opts);
51 vector<int> ctx_attribs;
53 if(opts.forward_compatible)
55 ctx_attribs.push_back(WGL_CONTEXT_FLAGS_ARB);
56 ctx_attribs.push_back(WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
59 if(opts.gl_version_major)
61 ctx_attribs.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
62 ctx_attribs.push_back(opts.gl_version_major);
63 ctx_attribs.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
64 ctx_attribs.push_back(opts.gl_version_minor);
67 ctx_attribs.push_back(0);
69 priv->context = wglCreateContextAttribs(dc, 0, &ctx_attribs[0]);
72 priv->context = wglCreateContext(dc);
73 wglMakeCurrent(dc, priv->context);
75 ReleaseDC(window.get_private().window, dc);
78 GLContext::~GLContext()
81 wglDeleteContext(priv->context);
86 void GLContext::set_swap_interval(unsigned i)
88 PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
90 throw runtime_error("wglSwapIntervalEXT not found");
94 void GLContext::swap_buffers()
96 HDC dc = GetDC(window.get_private().window);
98 ReleaseDC(window.get_private().window, dc);
101 void GLContext::window_resized(unsigned, unsigned)
104 } // namespace Graphics