aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/OpenGLShaders.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/OpenGLShaders.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/OpenGLShaders.hh')
-rw-r--r--util/fbcompose/OpenGLShaders.hh227
1 files changed, 227 insertions, 0 deletions
diff --git a/util/fbcompose/OpenGLShaders.hh b/util/fbcompose/OpenGLShaders.hh
new file mode 100644
index 0000000..ee4a6b2
--- /dev/null
+++ b/util/fbcompose/OpenGLShaders.hh
@@ -0,0 +1,227 @@
1/** OpenGLShaders.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_OPENGLSHADERS_HH
25#define FBCOMPOSITOR_OPENGLSHADERS_HH
26
27
28#include "FbTk/Command.hh"
29#include "FbTk/RefCount.hh"
30
31#include <GL/glew.h>
32#include <GL/gl.h>
33
34#include <vector>
35
36
37namespace FbCompositor {
38
39 class BasePlugin;
40
41
42 //--- SHADER INITIALIZERS --------------------------------------------------
43
44 /** Rendering job initialization functor. */
45 typedef FbTk::Command<void> OpenGLShaderInitializer;
46
47 /**
48 * Null initialization action.
49 */
50 class NullInitializer : public OpenGLShaderInitializer {
51 public :
52 virtual ~NullInitializer() { }
53 void execute() { }
54 };
55
56
57 //--- SHADER DEINITIALIZERS ------------------------------------------------
58
59 /** Rendering job cleanup functor. */
60 typedef FbTk::Command<void> OpenGLShaderDeinitializer;
61
62 /**
63 * Null cleanup action.
64 */
65 class NullDeinitializer : public OpenGLShaderDeinitializer {
66 public :
67 virtual ~NullDeinitializer() { }
68 void execute() { }
69 };
70
71
72 //--- SHADER PROGRAM WRAPPER -----------------------------------------------
73
74 /**
75 * OpenGL shader program wrapper.
76 */
77 class OpenGLShaderProgram {
78 public :
79 //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------
80
81 /** Constructor. */
82 OpenGLShaderProgram(const std::vector<BasePlugin*> &plugins);
83
84 /** Destructor. */
85 ~OpenGLShaderProgram();
86
87
88 //--- ACCESSORS --------------------------------------------------------
89
90 /** \returns handle to the shader program. */
91 GLuint programHandle() const;
92
93
94 /** \returns location of the given attribute. */
95 GLuint getAttributeLocation(const char *attrib_name);
96
97 /** \returns location of the fb_InitMainTexCoord attribute. */
98 GLuint mainTexCoordAttrib() const;
99
100 /** \returns location of the fb_InitPrimPos attribute. */
101 GLuint primPosAttrib() const;
102
103 /** \returns location of the fb_InitShapeTexCoord attribute. */
104 GLuint shapeTexCoordAttrib() const;
105
106
107 /** \returns location of the given uniform. */
108 GLuint getUniformLocation(const char *uniform_name);
109
110 /** \returns location of the fb_Alpha uniform. */
111 GLuint alphaUniform() const;
112
113 /** \returns location of the fb_MainTexture uniform. */
114 GLuint mainTexUniform() const;
115
116 /** \returns location of the fb_ShapeTexture uniform. */
117 GLuint shapeTexUniform() const;
118
119
120 //--- SHADER MANIPULATION ----------------------------------------------
121
122 /** Uses the current shader program. */
123 void use();
124
125
126 private :
127 //--- INITIALIZATION FUNCTIONS -----------------------------------------
128
129 /** Creates a shader. */
130 GLuint createShader(GLenum shader_type, GLint source_length, const GLchar *source);
131
132 /** Creates a shader program. */
133 GLuint createShaderProgram(GLuint vertex_shader, GLuint fragment_shader);
134
135
136 //--- MAIN VARIABLES ---------------------------------------------------
137
138 /** The vertex shader. */
139 GLuint m_vertex_shader;
140
141 /** The fragment shader. */
142 GLuint m_fragment_shader;
143
144 /** The shader program. */
145 GLuint m_shader_program;
146
147
148 /** Location of the fb_InitMainTexCoord attribute. */
149 GLuint m_main_tex_coord_attrib;
150
151 /** Location of the fb_InitPrimPos attribute. */
152 GLuint m_prim_pos_attrib;
153
154 /** Location of the fb_InitShapeTexCoord attribute. */
155 GLuint m_shape_tex_coord_attrib;
156
157
158 /** Location of the fb_Alpha uniform. */
159 GLuint m_alpha_uniform;
160
161 /** Location of the fb_MainTexture uniform. */
162 GLuint m_main_tex_uniform;
163
164 /** Location of the fb_ShapeTexture uniform. */
165 GLuint m_shape_tex_uniform;
166 };
167
168
169 //--- INLINE FUNCTIONS -------------------------------------------------
170
171 // Returns location of the fb_Alpha uniform.
172 inline GLuint OpenGLShaderProgram::alphaUniform() const {
173 return m_alpha_uniform;
174 }
175
176 // Returns location of the given attribute.
177 inline GLuint OpenGLShaderProgram::getAttributeLocation(const char *attrib_name) {
178 return glGetAttribLocation(m_shader_program, attrib_name);
179 }
180
181 // Returns location of the given uniform.
182 inline GLuint OpenGLShaderProgram::getUniformLocation(const char *uniform_name) {
183 return glGetUniformLocation(m_shader_program, uniform_name);
184 }
185
186 // Returns location of the fb_InitMainTexCoord attribute.
187 inline GLuint OpenGLShaderProgram::mainTexCoordAttrib() const {
188 return m_main_tex_coord_attrib;
189 }
190
191 // Returns location of the fb_MainTexture uniform.
192 inline GLuint OpenGLShaderProgram::mainTexUniform() const {
193 return m_main_tex_uniform;
194 }
195
196 // Returns location of the fb_InitPrimPos attribute.
197 inline GLuint OpenGLShaderProgram::primPosAttrib() const {
198 return m_prim_pos_attrib;
199 }
200
201 // Returns the handle to the shader program.
202 inline GLuint OpenGLShaderProgram::programHandle() const {
203 return m_shader_program;
204 }
205
206 // Returns location of the fb_InitShapeTexCoord attribute.
207 inline GLuint OpenGLShaderProgram::shapeTexCoordAttrib() const {
208 return m_shape_tex_coord_attrib;
209 }
210
211 // Returns location of the fb_ShapeTexture uniform.
212 inline GLuint OpenGLShaderProgram::shapeTexUniform() const {
213 return m_shape_tex_uniform;
214 }
215
216 // Uses the current shader program.
217 inline void OpenGLShaderProgram::use() {
218 glUseProgram(m_shader_program);
219 }
220
221
222 //--- TYPEDEFS ---------------------------------------------------------
223
224 typedef FbTk::RefCount<OpenGLShaderProgram> OpenGLShaderProgramPtr;
225}
226
227#endif // FBCOMPOSITOR_OPENGLSHADERS_HH