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  * *
44  * $Revision: 17546 $ *
45  * $Author: moebius $ *
46  * $Date: 2013-09-17 10:04:29 +0200 (Di, 17. Sep 2013) $ *
47  * *
48 \*===========================================================================*/
49 
50 #pragma once
51 
52 //==============================================================================
53 
54 #include <ACG/Config/ACGDefines.hh>
55 #include <ACG/Math/VectorT.hh>
56 #include <ACG/Math/GLMatrixT.hh>
57 #include <ACG/ShaderUtils/GLSLShader.hh>
58 
59 #include <list>
60 #include <string>
61 
62 
63 //==============================================================================
64 
65 namespace GLSL {
66 
71  class ACGDLLEXPORT UniformPool {
72 
73  public:
76  UniformPool();
77 
80  UniformPool(const UniformPool& _pool);
81 
82  virtual ~UniformPool();
83 
84  void bind(PtrProgram _prog) const;
85  void bind(GLuint _prog) const;
86 
87  void setUniform(const char *_name, GLint _value);
88  void setUniform(const char *_name, const ACG::Vec2i &_value);
89  void setUniform(const char *_name, const ACG::Vec3i &_value);
90  void setUniform(const char *_name, const ACG::Vec4i &_value);
91 
92  void setUniform(const char *_name, GLuint _value);
93  void setUniform(const char *_name, const ACG::Vec2ui &_value);
94  void setUniform(const char *_name, const ACG::Vec3ui &_value);
95  void setUniform(const char *_name, const ACG::Vec4ui &_value);
96 
97  void setUniform(const char *_name, GLfloat _value);
98  void setUniform(const char *_name, const ACG::Vec2f &_value);
99  void setUniform(const char *_name, const ACG::Vec3f &_value);
100  void setUniform(const char *_name, const ACG::Vec4f &_value);
101 
102 
103  void setUniform(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
104  void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
105 
106 
107  void setUniform(const char *_name, GLint *_values, int _count);
108  void setUniform(const char *_name, GLfloat *_values, int _count);
109 
110 
111  void addPool(const UniformPool& _src);
112 
116  void clear();
117 
122  bool empty() const;
123 
124  private:
125  struct UniformBase {
126  std::string id;
127 
128 
129  UniformBase() {}
130  virtual ~UniformBase() {}
131 
132  virtual void bind(GLuint _progID) const {}
133  };
134 
135  struct UniformVecf : public UniformBase {
136  ACG::Vec4f val;
137  int size;
138 
139  void bind(GLuint _progID) const;
140  };
141 
142  // separate float int vector because sizeof(int) != sizeof(float) for some compilers
143  struct UniformVeci : public UniformBase {
144  ACG::Vec4i val;
145  int size;
146 
147  void bind(GLuint _progID) const;
148  };
149 
150  struct UniformVecui : public UniformBase {
151  ACG::Vec4ui val;
152  int size;
153 
154  void bind(GLuint _progID) const;
155  };
156 
157 
159  ACG::Matrix4x4f val;
160 
161  bool transposed;
162  int size;
163 
164  void bind(GLuint _progID) const;
165  };
166 
167  struct UniformBuf : public UniformBase {
168  float* val;
169 
170  bool integer;
171  int size;
172 
173  UniformBuf();
174  ~UniformBuf();
175 
176  void bind(GLuint _progID) const;
177  };
178 
179 
180  typedef std::list<UniformBase*> UniformList;
181  typedef UniformList::iterator UniformListIt;
182 
184  UniformList pool_;
185 
186  private:
187 
188  UniformListIt findEntry(std::string _name);
189 
190  void addVecf(const UniformVecf& _vec);
191  void addVeci(const UniformVeci& _vec);
192  void addVecui(const UniformVecui& _vec);
193  void addMatrix(const UniformMat& _mat);
194  void addBuf(const char *_name, void *_values, int _count, bool _integer);
195  };
196 
197  typedef UniformPool* PtrUniformPool;
198  typedef const UniformPool* PtrConstUniformPool;
199 
200 }
201 
GLSL uniform pool.
Definition: UniformPool.hh:71
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Definition: bindT.hh:106
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:75
UniformList pool_
list of uniform params
Definition: UniformPool.hh:184
GLSL program class.
Definition: GLSLShader.hh:217