18#ifndef HEADER_SP_UNIFORM_ASSIGNER_HPP
19#define HEADER_SP_UNIFORM_ASSIGNER_HPP
21#include "graphics/gl_headers.hpp"
22#include "utils/no_copy.hpp"
25#include "utils/log.hpp"
45 const GLuint m_location;
47 const std::type_index m_type;
49 mutable bool m_assigned;
54 : m_location(location), m_type(ti), m_assigned(
false) {}
56 bool runtimeChecking(
const std::type_info& ti)
const
61 Log::error(
"SPUniformAssigner",
"%s doesn't match %s which is the"
62 " type of this SPUniformAssigner", ti.name(), m_type.name());
69 void getValue(
const GLuint& p, irr::core::matrix4& mat)
const
71 if (runtimeChecking(
typeid(mat)))
74 glGetUniformfv(p, m_location, mat.pointer());
79 void getValue(
const GLuint& p, std::array<float, 4>& v)
const
81 if (runtimeChecking(
typeid(v)))
84 glGetUniformfv(p, m_location, v.data());
89 void getValue(
const GLuint& p, irr::core::vector3df& v)
const
91 if (runtimeChecking(
typeid(v)))
94 glGetUniformfv(p, m_location, &v.X);
99 void getValue(
const GLuint& p, irr::core::vector2df& v)
const
101 if (runtimeChecking(
typeid(v)))
104 glGetUniformfv(p, m_location, &v.X);
109 void getValue(
const GLuint& p,
float& v)
const
111 if (runtimeChecking(
typeid(v)))
114 glGetUniformfv(p, m_location, &v);
119 void getValue(
const GLuint& p,
int& v)
const
121 if (runtimeChecking(
typeid(v)))
124 glGetUniformiv(p, m_location, &v);
129 void setValue(
const irr::core::matrix4& mat)
const
131 if (runtimeChecking(
typeid(mat)))
134 glUniformMatrix4fv(m_location, 1, GL_FALSE, mat.pointer());
140 void setValue(
const std::array<float, 4>& v)
const
142 if (runtimeChecking(
typeid(v)))
145 glUniform4f(m_location, v[0], v[1], v[2], v[3]);
151 void setValue(
const irr::core::vector3df& v)
const
153 if (runtimeChecking(
typeid(v)))
156 glUniform3f(m_location, v.X, v.Y, v.Z);
162 void setValue(
const irr::core::vector2df& v)
const
164 if (runtimeChecking(
typeid(v)))
167 glUniform2f(m_location, v.X, v.Y);
173 void setValue(
float v)
const
175 if (runtimeChecking(
typeid(v)))
178 glUniform1f(m_location, v);
184 void setValue(
int v)
const
186 if (runtimeChecking(
typeid(v)))
189 glUniform1i(m_location, v);
201 if (m_type ==
typeid(
int))
203 glUniform1i(m_location, 0);
205 else if (m_type ==
typeid(
float))
207 glUniform1f(m_location, 0.0f);
209 else if (m_type ==
typeid(irr::core::matrix4))
211 static const char zeroes[64] = {};
212 glUniformMatrix4fv(m_location, 1, GL_FALSE, (
float*)zeroes);
214 else if (m_type ==
typeid(std::array<float, 4>))
216 glUniform4f(m_location, 0.0f, 0.0f, 0.0f,0.0f);
218 else if (m_type ==
typeid(irr::core::vector3df))
220 glUniform3f(m_location, 0.0f, 0.0f, 0.0f);
222 else if (m_type ==
typeid(irr::core::vector2df))
224 glUniform2f(m_location, 0.0f, 0.0f);
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26