]> git.cworth.org Git - apitrace/blob - glws.hpp
Make windows build user friendlier.
[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     bool visible;
57
58     Drawable(const Visual *vis, int w, int h) :
59         visual(vis),
60         width(w),
61         height(h),
62         visible(false)
63     {}
64
65     virtual ~Drawable() {}
66     
67     virtual void
68     resize(int w, int h) {
69         width = w;
70         height = h;
71     }
72
73     virtual void
74     show(void) {
75         visible = true;
76     }
77
78     virtual void swapBuffers(void) = 0;
79 };
80
81
82 class Context
83 {
84 public:
85     const Visual *visual;
86     
87     Context(const Visual *vis) :
88         visual(vis)
89     {}
90
91     virtual ~Context() {}
92 };
93
94
95 class WindowSystem
96 {
97 public:
98     virtual ~WindowSystem() {}
99
100     virtual Visual *
101     createVisual(bool doubleBuffer = false) = 0;
102     
103     virtual Drawable *
104     createDrawable(const Visual *visual, int width = 32, int height = 32) = 0;
105
106     virtual Context *
107     createContext(const Visual *visual, Context *shareContext = NULL) = 0;
108     
109     virtual bool
110     makeCurrent(Drawable *drawable, Context *context) = 0;
111
112     virtual bool
113     processEvents(void) = 0;
114 };
115
116
117 WindowSystem *createNativeWindowSystem(void);
118
119
120 } /* namespace glws */
121
122
123 #endif /* _GLWS_HPP_ */