OGLplus (0.52.0) a C++ wrapper for OpenGL

location.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_PROG_VAR_LOCATION_1405052234_HPP
14 #define OGLPLUS_PROG_VAR_LOCATION_1405052234_HPP
15 
16 #include <oglplus/fwd.hpp>
17 #include <oglplus/string/ref.hpp>
18 #include <oglplus/object/tags.hpp>
19 #include <oglplus/object/name.hpp>
21 
22 namespace oglplus {
23 
24 template <typename VarTag>
25 GLint GetGLLocation(ProgVarLoc<VarTag>);
26 
28 template <typename VarTag>
29 class ProgVarLoc
30  : public ProgVarLocOps<VarTag>
31 {
32 protected:
33  friend GLint GetGLLocation<VarTag>(ProgVarLoc);
34  GLuint _program;
35  GLint _location;
36 
37  void RequireActive(StrCRef identifier) const
38  {
39  OGLPLUS_HANDLE_ERROR_IF(
40  !IsActive(),
41  GL_INVALID_OPERATION,
42  ProgVarLocOps<VarTag>::MsgUsingInactive(),
43  ProgVarError,
44  Program(ProgramName(_program)).
45  Identifier(identifier)
46  );
47  }
48 
49  void RequireActive(void) const
50  {
51  RequireActive(StrCRef());
52  }
53 public:
55  ProgVarLoc(void)
56  OGLPLUS_NOEXCEPT(true)
57  : _program(0u)
58  , _location(-1)
59  { }
60 
63  OGLPLUS_NOEXCEPT(true)
64  : _program(GetGLName(program))
65  , _location(-1)
66  { }
67 
69  OGLPLUS_EXPLICIT
70  ProgVarLoc(GLint location)
71  OGLPLUS_NOEXCEPT(true)
72  : _program(0)
73  , _location(location)
74  { }
75 
77  ProgVarLoc(ProgramName program, GLint location)
78  OGLPLUS_NOEXCEPT(true)
79  : _program(GetGLName(program))
80  , _location(location)
81  { }
82 
84  ProgVarLoc(ProgramName program, StrCRef identifier)
85  : _program(GetGLName(program))
86  , _location(ProgVarLocOps<VarTag>::GetLocation(
87  program,
88  identifier,
89  true
90  )){ }
91 
92  template <typename LocOpsParam>
93  ProgVarLoc(LocOpsParam param, ProgramName program, StrCRef identifier)
94  : ProgVarLocOps<VarTag>(param)
95  , _program(GetGLName(program))
96  , _location(ProgVarLocOps<VarTag>::GetLocation(
97  program,
98  identifier,
99  true
100  )){ }
101 
103  ProgVarLoc(ProgramName program, StrCRef identifier, bool active_only)
104  : _program(GetGLName(program))
105  , _location(ProgVarLocOps<VarTag>::GetLocation(
106  program,
107  identifier,
108  active_only
109  )){ }
110 
111  template <typename LocOpsParam>
112  ProgVarLoc(
113  LocOpsParam param,
114  ProgramName program,
115  StrCRef identifier,
116  bool active_only
117  ): ProgVarLocOps<VarTag>(param)
118  , _program(GetGLName(program))
119  , _location(ProgVarLocOps<VarTag>::GetLocation(
120  program,
121  identifier,
122  active_only
123  )){ }
124 
127  {
128  this->_program = that._program;
129  this->_location= that._location;
130  return *this;
131  }
132 
134  ProgVarLoc& BindTo(StrCRef identifier, bool is_active = true)
135  {
136  _location = ProgVarLocOps<VarTag>::GetLocation(
137  ProgramName(_program),
138  identifier,
139  is_active
140  );
141  return *this;
142  }
143 
145  ProgramName Program(void) const
146  OGLPLUS_NOEXCEPT(true)
147  {
148  return ProgramName(_program);
149  }
150 
152  GLint Location(void) const
153  OGLPLUS_NOEXCEPT(true)
154  {
155  return _location;
156  }
157 
159  bool IsActive(void) const
160  OGLPLUS_NOEXCEPT(true)
161  {
162  return _location >= 0;
163  }
164 
166  OGLPLUS_EXPLICIT operator bool (void) const
167  OGLPLUS_NOEXCEPT(true)
168  {
169  return IsActive();
170  }
171 
174  OGLPLUS_NOEXCEPT(true)
175  {
176  return (a._program == b._program)&&(a._location == b._location);
177  }
178 
181  OGLPLUS_NOEXCEPT(true)
182  {
183  return (a._program != b._program)||(a._location != b._location);
184  }
185 
188  OGLPLUS_NOEXCEPT(true)
189  {
190  if(a._program < b._program) return true;
191  if(a._program == b._program) return (a._location < b._location);
192  return false;
193  }
194 };
195 
197 template <typename VarTag>
198 inline GLint GetGLLocation(ProgVarLoc<VarTag> variable)
199 {
200  return variable._location;
201 }
202 
203 } // namespace oglplus
204 
205 #endif // include guard
ProgVarLoc(ProgramName program)
Creates variable without specific location in specified program.
Definition: location.hpp:62
OGLPLUS_EXPLICIT ProgVarLoc(GLint location)
Creates variable with specified location without specific program.
Definition: location.hpp:70
ProgVarLoc(ProgramName program, StrCRef identifier)
Creates variable with specified identifier in specified program.
Definition: location.hpp:84
ProgVarLoc(void)
Default construction.
Definition: location.hpp:55
ProgVarLoc(ProgramName program, GLint location)
Creates variable with specified location in specified program.
Definition: location.hpp:77
Forward declarations.
Wrapper encapsulating program variable location/index.
Definition: fwd.hpp:191
GLint GetGLLocation(ProgVarLoc< VarTag >)
Returns the GL location/index of the specified variable.
Definition: location.hpp:198
friend bool operator==(ProgVarLoc a, ProgVarLoc b)
Equality comparison.
Definition: location.hpp:173
ProgVarLoc(ProgramName program, StrCRef identifier, bool active_only)
Creates variable with specified identifier in specified program.
Definition: location.hpp:103
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
ProgVarLoc & Assign(ProgVarLoc that)
Copy assignment.
Definition: location.hpp:126
String reference.
GL Object tag types.
String const reference wrapper template.
Definition: ref_tpl.hpp:72
bool IsActive(void) const
Returns true if the variable is active.
Definition: location.hpp:159
ProgVarLoc & BindTo(StrCRef identifier, bool is_active=true)
Late initialization of the variable location from its identifier.
Definition: location.hpp:134
friend bool operator<(ProgVarLoc a, ProgVarLoc b)
Ordering.
Definition: location.hpp:187
friend bool operator!=(ProgVarLoc a, ProgVarLoc b)
Inequality comparison.
Definition: location.hpp:180
Base class for OpenGL "named" objects.
StrCRefTpl< GLchar > StrCRef
String const reference wrapper.
Definition: ref.hpp:21
Declaration of OGLplus program-variable-related error.
GLint Location(void) const
Returns the location of the variable.
Definition: location.hpp:152
ProgramName Program(void) const
The program the variable belongs to.
Definition: location.hpp:145

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