OGLplus (0.52.0) a C++ wrapper for OpenGL

wrapper.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_PROG_VAR_WRAPPER_1405052234_HPP
14 #define OGLPLUS_PROG_VAR_WRAPPER_1405052234_HPP
15 
16 #include <oglplus/fwd.hpp>
17 #include <oglplus/string/ref.hpp>
20 #include <cassert>
21 #include <new>
22 
23 namespace oglplus {
24 
25 template <typename VarTag>
26 class ProgVarCommonOps
27  : public ProgVarLoc<VarTag>
28 {
29 protected:
30  ProgVarCommonOps(ProgVarLoc<VarTag> pvloc)
31  : ProgVarLoc<VarTag>(pvloc)
32  { }
33 public:
34 };
35 
37 template <typename OpsTag, typename VarTag, typename ChkTag, typename T>
38 class ProgVar
39  : public ProgVarGetSetOps<OpsTag, VarTag, typename AdjustProgVar<T>::BaseType>
40  , public ProgVarTypecheck<ChkTag, VarTag>
41 {
42 private:
43  typedef typename AdjustProgVar<T>::BaseType BaseType;
44  typedef ProgVarGetSetOps<OpsTag, VarTag, BaseType> BaseGetSetOps;
45  typedef ProgVarTypecheck<ChkTag, VarTag> Typecheck;
46 public:
48  ProgVar(void)
49  : BaseGetSetOps(ProgVarLoc<VarTag>())
50  , Typecheck((BaseType*)0)
51  { }
52 
55  : BaseGetSetOps(pvloc)
56  , Typecheck((BaseType*)0)
57  { }
58 
60  ProgVar(ProgramName program, GLuint location)
61  : BaseGetSetOps(ProgVarLoc<VarTag>(program, GLint(location)))
62  , Typecheck((BaseType*)0)
63  { }
64 
66  ProgVar(ProgramName program, StrCRef identifier)
67  : BaseGetSetOps(ProgVarLoc<VarTag>(program, identifier))
68  , Typecheck((BaseType*)0)
69  {
70  Typecheck::CheckType(program, this->_location, identifier);
71  }
72 
74  ProgVar(ProgramName program, StrCRef identifier, bool active_only)
75  : BaseGetSetOps(ProgVarLoc<VarTag>(program, identifier, active_only))
76  , Typecheck((BaseType*)0)
77  {
78  Typecheck::CheckType(program, this->_location, identifier);
79  }
80 
82  ProgVar(ProgramName program, StrCRef identifier, std::nothrow_t)
83  : BaseGetSetOps(ProgVarLoc<VarTag>(program, identifier, false))
84  , Typecheck((BaseType*)0)
85  {
86  Typecheck::CheckType(program, this->_location, identifier);
87  }
88 
89  ProgVar& BindTo(StrCRef identifier)
90  {
91  BaseGetSetOps::BindTo(identifier);
92  Typecheck::CheckType(
93  ProgramName(this->_program),
94  this->_location,
95  identifier
96  );
97  return *this;
98  }
99 
100  ProgVar operator[](std::size_t offset) const
101  {
102  return ProgVar(
103  ProgramName(this->_program),
104  this->_location+offset
105  );
106  }
107 
108  ProgVar& operator = (ProgVarLoc<VarTag> pvloc)
109  {
110  BaseGetSetOps::Assign(pvloc);
111  return *this;
112  }
113 
115  typedef typename AdjustProgVar<T>::ValueType ParamType;
116 
118  void Set(ParamType value)
119  {
120  BaseGetSetOps::RequireActive();
121  BaseGetSetOps::SetValue(AdjustProgVar<T>::Adjust(value));
122  }
123 
125  void Set(std::size_t count, const T* values)
126  {
127  BaseGetSetOps::RequireActive();
128  BaseGetSetOps::SetValues(count, values);
129  }
130 
131  void Set(const std::vector<T>& values)
132  {
133  Set(values.size(), values.data());
134  }
135 
136  template <typename T0, typename T1>
137  void Set(T0 v0, T1 v1)
138  {
139  Set(ParamType(v0, v1));
140  }
141 
142  template <typename T0, typename T1, typename T2>
143  void Set(T0 v0, T1 v1, T2 v2)
144  {
145  Set(ParamType(v0, v1, v2));
146  }
147 
148  template <typename T0, typename T1, typename T2, typename T3>
149  void Set(T0 v0, T1 v1, T2 v2, T3 v3)
150  {
151  Set(ParamType(v0, v1, v2, v3));
152  }
153 
155  void TrySet(ParamType value)
156  {
157  if(this->IsActive())
158  {
159  BaseGetSetOps::SetValue(AdjustProgVar<T>::Adjust(value));
160  }
161  }
162 
164  ProgVar& operator = (ParamType value)
165  {
166  this->Set(value);
167  return *this;
168  }
169 };
170 
171 template <typename OpsTag, typename VarTag>
172 class ProgVar<OpsTag, VarTag, tag::NoTypecheck, void>
173  : public ProgVarCommonOps<VarTag>
174 {
175 private:
176  typedef ProgVarCommonOps<VarTag> BaseOps;
177 public:
179  ProgVar(void)
180  : BaseOps(ProgVarLoc<VarTag>())
181  { }
182 
184  ProgVar(ProgVarLoc<VarTag> pvloc)
185  : BaseOps(pvloc)
186  { }
187 
189  ProgVar(ProgramName program, GLuint location)
190  : BaseOps(ProgVarLoc<VarTag>(program, GLint(location)))
191  { }
192 
194  ProgVar(ProgramName program, StrCRef identifier)
195  : BaseOps(ProgVarLoc<VarTag>(program, identifier))
196  { }
197 
199  ProgVar(ProgramName program, StrCRef identifier, bool active_only)
200  : BaseOps(ProgVarLoc<VarTag>(program, identifier, active_only))
201  { }
202 
204  ProgVar(ProgramName program, StrCRef identifier, std::nothrow_t)
205  : BaseOps(ProgVarLoc<VarTag>(program, identifier, false))
206  { }
207 };
208 
209 #if !OGLPLUS_NO_INHERITED_CONSTRUCTORS
210 #define OGLPLUS_IMPLEMENT_PROG_VAR_CTRS(VAR_TAG, PROG_VAR, BASE) \
211  using BASE::BASE;
212 
213 #else
214 #define OGLPLUS_IMPLEMENT_PROG_VAR_CTRS(VAR_TAG, PROG_VAR, BASE) \
215  PROG_VAR(void) : BASE() { } \
216  PROG_VAR(ProgVarLoc<VAR_TAG> pvloc) : BASE(pvloc) { } \
217  PROG_VAR(ProgramName program, GLuint location) \
218  : BASE(program, location) { } \
219  PROG_VAR(ProgramName program, StrCRef identifier) \
220  : BASE(program, identifier) { } \
221  PROG_VAR(ProgramName program, StrCRef identifier, bool active_only) \
222  : BASE(program, identifier, active_only) { } \
223  PROG_VAR(ProgramName program, StrCRef identifier, std::nothrow_t nt) \
224  : BASE(program, identifier, nt) { }
225 #endif
226 
227 #if !OGLPLUS_NO_TEMPLATE_ALIASES
228 
229 // OGLPLUS_DECLARE_PROG_VAR
230 #define OGLPLUS_DECLARE_PROG_VAR(PROG_VAR, OPS_TAG, VAR_TAG, CHK_TAG) \
231 template <typename T> \
232 using PROG_VAR = ProgVar<OPS_TAG, VAR_TAG, CHK_TAG, T>;
233 
234 #else
235 
236 // OGLPLUS_DECLARE_PROG_VAR
237 #define OGLPLUS_DECLARE_PROG_VAR(PROG_VAR, OPS_TAG, VAR_TAG, CHK_TAG) \
238 template <typename T> \
239 class PROG_VAR \
240  : public ProgVar<OPS_TAG, VAR_TAG, CHK_TAG, T> \
241 { \
242 private:\
243  typedef ProgVar<OPS_TAG, VAR_TAG, CHK_TAG, T> Base;\
244 public:\
245  OGLPLUS_IMPLEMENT_PROG_VAR_CTRS(VAR_TAG, PROG_VAR, Base) \
246  PROG_VAR& operator = (ProgVarLoc<VAR_TAG> pvloc) \
247  { \
248  Base::Assign(pvloc); \
249  return *this; \
250  } \
251  PROG_VAR& operator = (typename Base::ParamType value) \
252  { \
253  this->Set(value); \
254  return *this; \
255  } \
256 }; \
257 template <typename T> \
258 struct Classify<PROG_VAR<T>> \
259  : Classify<ProgVar<OPS_TAG, VAR_TAG, CHK_TAG, T>> \
260 { };
261 #endif
262 
263 } // namespace oglplus
264 
265 #endif // include guard
ProgVar(ProgVarLoc< VarTag > pvloc)
Variable from a ProgVarLoc.
Definition: wrapper.hpp:54
AdjustProgVar< T >::ValueType ParamType
Parameter value type.
Definition: wrapper.hpp:115
void Set(ParamType value)
Set the variable value.
Definition: wrapper.hpp:118
Program variable location wrapper.
ProgVar(ProgramName program, StrCRef identifier, bool active_only)
Variable with the specified identifier in the specified program.
Definition: wrapper.hpp:74
void TrySet(ParamType value)
Sets the variable value if it is active.
Definition: wrapper.hpp:155
ProgVarLoc(void)
Default construction.
Definition: location.hpp:55
Forward declarations.
Wrapper encapsulating program variable location/index.
Definition: fwd.hpp:191
String reference.
void Set(std::size_t count, const T *values)
Set multiple values.
Definition: wrapper.hpp:125
Helper classes and functions used for program variable typechecking.
String const reference wrapper template.
Definition: ref_tpl.hpp:72
ProgVar(void)
Default construction.
Definition: wrapper.hpp:48
ProgVar(ProgramName program, StrCRef identifier, std::nothrow_t)
Variable with the specified identifier in the specified program.
Definition: wrapper.hpp:82
Program variable (vertex attrib / uniform ) wrapper.
Definition: fwd.hpp:222
ProgVar(ProgramName program, GLuint location)
Variable with the specified location in the specified program.
Definition: wrapper.hpp:60
ProgVar(ProgramName program, StrCRef identifier)
Variable with the specified identifier in the specified program.
Definition: wrapper.hpp:66

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).