]> git.tdb.fi Git - libs/gui.git/blob - source/graphics/cgl/glcontext.cpp
Remove glViewport calls from GLContext
[libs/gui.git] / source / graphics / cgl / glcontext.cpp
1 #include <vector>
2 #include <OpenGL/gl.h>
3 #include "cocoaglcontext.h"
4 #include "cocoapixelformat.h"
5 #include "glcontext.h"
6 #include "window_private.h"
7
8 using namespace std;
9
10 namespace Msp {
11 namespace Graphics {
12
13 typedef CocoaGLContext *ContextHandle;
14
15 struct GLContext::Private
16 {
17         ContextHandle context;
18 };
19
20 void GLContext::platform_init(const GLOptions &opts)
21 {
22         vector<unsigned> attribs;
23
24         attribs.push_back(CPF_DEPTH_SIZE);
25         attribs.push_back(1);
26
27         if(opts.alpha)
28         {
29                 attribs.push_back(CPF_ALPHA_SIZE);
30                 attribs.push_back(1);
31         }
32
33         if(opts.stencil)
34         {
35                 attribs.push_back(CPF_STENCIL_SIZE);
36                 attribs.push_back(1);
37         }
38
39         if(opts.doublebuffer)
40                 attribs.push_back(CPF_DOUBLEBUFFER);
41
42         if(opts.multisample>0)
43         {
44                 attribs.push_back(CPF_SAMPLE_BUFFERS);
45                 attribs.push_back(1);
46                 attribs.push_back(CPF_SAMPLES);
47                 attribs.push_back(opts.multisample);
48         }
49
50         attribs.push_back(0);
51
52         CocoaPixelFormat *pixfmt = choose_pixel_format(&attribs.front());
53         if(!pixfmt)
54                 throw unsupported_gl_mode(opts);
55
56         priv = new Private;
57         priv->context = create_gl_context(pixfmt);
58         destroy_pixel_format(pixfmt);
59
60         attach_gl_context_to_window(priv->context, window.get_private().window);
61         make_gl_context_current(priv->context);
62 }
63
64 GLContext::~GLContext()
65 {
66         destroy_gl_context(priv->context);
67         delete priv;
68 }
69
70 void GLContext::swap_buffers()
71 {
72         flush_gl_buffer(priv->context);
73 }
74
75 void GLContext::window_resized(unsigned w, unsigned h)
76 {
77         // XXX Call [context update] here?
78 }
79
80 } // namespace Graphics
81 } // namespace Msp