]> git.cworth.org Git - apitrace/blob - glws.hpp
9afebf4b878a4b639863bb08d8bf12927fbd0495
[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 #include <vector>
35
36
37 namespace glws {
38
39
40 enum Profile {
41     PROFILE_COMPAT = 0,
42     PROFILE_CORE,
43     PROFILE_ES1,
44     PROFILE_ES2,
45     PROFILE_MAX
46 };
47
48
49 extern bool debug;
50
51
52 bool
53 checkExtension(const char *extName, const char *extString);
54
55
56 template< class T >
57 class Attributes {
58 protected:
59     std::vector<T> attribs;
60
61 public:
62     void add(T param) {
63         attribs.push_back(param);
64     }
65
66     void add(T pname, T pvalue) {
67         add(pname);
68         add(pvalue);
69     }
70
71     void end(T terminator = 0) {
72         add(terminator);
73     }
74
75     operator T * (void) {
76         return &attribs[0];
77     }
78
79     operator const T * (void) const {
80         return &attribs[0];
81     }
82 };
83
84
85 class Visual
86 {
87 public:
88     unsigned long redMask;
89     unsigned long greenMask;
90     unsigned long blueMask;
91     unsigned long alphaMask;
92     bool doubleBuffer;
93
94     virtual ~Visual() {}
95 };
96
97
98 class Drawable
99 {
100 public:
101     const Visual *visual;
102     int width;
103     int height;
104     bool visible;
105
106     Drawable(const Visual *vis, int w, int h) :
107         visual(vis),
108         width(w),
109         height(h),
110         visible(false)
111     {}
112
113     virtual ~Drawable() {}
114     
115     virtual void
116     resize(int w, int h) {
117         width = w;
118         height = h;
119     }
120
121     virtual void
122     show(void) {
123         visible = true;
124     }
125
126     virtual void swapBuffers(void) = 0;
127 };
128
129
130 class Context
131 {
132 public:
133     const Visual *visual;
134     Profile profile;
135     
136     Context(const Visual *vis, Profile prof) :
137         visual(vis),
138         profile(prof)
139     {}
140
141     virtual ~Context() {}
142 };
143
144
145 void
146 init(void);
147
148 void
149 cleanup(void);
150
151 Visual *
152 createVisual(bool doubleBuffer = false, Profile profile = PROFILE_COMPAT);
153
154 Drawable *
155 createDrawable(const Visual *visual, int width = 32, int height = 32);
156
157 Context *
158 createContext(const Visual *visual, Context *shareContext = 0, Profile profile = PROFILE_COMPAT);
159
160 bool
161 makeCurrent(Drawable *drawable, Context *context);
162
163 bool
164 processEvents(void);
165
166
167 } /* namespace glws */
168
169
170 #endif /* _GLWS_HPP_ */