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