]> git.cworth.org Git - apitrace/blob - retrace/glws.hpp
retrace: Implement glxCopySubBufferMESA
[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 copySubBuffer(int x, int y, int width, int height) = 0;
131
132     virtual void swapBuffers(void) = 0;
133 };
134
135
136 class Context
137 {
138 public:
139     const Visual *visual;
140     Profile profile;
141     
142     std::set<std::string> extensions;
143
144     Context(const Visual *vis, Profile prof) :
145         visual(vis),
146         profile(prof)
147     {}
148
149     virtual ~Context() {}
150
151     // Context must be current
152     bool
153     hasExtension(const char *extension);
154 };
155
156
157 void
158 init(void);
159
160 void
161 cleanup(void);
162
163 Visual *
164 createVisual(bool doubleBuffer = false, Profile profile = PROFILE_COMPAT);
165
166 Drawable *
167 createDrawable(const Visual *visual, int width, int height, bool pbuffer = false);
168
169 Context *
170 createContext(const Visual *visual, Context *shareContext = 0, Profile profile = PROFILE_COMPAT, bool debug = false);
171
172 bool
173 makeCurrent(Drawable *drawable, Context *context);
174
175 bool
176 processEvents(void);
177
178
179 } /* namespace glws */
180
181
182 #endif /* _GLWS_HPP_ */