uniform_matrix4(name, v);
}
+void ProgramData::uniform1_array(const string &name, unsigned n, const float *v)
+{
+ uniform(name, new UniformArray<Uniform1f>(n, v));
+}
+
+void ProgramData::uniform2_array(const string &name, unsigned n, const float *v)
+{
+ uniform(name, new UniformArray<Uniform2f>(n, v));
+}
+
+void ProgramData::uniform3_array(const string &name, unsigned n, const float *v)
+{
+ uniform(name, new UniformArray<Uniform3f>(n, v));
+}
+
+void ProgramData::uniform4_array(const string &name, unsigned n, const float *v)
+{
+ uniform(name, new UniformArray<Uniform4f>(n, v));
+}
+
+void ProgramData::uniform_matrix4_array(const string &name, unsigned n, const float *v)
+{
+ uniform(name, new UniformArray<UniformMatrix4x4f>(n, v));
+}
+
const UniformBlock &ProgramData::get_block(const Program &prog) const
{
if(modified)
void uniform4(const std::string &, const float *);
void uniform_matrix4(const std::string &, const float *);
void uniform_matrix4(const std::string &, const Matrix &);
+ void uniform1_array(const std::string &, unsigned, const float *);
+ void uniform2_array(const std::string &, unsigned, const float *);
+ void uniform3_array(const std::string &, unsigned, const float *);
+ void uniform4_array(const std::string &, unsigned, const float *);
+ void uniform_matrix4_array(const std::string &, unsigned, const float *);
const UniformBlock &get_block(const Program &) const;
namespace GL {
template<>
-void UniformScalar<int>::apply(int index) const
+void UniformScalar<int>::apply(int index, unsigned size, const int *value)
{
- glUniform1iARB(index, value);
+ glUniform1ivARB(index, size, value);
}
template<>
-void UniformScalar<float>::apply(int index) const
+void UniformScalar<float>::apply(int index, unsigned size, const float *value)
{
- glUniform1fARB(index, value);
+ glUniform1fvARB(index, size, value);
}
template<>
-void UniformVector<float, 2>::apply(int index) const
+void UniformVector<float, 2>::apply(int index, unsigned size, const float *value)
{
- glUniform2fvARB(index, 1, value);
+ glUniform2fvARB(index, size, value);
}
template<>
-void UniformVector<float, 3>::apply(int index) const
+void UniformVector<float, 3>::apply(int index, unsigned size, const float *value)
{
- glUniform3fvARB(index, 1, value);
+ glUniform3fvARB(index, size, value);
}
template<>
-void UniformVector<float, 4>::apply(int index) const
+void UniformVector<float, 4>::apply(int index, unsigned size, const float *value)
{
- glUniform4fvARB(index, 1, value);
+ glUniform4fvARB(index, size, value);
}
template<>
-void UniformMatrix<float, 4, 4>::apply(int index) const
+void UniformMatrix<float, 4, 4>::apply(int index, unsigned size, const float *value)
{
- glUniformMatrix4fvARB(index, 1, false, value);
+ glUniformMatrix4fvARB(index, size, false, value);
}
} // namespace GL
public:
UniformScalar(Type v): value(v) { }
- virtual void apply(int index) const;
+ virtual void apply(int index) const
+ { apply(index, 1, &value); }
+
+ static void apply(int, unsigned, const T *);
virtual UniformScalar *clone() const
{ return new UniformScalar(value); }
UniformVector(const T *vp)
{ std::copy(vp, vp+vecsize, value); }
- virtual void apply(int index) const;
+ virtual void apply(int index) const
+ { apply(index, 1, value); }
+
+ static void apply(int index, unsigned size, const T *value);
virtual UniformVector *clone() const
{ return new UniformVector(value); }
UniformMatrix(const T *vp)
{ std::copy(vp, vp+rows*cols, value); }
- virtual void apply(int index) const;
+ virtual void apply(int index) const
+ { apply(index, 1, value); }
+
+ static void apply(int index, unsigned size, const T *value);
virtual UniformMatrix *clone() const
{ return new UniformMatrix(value); }
typedef UniformMatrix<float, 4, 4> UniformMatrix4x4f;
+
+template<typename T>
+class UniformArray: public Uniform
+{
+private:
+ typedef typename T::BaseType BaseType;
+
+ BaseType *values;
+ unsigned size;
+
+public:
+ UniformArray(unsigned n, const BaseType *vp):
+ size(n)
+ {
+ unsigned elemsize = sizeof(typename T::Type)/sizeof(typename T::BaseType);
+ values = new BaseType[elemsize*size];
+ std::copy(vp, vp+elemsize*size, values);
+ }
+
+ virtual void apply(int index) const
+ { T::apply(index, size, values); }
+
+ virtual UniformArray *clone() const
+ { return new UniformArray(size, values); }
+};
+
} // namespace GL
} // namespace Msp