3 #include "cocoaglcontext.h"
4 #include "cocoapixelformat.h"
6 #include "window_private.h"
13 typedef CocoaGLContext *ContextHandle;
15 struct GLContext::Private
17 ContextHandle context;
20 void GLContext::platform_init(const GLOptions &opts)
24 vector<unsigned> attribs;
26 attribs.push_back(CPF_DEPTH_SIZE);
31 attribs.push_back(CPF_ALPHA_SIZE);
37 attribs.push_back(CPF_STENCIL_SIZE);
42 attribs.push_back(CPF_DOUBLEBUFFER);
44 if(opts.multisample>0)
46 attribs.push_back(CPF_SAMPLE_BUFFERS);
48 attribs.push_back(CPF_SAMPLES);
49 attribs.push_back(opts.multisample);
54 CocoaPixelFormat *pixfmt = choose_pixel_format(&attribs.front());
56 throw unsupported_gl_mode(opts);
58 priv->context = create_gl_context(pixfmt);
59 destroy_pixel_format(pixfmt);
61 attach_gl_context_to_window(priv->context, window.get_private().window);
62 make_gl_context_current(priv->context);
65 GLContext::~GLContext()
67 destroy_gl_context(priv->context);
71 void GLContext::swap_buffers()
73 flush_gl_buffer(priv->context);
76 void GLContext::window_resized(unsigned w, unsigned h)
78 // XXX Call [context update] here?
79 glViewport(0, 0, w, h);
82 } // namespace Graphics