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