OGLplus (0.52.0) a C++ wrapper for OpenGL

set_ops.hpp
1 
12 #pragma once
13 #ifndef OGLPLUS_PROG_VAR_SET_OPS_1107121519_HPP
14 #define OGLPLUS_PROG_VAR_SET_OPS_1107121519_HPP
15 
16 #include <oglplus/fwd.hpp>
17 #include <oglplus/glfunc.hpp>
18 #include <oglplus/error/basic.hpp>
19 #include <oglplus/prog_var/callers.hpp>
20 
21 #include <type_traits>
22 #include <cstddef>
23 
24 namespace oglplus {
25 
26 template <class OpsTag, class VarTag, class TypTag, class T, std::size_t M>
27 class ProgVarBaseSetOps;
28 
29 template <typename OpsTag, typename VarTag, typename T, std::size_t M>
30 class ProgVarBaseSetOps<OpsTag, VarTag, tag::NativeTypes, T, M>
31  : public ProgVarSetters<OpsTag, VarTag, tag::NativeTypes>
32  , public ProgVarCallers<OpsTag, T>
33 {
34 private:
35  typedef ProgVarSetters<OpsTag, VarTag, tag::NativeTypes> Setters;
36  typedef ProgVarCallers<OpsTag, T> Callers;
37 
38  OGLPLUS_ERROR_REUSE_CONTEXT(Setters)
39 
40  typedef std::false_type _set_done;
41  typedef std::true_type _set_cont;
42 
43  template <std::size_t N>
44  static std::integral_constant<bool, (N > 4)> _set_mode(void)
45  {
46  return std::integral_constant<bool, (N > 4)>();
47  }
48 
49  template <std::size_t N, typename V>
50  static void _do_set_v(
51  _set_cont,
52  GLuint program,
53  GLuint base_location,
54  GLuint location,
55  const V* v
56  )
57  {
58  std::integral_constant<std::size_t, 4> nparam;
59  Callers::_call_set_v(
60  program,
61  location,
62  Setters::_fns_v(nparam, v),
63  v
64  );
65  OGLPLUS_CHECK_CTXT(
66  ProgVarError,
67  Program(ProgramName(program)).
68  Index(base_location)
69  );
70  _do_set_v<N - 4, V>(
71  _set_mode<N - 4>(),
72  program,
73  base_location,
74  location+1,
75  v+4
76  );
77  }
78 
79  template <std::size_t N, typename V>
80  static void _do_set_v(
81  _set_done,
82  GLuint program,
83  GLuint base_location,
84  GLuint location,
85  const V* v
86  )
87  {
88  std::integral_constant<std::size_t, N> nparam;
89  Callers::_call_set_v(
90  program,
91  location,
92  Setters::_fns_v(nparam, v),
93  v
94  );
95  OGLPLUS_CHECK_CTXT(
96  ProgVarError,
97  Program(ProgramName(program)).
98  Index(base_location)
99  );
100  }
101 
102  template <std::size_t N, typename V>
103  static void _do_set_n(
104  _set_done,
105  GLuint program,
106  GLuint base_location,
107  GLuint location,
108  GLsizei n,
109  const V* v
110  )
111  {
112  std::integral_constant<std::size_t, N> nparam;
113  Callers::_call_set_vn(
114  program,
115  location,
116  n,
117  Setters::_fns_v(nparam, v),
118  v
119  );
120  OGLPLUS_CHECK_CTXT(
121  ProgVarError,
122  Program(ProgramName(program)).
123  Index(base_location)
124  );
125  }
126 
127 
128 #if !OGLPLUS_NO_VARIADIC_TEMPLATES
129  template <typename S, typename ... V>
130  static void _do_set_t(
131  _set_cont,
132  GLuint program,
133  GLuint base_location,
134  GLuint location,
135  S v0, S v1, S v2, S v3,
136  V ... v
137  )
138  {
139  std::integral_constant<std::size_t, 4> nparam;
140  Callers::_call_set_t(
141  program,
142  location,
143  Setters::_fns_t(nparam, &v0),
144  v0, v1, v2, v3
145  );
146  OGLPLUS_CHECK_CTXT(
147  ProgVarError,
148  Program(ProgramName(program)).
149  Index(base_location)
150  );
151  _do_set_t(
152  _set_mode<sizeof...(V)>(),
153  program,
154  base_location,
155  location+1,
156  v...
157  );
158  }
159 
160  template <typename ... V>
161  static void _do_set_t(
162  _set_done,
163  GLuint program,
164  GLuint base_location,
165  GLuint location,
166  V ... v
167  )
168  {
169  std::integral_constant<std::size_t, sizeof...(V)> nparam;
170  Callers::_call_set_t(
171  program,
172  location,
173  Setters::_fns_t(nparam, &v...),
174  v...
175  );
176  OGLPLUS_CHECK_CTXT(
177  ProgVarError,
178  Program(ProgramName(program)).
179  Index(base_location)
180  );
181  }
182 #endif //NO_VARIADIC_TEMPLATES
183 
184 protected:
185 
186 #if !OGLPLUS_NO_VARIADIC_TEMPLATES
187  template <typename ... V>
188  static void _do_set(GLuint program, GLuint location, V ... v)
189  {
190  static_assert(
191  (sizeof...(V) > 0) && (sizeof...(V) <= M),
192  "Set requires 1 to M arguments"
193  );
194  _do_set_t(
195  _set_mode<sizeof...(V)>(),
196  program,
197  location,
198  location,
199  v...
200  );
201  OGLPLUS_CHECK_CTXT(
202  ProgVarError,
203  Program(ProgramName(program)).
204  Index(location)
205  );
206  }
207 #else
208  template <typename V>
209  static void _do_set(GLuint program, GLuint location, V v0)
210  {
211  std::integral_constant<std::size_t, 1> nparam;
212  Callers::_call_set_t(
213  program,
214  location,
215  Setters::_fns_t(nparam, &v0),
216  v0
217  );
218  OGLPLUS_CHECK_CTXT(
219  ProgVarError,
220  Program(ProgramName(program)).
221  Index(location)
222  );
223  }
224 
225  template <typename V>
226  static void _do_set(GLuint program, GLuint location, V v0, V v1)
227  {
228  std::integral_constant<std::size_t, 2> nparam;
229  Callers::_call_set_t(
230  program,
231  location,
232  Setters::_fns_t(nparam, &v0),
233  v0, v1
234  );
235  OGLPLUS_CHECK_CTXT(
236  ProgVarError,
237  Program(ProgramName(program)).
238  Index(base_location)
239  );
240  }
241 
242  template <typename V>
243  static void _do_set(GLuint program, GLuint location, V v0, V v1, V v2)
244  {
245  std::integral_constant<std::size_t, 3> nparam;
246  Callers::_call_set_t(
247  program,
248  location,
249  Setters::_fns_t(nparam, &v0),
250  v0, v1, v2
251  );
252  OGLPLUS_CHECK_CTXT(
253  ProgVarError,
254  Program(ProgramName(program)).
255  Index(base_location)
256  );
257  }
258 
259  template <typename V>
260  static void _do_set(GLuint program, GLuint location, V v0, V v1, V v2, V v3)
261  {
262  std::integral_constant<std::size_t, 4> nparam;
263  Callers::_call_set_t(
264  program,
265  location,
266  Setters::_fns_t(nparam, &v0),
267  v0, v1, v2, v3
268  );
269  OGLPLUS_CHECK_CTXT(
270  ProgVarError,
271  Program(ProgramName(program)).
272  Index(base_location)
273  );
274  }
275 #endif //NO_VARIADIC_TEMPLATES
276 
277  template <std::size_t Cols, typename V>
278  static void _do_set(GLuint program, GLuint location, const V* v)
279  {
280  static_assert(
281  (Cols > 0) && (Cols <= M),
282  "The number of elements must be between 1 and M"
283  );
284  _do_set_v<Cols, V>(
285  _set_mode<Cols>(),
286  program,
287  location,
288  location,
289  v
290  );
291  }
292 
293  template <std::size_t Cols, typename V>
294  static void _do_set_many(GLuint prog, GLuint location, GLsizei n, const V*v)
295  {
296  static_assert(
297  (Cols > 0) && (Cols <= M),
298  "The number of elements must be between 1 and M"
299  );
300  _do_set_n<Cols, V>(
301  _set_mode<Cols>(),
302  prog,
303  location,
304  location,
305  n,
306  v
307  );
308  }
309 };
310 
311 template <typename OpsTag, typename VarTag, typename T, std::size_t M>
312 class ProgVarBaseSetOps<OpsTag, VarTag, tag::MatrixTypes, T, M>
313  : public ProgVarSetters<OpsTag, VarTag, tag::MatrixTypes>
314  , public ProgVarCallers<OpsTag, T>
315 {
316 private:
317  typedef ProgVarSetters<OpsTag, VarTag, tag::MatrixTypes> Setters;
318  typedef ProgVarCallers<OpsTag, T> Callers;
319 
320  OGLPLUS_ERROR_REUSE_CONTEXT(Setters)
321 protected:
322  template <std::size_t Cols, std::size_t Rows, typename V>
323  static void _do_set_mat(
324  GLuint program,
325  GLuint location,
326  GLsizei count,
327  bool transpose,
328  V* v
329  )
330  {
331  static_assert(
332  (Cols > 0) && (Cols <= 4),
333  "The number of columns must be between 1 and 4"
334  );
335  static_assert(
336  (Rows > 0) && (Rows <= 4),
337  "The number of rows must be between 1 and 4"
338  );
339  std::integral_constant<std::size_t, Rows> rows;
340  std::integral_constant<std::size_t, Cols> cols;
341  Callers::_call_set_m(
342  program,
343  location,
344  count,
345  transpose ? GL_TRUE : GL_FALSE,
346  Setters::_fns_v(cols, rows, v),
347  v
348  );
349  OGLPLUS_CHECK_CTXT(
350  ProgVarError,
351  Program(ProgramName(program)).
352  Index(location)
353  );
354  }
355 
356 #if !OGLPLUS_NO_VARIADIC_TEMPLATES
357  template <std::size_t Cols, typename V, typename ... P>
358  static void _do_set_mat_p(
359  GLuint program,
360  GLuint location,
361  bool transpose,
362  V v,
363  P ... p
364  )
365  {
366  static_assert(
367  (Cols > 0) && (Cols <= 4),
368  "The number of columns must be between 1 and 4"
369  );
370  static_assert(
371  (sizeof...(P) + 1) % Cols == 0,
372  "Not enough values for the last row"
373  );
374  V values[] = {v, V(p)...};
375  _do_set_mat<Cols, (sizeof...(P) + 1) / Cols, V>(
376  program,
377  location,
378  1,
379  transpose,
380  values
381  );
382  }
383 #endif //NO_VARIADIC_TEMPLATES
384 };
385 
386 } // namespace oglplus
387 
388 #endif // include guard
Forward declarations.
Helper macro for optional checking of availability of GL function.
Declaration of basic OGLplus' exceptions.

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).