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