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