Developer Documentation

UniformPool.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 #pragma once
44
45 //==============================================================================
46
47 #include <ACG/Config/ACGDefines.hh>
48 #include <ACG/Math/VectorT.hh>
49 #include <ACG/Math/GLMatrixT.hh>
50 #include <ACG/ShaderUtils/GLSLShader.hh>
51
52 #include <list>
53 #include <string>
54
55
56 //==============================================================================
57
58 namespace GLSL {
59
64 class ACGDLLEXPORT UniformPool {
65
66 public:
69 UniformPool();
70
73 UniformPool(const UniformPool& _pool);
74
75 virtual ~UniformPool();
76
77 void bind(PtrProgram _prog) const;
78 void bind(GLuint _prog) const;
79
80 void setUniform(const char *_name, GLint _value);
81 void setUniform(const char *_name, const ACG::Vec2i &_value);
82 void setUniform(const char *_name, const ACG::Vec3i &_value);
83 void setUniform(const char *_name, const ACG::Vec4i &_value);
84
85 void setUniform(const char *_name, GLuint _value);
86 void setUniform(const char *_name, const ACG::Vec2ui &_value);
87 void setUniform(const char *_name, const ACG::Vec3ui &_value);
88 void setUniform(const char *_name, const ACG::Vec4ui &_value);
89
90 void setUniform(const char *_name, GLfloat _value);
91 void setUniform(const char *_name, const ACG::Vec2f &_value);
92 void setUniform(const char *_name, const ACG::Vec3f &_value);
93 void setUniform(const char *_name, const ACG::Vec4f &_value);
94
95
96 void setUniform(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
97 void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
98
99
100 void setUniform(const char *_name, GLint *_values, int _count);
101 void setUniform(const char *_name, GLfloat *_values, int _count);
102
103
104 void addPool(const UniformPool& _src);
105
109 void clear();
110
115 bool empty() const;
116
120 QString toString() const;
121
125 UniformPool& operator =(const UniformPool& _other);
126
127 private:
128 struct UniformBase {
129 std::string id;
130
131
132 UniformBase() {}
133 virtual ~UniformBase() {}
134
135 virtual void bind(GLuint _progID) const {}
136
137 virtual QString toString() const { return QString(""); }
138 };
139
140 struct UniformVecf : public UniformBase {
141 ACG::Vec4f val;
142 int size;
143
144 void bind(GLuint _progID) const;
145
146 virtual QString toString() const;
147 };
148
149 // separate float int vector because sizeof(int) != sizeof(float) for some compilers
150 struct UniformVeci : public UniformBase {
151 ACG::Vec4i val;
152 int size;
153
154 void bind(GLuint _progID) const;
155
156 virtual QString toString() const;
157 };
158
159 struct UniformVecui : public UniformBase {
160 ACG::Vec4ui val;
161 int size;
162
163 void bind(GLuint _progID) const;
164
165 virtual QString toString() const;
166 };
167
168
169 struct UniformMat : UniformBase {
170 ACG::Matrix4x4f val;
171
172 bool transposed;
173 int size;
174
175 void bind(GLuint _progID) const;
176
177 virtual QString toString() const;
178 };
179
180 struct UniformBuf : public UniformBase {
181 float* val;
182
183 bool integer;
184 int size;
185
186 UniformBuf();
187 ~UniformBuf();
188
189 void bind(GLuint _progID) const;
190
191 virtual QString toString() const;
192 };
193
194
195 typedef std::list<UniformBase*> UniformList;
196 typedef UniformList::iterator UniformListIt;
197
199 UniformList pool_;
200
201 private:
202
203 UniformListIt findEntry(std::string _name);
204
205 void addVecf(const UniformVecf& _vec);
206 void addVeci(const UniformVeci& _vec);
207 void addVecui(const UniformVecui& _vec);
208 void addMatrix(const UniformMat& _mat);
209 void addBuf(const char *_name, void *_values, int _count, bool _integer);
210 };
211
212 typedef UniformPool* PtrUniformPool;
213 typedef const UniformPool* PtrConstUniformPool;
214
215 }
216
GLSL
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:66
OpenMesh::Kernel_OSG::bind
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Definition: bindT.hh:101
GLSL::UniformPool::pool_
UniformList pool_
list of uniform params
Definition: UniformPool.hh:199
GLSL::Program
GLSL program class.
Definition: GLSLShader.hh:211
GLSL::UniformPool::UniformVecui
Definition: UniformPool.hh:159
GLSL::UniformPool::UniformBase
Definition: UniformPool.hh:128
VectorT< signed int, 4 >
ACG::GLMatrixT< float >
GLSL::UniformPool::UniformBuf
Definition: UniformPool.hh:180
ACG::Matrix4x4T< float >
OpenMesh::VectorT
Definition: Vector11T.hh:83
GLSL::UniformPool::UniformVeci
Definition: UniformPool.hh:150
GLSL::UniformPool
GLSL uniform pool.
Definition: UniformPool.hh:64
GLSL::UniformPool::UniformMat
Definition: UniformPool.hh:169
GLSL::UniformPool::UniformVecf
Definition: UniformPool.hh:140