]> git.cworth.org Git - apitrace/blob - glws.hpp
Workaround weird issue with gdb and dlopen'ed libpthread.so
[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 };
46
47
48 extern bool debug;
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     Context(const Visual *vis, Profile prof) :
136         visual(vis),
137         profile(prof)
138     {}
139
140     virtual ~Context() {}
141 };
142
143
144 void
145 init(void);
146
147 void
148 cleanup(void);
149
150 Visual *
151 createVisual(bool doubleBuffer = false);
152
153 Drawable *
154 createDrawable(const Visual *visual, int width = 32, int height = 32);
155
156 Context *
157 createContext(const Visual *visual, Context *shareContext = 0, Profile profile = PROFILE_COMPAT);
158
159 bool
160 makeCurrent(Drawable *drawable, Context *context);
161
162 bool
163 processEvents(void);
164
165
166 } /* namespace glws */
167
168
169 #endif /* _GLWS_HPP_ */