]> git.cworth.org Git - apitrace/blob - glws.hpp
Put license in a separate file.
[apitrace] / glws.hpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 /*
27  * Abstraction for GL window system specific APIs (GLX, WGL).
28  */
29
30 #ifndef _GLWS_HPP_
31 #define _GLWS_HPP_
32
33
34 namespace glws {
35
36
37 class Visual
38 {
39 public:
40     unsigned long redMask;
41     unsigned long greenMask;
42     unsigned long blueMask;
43     unsigned long alphaMask;
44     bool doubleBuffer;
45
46     virtual ~Visual() {}
47 };
48
49
50 class Drawable
51 {
52 public:
53     const Visual *visual;
54     int width;
55     int height;
56
57     Drawable(const Visual *vis, int w, int h) :
58         visual(vis),
59         width(w),
60         height(h)
61     {}
62
63     virtual ~Drawable() {}
64     
65     virtual void
66     resize(int w, int h) {
67         width = w;
68         height = h;
69     }
70
71     virtual void swapBuffers(void) = 0;
72 };
73
74
75 class Context
76 {
77 public:
78     const Visual *visual;
79     
80     Context(const Visual *vis) :
81         visual(vis)
82     {}
83
84     virtual ~Context() {}
85 };
86
87
88 class WindowSystem
89 {
90 public:
91     virtual ~WindowSystem() {}
92
93     virtual Visual *
94     createVisual(bool doubleBuffer = false) = 0;
95     
96     virtual Drawable *
97     createDrawable(const Visual *visual, int width = 256, int height = 256) = 0;
98
99     virtual Context *
100     createContext(const Visual *visual, Context *shareContext = NULL) = 0;
101     
102     virtual bool
103     makeCurrent(Drawable *drawable, Context *context) = 0;
104
105     virtual bool
106     processEvents(void) = 0;
107 };
108
109
110 WindowSystem *createNativeWindowSystem(void);
111
112
113 } /* namespace glws */
114
115
116 #endif /* _GLWS_HPP_ */