FastUIDraw
gluniform.hpp
Go to the documentation of this file.
1 /*!
2  * \file gluniform.hpp
3  * \brief file gluniform.hpp
4  *
5  * Adapted from: WRATHgluniform.hpp of WRATH:
6  *
7  * Copyright 2013 by Nomovok Ltd.
8  * Contact: info@nomovok.com
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@nomovok.com>
16  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
17  *
18  */
19 
20 
21 #ifndef FASTUIDRAW_GLUNIFORM_HPP
22 #define FASTUIDRAW_GLUNIFORM_HPP
23 
25 #include <fastuidraw/util/vecN.hpp>
28 #include <fastuidraw/gl_backend/gluniform_implement.hpp>
29 
30 
31 namespace fastuidraw
32 {
33 
34 namespace gl {
35 
36 /*!\addtogroup GLUtility
37  * @{
38  */
39 
40 
41  /*
42  * NOTE:
43  * The overload Uniform(int loc, const vecN<T, N> &v) mapping to
44  * Uniform(loc, v.size(), &v[0]) because if T is a GL type
45  * (for example float) and N is 2,3 or 4 it is ambigous if
46  * we are setting an array of floats or a single vec2, vec3
47  * or vec4 (for the case T=float)
48  */
49 
50 /*!
51  * \brief
52  * Template version for setting array of uniforms.
53  *
54  * Equivalent to
55  * \code
56  * Uniform(location, count, v.c_ptr());
57  * \endcode
58  * \param location location of uniform, i.e. return value
59  * of glGetUniformLocation
60  * \param v array of values
61  * \param count number of elements from the array v to use.
62  */
63 template<typename T, size_t N>
64 void
65 Uniform(int location, GLsizei count, const vecN<T,N> &v)
66 {
67  Uniform(location, count, v.c_ptr());
68 }
69 
70 /*!
71  * \brief
72  * Template version for setting array of uniform matrices.
73  *
74  * Equivalent to
75  * \code
76  * Uniform(location, count, v.c_ptr(), transposed);
77  * \endcode
78  * This call is for when v is an array of matrices.
79  * \param location location of uniform, i.e. return value
80  * of glGetUniformLocation
81  * \param v array of values
82  * \param count number of elements from the array v to use
83  * \param transposed flag to indicate if the matrices are to be transposed
84  */
85 template<typename T, size_t N>
86 void
87 Uniform(int location, GLsizei count, const vecN<T,N> &v, bool transposed)
88 {
89  Uniform(location, count, v.c_ptr(), transposed);
90 }
91 
92 
93 /*!
94  * \brief
95  * Template version for setting array of uniforms.
96  *
97  * Equivalent to
98  * \code
99  * Uniform(location, count, &v[0]);
100  * \endcode
101  * \param location location of uniform, i.e. return value
102  * of glGetUniformLocation
103  * \param v array of values
104  * \param count number of elements from the array v to use.
105  */
106 template<typename T>
107 void
108 Uniform(int location, GLsizei count, c_array<const T> v)
109 {
110  if (!v.empty())
111  {
112  Uniform(location, count, &v[0]);
113  }
114 }
115 
116 /*!
117  * \brief
118  * Template version for setting array of uniforms.
119  *
120  * Equivalent to
121  * \code
122  * Uniform(location, count, &v[0]);
123  * \endcode
124  * \param location location of uniform, i.e. return value
125  * of glGetUniformLocation
126  * \param v array of values
127  * \param count number of elements from the array v to use.
128  */
129 template<typename T>
130 void
131 Uniform(int location, GLsizei count, c_array<T> v)
132 {
133  if (!v.empty())
134  {
135  Uniform(location, count, &v[0]);
136  }
137 }
138 
139 /*!
140  * \brief
141  * Template version for setting array of uniforms.
142  *
143  * Equivalent to
144  * \code
145  * Uniform(location, count, &v[0], transposed);
146  * \endcode
147  * This call is for when v is an array of matrices.
148  * \param location location of uniform, i.e. return value
149  * of glGetUniformLocation
150  * \param v array of values
151  * \param count number of elements from the array v to use
152  * \param transposed flag to indicate if the matrices are to be transposed
153  */
154 template<typename T>
155 void
156 Uniform(int location, GLsizei count, c_array<const T> v, bool transposed)
157 {
158  if (!v.empty())
159  {
160  Uniform(location, count, &v[0], transposed);
161  }
162 }
163 
164 /*!
165  * \brief
166  * Template version for setting array of uniforms,
167  *
168  * Equivalent to
169  * \code
170  * Uniform(location, v.size(), &v[0]);
171  * \endcode
172  * \param location location of uniform, i.e. return value
173  * of glGetUniformLocation
174  * \param v array of values
175  */
176 template<typename T>
177 void
178 Uniform(int location, c_array<const T> v)
179 {
180  if (!v.empty())
181  {
182  Uniform(location, v.size(), &v[0]);
183  }
184 }
185 
186 #ifndef __EMSCRIPTEN__
187 
188 /*!
189  * \brief
190  * Template version for setting array of uniforms,
191  *
192  * Equivalent to
193  * \code
194  * ProgramUniform(program, location, count, v.c_ptr());
195  * \endcode
196  * \param program GL name of program to which uniform(s) belong
197  * \param location location of uniform, i.e. return value
198  * of glGetUniformLocation
199  * \param v array of values
200  * \param count number of elements from the array v to use.
201  */
202 template<typename T, size_t N>
203 void
204 ProgramUniform(GLuint program, int location, GLsizei count, const vecN<T,N> &v)
205 {
206  ProgramUniform(program, location, count, v.c_ptr());
207 }
208 
209 /*!
210  * Template version for setting array of uniform matrices,
211  * equivalent to
212  * \code
213  * ProgramUniform(program, location, count, v.c_ptr(), transposed);
214  * \endcode
215  * This call is for when v is an array of matrices.
216  * \param program GL name of program to which uniform(s) belong
217  * \param location location of uniform, i.e. return value
218  * of glGetUniformLocation
219  * \param v array of values
220  * \param count number of elements from the array v to use
221  * \param transposed flag to indicate if the matrices are to be transposed
222  */
223 template<typename T, size_t N>
224 void
225 ProgramUniform(GLuint program, int location, GLsizei count, const vecN<T,N> &v, bool transposed)
226 {
227  ProgramUniform(program, location, count, v.c_ptr(), transposed);
228 }
229 
230 
231 /*!
232  * \brief
233  * Template version for setting array of uniforms,
234  *
235  * Equivalent to
236  * \code
237  * ProgramUniform(program, location, count, &v[0]);
238  * \endcode
239  * \param program GL name of program to which uniform(s) belong
240  * \param location location of uniform, i.e. return value
241  * of glGetUniformLocation
242  * \param v array of values
243  * \param count number of elements from the array v to use.
244  */
245 template<typename T>
246 void
247 ProgramUniform(GLuint program, int location, GLsizei count, c_array<const T> v)
248 {
249  if (!v.empty())
250  {
251  ProgramUniform(program, location, count, &v[0]);
252  }
253 }
254 
255 /*!
256  * \brief
257  * Template version for setting array of uniforms,
258  *
259  * Equivalent to
260  * \code
261  * ProgramUniform(program, location, count, &v[0]);
262  * \endcode
263  * \param program GL name of program to which uniform(s) belong
264  * \param location location of uniform, i.e. return value
265  * of glGetUniformLocation
266  * \param v array of values
267  * \param count number of elements from the array v to use.
268  */
269 template<typename T>
270 void
271 ProgramUniform(GLuint program, int location, GLsizei count, c_array<T> v)
272 {
273  if (!v.empty())
274  {
275  ProgramUniform(program, location, count, &v[0]);
276  }
277 }
278 
279 /*!
280  * \brief
281  * Template version for setting array of uniforms.
282  *
283  * Equivalent to
284  * \code
285  * ProgramUniform(program, location, count, &v[0], transposed);
286  * \endcode
287  * This call is for when v is an array of matrices.
288  * \param program GL name of program to which uniform(s) belong
289  * \param location location of uniform, i.e. return value
290  * of glGetUniformLocation
291  * \param v array of values
292  * \param count number of elements from the array v to use
293  * \param transposed flag to indicate if the matrices are to be transposed
294  */
295 template<typename T>
296 void
297 ProgramUniform(GLuint program, int location, GLsizei count, c_array<const T> v, bool transposed)
298 {
299  if (!v.empty())
300  {
301  ProgramUniform(program, location, count, &v[0], transposed);
302  }
303 }
304 
305 /*!
306  * \brief
307  * Template version for setting array of uniforms,
308  *
309  * Equivalent to
310  * \code
311  * ProgramUniform(program, location, v.size(), &v[0]);
312  * \endcode
313  * \param program GL name of program to which uniform(s) belong
314  * \param location location of uniform, i.e. return value
315  * of glGetUniformLocation
316  * \param v array of values
317  */
318 template<typename T>
319 void
320 ProgramUniform(GLuint program, int location, c_array<const T> v)
321 {
322  if (!v.empty())
323  {
324  ProgramUniform(program, location, v.size(), &v[0]);
325  }
326 }
327 
328 #endif
329 
330 /*! @} */
331 
332 
333 } //namespace gl
334 } //namespace fastuidraw
335 
336 #endif
T * c_ptr(void)
Definition: vecN.hpp:400
file matrix.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
file gl_header.hpp
vecN is a simple static array class with no virtual functions and no memory overhead. Supports runtim array index checking and STL style iterators via pointer iterators.
Definition: vecN.hpp:42
bool empty(void) const
Definition: c_array.hpp:274
size_type size(void) const
Definition: c_array.hpp:283
file c_array.hpp
void Uniform(int location, GLsizei count, const vecN< T, N > &v)
Template version for setting array of uniforms.
Definition: gluniform.hpp:65
file vecN.hpp
void ProgramUniform(GLuint program, int location, GLsizei count, const vecN< T, N > &v)
Template version for setting array of uniforms,.
Definition: gluniform.hpp:204