13 #ifndef OGLPLUS_UNIFORM_1107121519_HPP
14 #define OGLPLUS_UNIFORM_1107121519_HPP
20 #include <oglplus/prog_var/varpara_fns.hpp>
21 #include <oglplus/prog_var/set_ops.hpp>
23 #include <type_traits>
28 class ProgVarLocOps<tag::Uniform>
31 static const char* MsgGettingInactive(
void);
33 static const char* MsgUsingInactive(
void);
43 static GLint GetLocation(
49 GLint result = OGLPLUS_GLFUNC(GetUniformLocation)(
57 Identifier(identifier)
59 OGLPLUS_HANDLE_ERROR_IF(
60 active_only && (result < 0),
65 Identifier(identifier)
73 class ProgVarSetters<tag::ImplicitSel,
tag::Uniform, tag::NativeTypes>
78 OGLPLUS_AUX_VARPARA_FNS(
Uniform, ui, t, GLuint)
79 OGLPLUS_AUX_VARPARA_FNS(Uniform, i, t, GLint)
80 #if GL_ARB_bindless_texture
81 OGLPLUS_AUX_VARPARA_FNC(UniformHandle, ui64ARB, t, GLuint64, 1)
82 #elif GL_NV_shader_buffer_load
83 OGLPLUS_AUX_VARPARA_FNC(Uniform, ui64NV, t, GLuint64EXT, 1)
85 OGLPLUS_AUX_VARPARA_FNS(Uniform, f, t, GLfloat)
86 #if GL_VERSION_3_3 || GL_ARB_gpu_shader_fp64
87 OGLPLUS_AUX_VARPARA_FNS(Uniform, d, t, GLdouble)
90 OGLPLUS_AUX_VARPARA_FNS(Uniform, iv, v, GLint)
91 #if GL_ARB_bindless_texture
92 OGLPLUS_AUX_VARPARA_FNC(UniformHandle, ui64vARB, v, GLuint64, 1)
94 OGLPLUS_AUX_VARPARA_FNS(Uniform, fv, v, GLfloat)
95 #if GL_VERSION_3_3 || GL_ARB_gpu_shader_fp64
96 OGLPLUS_AUX_VARPARA_FNS(Uniform, dv, v, GLdouble)
102 class ProgVarSetters<tag::ImplicitSel,
tag::Uniform, tag::MatrixTypes>
105 OGLPLUS_ERROR_CONTEXT(UniformMatrix, Uniform)
107 OGLPLUS_AUX_VARPARA_MAT_FNS(UniformMatrix, fv, v, GLfloat)
108 #if GL_VERSION_3_3 || GL_ARB_gpu_shader_fp64
109 OGLPLUS_AUX_VARPARA_MAT_FNS(UniformMatrix, dv, v, GLdouble)
117 template <
typename OpsTag,
typename T>
118 class ProgVarGetSetOps<OpsTag, tag::Uniform, T>
119 :
public ProgVarCommonOps<tag::Uniform>
120 ,
public ProgVarBaseSetOps<OpsTag, tag::Uniform, tag::NativeTypes, T, 16>
124 : ProgVarCommonOps<tag::Uniform>(uloc)
145 this->
template _do_set_many<1>(
154 template <
typename OpsTag,
typename T, std::
size_t N>
155 class ProgVarGetSetOps<OpsTag, tag::Uniform, Vector<T, N>>
156 :
public ProgVarCommonOps<tag::Uniform>
157 ,
public ProgVarBaseSetOps<OpsTag, tag::Uniform, tag::NativeTypes, T, 4>
160 ProgVarGetSetOps(UniformLoc uloc)
161 : ProgVarCommonOps<tag::Uniform>(uloc)
164 void SetValue(
const Vector<T, N>& value)
166 this->
template _do_set<N>(_program, _location, Data(value));
169 void SetValues(std::size_t n,
const T* values)
172 this->
template _do_set_many<N>(
180 void SetValues(std::size_t n,
const Vector<T, N>* values, std::true_type)
182 const T* temp = (
const T*)(values);
183 SetValues(n*N, temp);
186 void SetValues(std::size_t n,
const Vector<T, N>* values,std::false_type)
190 for(std::size_t i=0; i!=n; ++i)
192 temp.insert(temp.end(), Data(values), Data(values)+N);
194 SetValues(temp.size(), temp.data());
197 void SetValues(std::size_t n,
const Vector<T, N>* values)
201 std::integral_constant<
203 sizeof(Vector<T, N>[4]) ==
sizeof(T[N*4])
209 template <
typename OpsTag,
typename T, std::
size_t R, std::
size_t C>
210 class ProgVarGetSetOps<OpsTag, tag::Uniform, Matrix<T, R, C>>
211 :
public ProgVarCommonOps<tag::Uniform>
212 ,
public ProgVarBaseSetOps<OpsTag, tag::Uniform, tag::MatrixTypes, T, 16>
215 ProgVarGetSetOps(UniformLoc uloc)
216 : ProgVarCommonOps<tag::Uniform>(uloc)
219 void SetValue(
const Matrix<T, R, C>& value)
221 this->
template _do_set_mat<C, R>(
230 void SetValues(std::size_t n,
bool row_major,
const T* values)
232 assert(n % R*C == 0);
233 this->
template _do_set_mat<C, R>(
244 const Matrix<T, R, C>* values,
248 const T* temp = (
const T*)(values);
249 SetValues(n*R*C,
true, temp);
254 const Matrix<T, R, C>* values,
260 for(std::size_t i=0; i!=n; ++i)
262 temp.insert(temp.end(), Data(values), Data(values)+R*C);
264 SetValues(temp.size(), temp.data());
267 void SetValues(std::size_t n,
const Matrix<T, R, C>* values)
271 std::integral_constant<
273 sizeof(Matrix<T, R, C>[4]) ==
sizeof(T[R*C*4])
286 typedef Uniform<GLint> UniformSampler;
290 template <typename OpsTag>
291 class ProgVar<OpsTag, tag::Uniform, tag::NoTypecheck,
void>
292 : public ProgVarCommonOps<tag::Uniform>
295 typedef ProgVarCommonOps<tag::Uniform> Base;
297 ProgVar(ProgramName program, GLuint location)
298 : Base(UniformLoc(program, location))
301 ProgVar(ProgramName program,
StrCRef identifier)
302 : Base(UniformLoc(program, identifier))
305 template <
typename T>
308 ProgVar<OpsTag, tag::Uniform, tag::NoTypecheck, T>(*this).Set(value);
311 template <
typename T>
312 ProgVar& operator = (T value)
319 typedef ProgVar<tag::ImplicitSel, tag::Uniform, tag::NoTypecheck, void> UntypedUniform;
321 inline UntypedUniform
322 operator / (ProgramName program,
StrCRef identifier)
324 return UntypedUniform(program, identifier);
329 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
330 #include <oglplus/uniform.ipp>
333 #endif // include guard
const Char * c_str(void) const
Returns the null-terminated c-string.
Definition: ref_tpl.hpp:200
Program variable wrapper.
Program variable location wrapper.
OGLPLUS_DECLARE_PROG_VAR(Uniform, tag::ImplicitSel, tag::Uniform, tag::NoTypecheck) typedef Uniform< GLint > UniformSampler
Uniform sampler.
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
String const reference wrapper template.
Definition: ref_tpl.hpp:72
Helper macro for optional checking of availability of GL function.
Declaration of OGLplus program-variable-related error.