aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/OpenGLResources.hh
diff options
context:
space:
mode:
authorGediminas Liktaras <gliktaras@gmail.com>2011-12-08 13:34:09 (GMT)
committerPaul Tagliamonte <paultag@fluxbox.org>2011-12-10 16:13:19 (GMT)
commitcd339169d1961eb508ea89cee2609ec6d0fc0c15 (patch)
tree01acd158a03fb17a72e067ff0b36701da75e49dc /util/fbcompose/OpenGLResources.hh
parent85ac5c4b2c6a526992f483a6e91867dc2f82a19e (diff)
downloadfluxbox_paul-cd339169d1961eb508ea89cee2609ec6d0fc0c15.zip
fluxbox_paul-cd339169d1961eb508ea89cee2609ec6d0fc0c15.tar.bz2
fbcompose - A compositing addon for fluxbox window manager.
fbcompose(1) is an optional compositing addon for fluxbox window manager. It augments fluxbox with a number of graphical features. Most notably, fbcompose allows fluxbox to properly display applications that require compositing (docky, for example), adds support for true window transparency (as opposed to fluxbox's pseudo transparency) and provides a plugin framework to extend the compositor's functionality. As this is still a beta version of the compositor, the bugs are likely.
Diffstat (limited to 'util/fbcompose/OpenGLResources.hh')
-rw-r--r--util/fbcompose/OpenGLResources.hh231
1 files changed, 231 insertions, 0 deletions
diff --git a/util/fbcompose/OpenGLResources.hh b/util/fbcompose/OpenGLResources.hh
new file mode 100644
index 0000000..6c27f99
--- /dev/null
+++ b/util/fbcompose/OpenGLResources.hh
@@ -0,0 +1,231 @@
1/** OpenGLResources.hh file for the fluxbox compositor. */
2
3// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21// THE SOFTWARE.
22
23
24#ifndef FBCOMPOSITOR_OPENGLRESOURCES_HH
25#define FBCOMPOSITOR_OPENGLRESOURCES_HH
26
27
28#include "FbTk/RefCount.hh"
29
30#include <GL/glxew.h>
31#include <GL/glx.h>
32
33#include <X11/Xlib.h>
34
35
36namespace FbCompositor {
37
38 class OpenGLScreen;
39
40
41 //--- OPENGL BUFFER WRAPPER ------------------------------------------------
42
43 /**
44 * A wrapper for OpenGL buffers.
45 */
46 class OpenGLBuffer {
47 public:
48 //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------
49
50 /** Constructor. */
51 OpenGLBuffer(const OpenGLScreen &screen, GLenum target_buffer);
52
53 /** Destructor. */
54 ~OpenGLBuffer();
55
56
57 //--- ACCESSORS --------------------------------------------------------
58
59 /** \returns the handle to the buffer held. */
60 GLuint handle() const;
61
62 /** \returns the target of the buffer. */
63 GLenum target() const;
64
65
66 //--- MUTATORS ---------------------------------------------------------
67
68 /** Bind the buffer to its target. */
69 void bind();
70
71 /** Loads the given data into the buffer. */
72 void bufferData(int element_size, const GLvoid *data, GLenum usage_hint);
73
74 /** Sets the buffer's contents to be the rectangle's coordinates on the screen. */
75 void bufferPosRectangle(int screen_width, int screen_height, XRectangle rect);
76
77
78 private:
79 //--- CONSTRUCTORS -----------------------------------------------------
80
81 /** Copy constructor. */
82 OpenGLBuffer(const OpenGLBuffer &other);
83
84 /** Assignment operator. */
85 OpenGLBuffer &operator=(const OpenGLBuffer &other);
86
87
88 //--- INTERNALS --------------------------------------------------------
89
90 /** The buffer in question. */
91 GLuint m_buffer;
92
93 /** The target buffer. */
94 GLenum m_target;
95
96
97 /** Screen that manages this buffer. */
98 const OpenGLScreen &m_screen;
99 };
100
101
102 // Bind the buffer to its target.
103 inline void OpenGLBuffer::bind() {
104 glBindBuffer(m_target, m_buffer);
105 }
106
107 // Loads the given data into the buffer.
108 inline void OpenGLBuffer::bufferData(int element_size, const GLvoid *data, GLenum usage_hint) {
109 bind();
110 glBufferData(m_target, element_size, data, usage_hint);
111 }
112
113 // Returns the handle to the buffer held.
114 inline GLuint OpenGLBuffer::handle() const {
115 return m_buffer;
116 }
117
118 // Returns the target of the buffer.
119 inline GLenum OpenGLBuffer::target() const {
120 return m_target;
121 }
122
123
124 /** OpenGL buffer wrapper smart pointer. */
125 typedef FbTk::RefCount<OpenGLBuffer> OpenGLBufferPtr;
126
127
128 //--- OPENGL TEXTURE WRAPPER -----------------------------------------------
129
130 /**
131 * OpenGL texture wrapper.
132 */
133 class OpenGL2DTexture {
134 public:
135 //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------
136
137 /** Constructor. */
138 OpenGL2DTexture(const OpenGLScreen &screen, bool swizzle_alpha_to_one);
139
140 /** Destructor. */
141 ~OpenGL2DTexture();
142
143
144 //--- ACCESSORS --------------------------------------------------------
145
146 /** \returns the handle to the texture held. */
147 GLuint handle() const;
148
149
150 /** \returns the height of the texture. */
151 int height() const;
152
153 /** \returns the width of the texture. */
154 int width() const;
155
156
157 //--- MUTATORS ---------------------------------------------------------
158
159 /** Bind the texture to GL_TEXTURE_2D. */
160 void bind();
161
162 /** Sets the texture's contents to the given pixmap. */
163 void setPixmap(Pixmap pixmap, bool manage_pixmap, int width, int height, bool force_direct = false);
164
165
166 private:
167 //--- CONSTRUCTORS -----------------------------------------------------
168
169 /** Constructor. */
170 OpenGL2DTexture(const OpenGL2DTexture &other);
171
172 /** Assignment operator. */
173 OpenGL2DTexture &operator=(const OpenGL2DTexture &other);
174
175
176 //--- INTERNALS --------------------------------------------------------
177
178 /** Whether this object manages the pixmap. */
179 bool m_pixmap_managed;
180
181 /** Pixmap of the texture's contents. */
182 Pixmap m_pixmap;
183
184 /** GLX pixmap of the texture's contents. */
185 GLXPixmap m_glx_pixmap;
186
187 /** The texture in question. */
188 GLuint m_texture;
189
190
191 /** Height of the texture. */
192 int m_height;
193
194 /** Width of the texture. */
195 int m_width;
196
197
198 /** Current connection to the X server. */
199 Display *m_display;
200
201 /** Screen that manages this texture. */
202 const OpenGLScreen &m_screen;
203 };
204
205
206 // Bind the texture to its target.
207 inline void OpenGL2DTexture::bind() {
208 glBindTexture(GL_TEXTURE_2D, m_texture);
209 }
210
211 // Returns the handle to the texture held.
212 inline GLuint OpenGL2DTexture::handle() const {
213 return m_texture;
214 }
215
216 // Returns the height of the texture.
217 inline int OpenGL2DTexture::height() const {
218 return m_height;
219 }
220
221 // Returns the width of the texture.
222 inline int OpenGL2DTexture::width() const {
223 return m_width;
224 }
225
226
227 /** OpenGL texture wrapper smart pointer. */
228 typedef FbTk::RefCount<OpenGL2DTexture> OpenGL2DTexturePtr;
229}
230
231#endif // FBCOMPOSITOR_OPENGLRESOURCES_HH