2 #include <msp/gl/extensions/arb_shader_objects.h>
3 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
9 #include "uniformblock.h"
17 UniformBlock::UniformBlock():
21 static Require _req(ARB_shader_objects);
24 UniformBlock::UniformBlock(unsigned s):
28 static Require _req(ARB_uniform_buffer_object);
31 throw invalid_argument("UniformBlock::UniformBlock");
35 UniformBlock::~UniformBlock()
40 unsigned UniformBlock::get_alignment() const
42 return BufferRange::get_uniform_buffer_alignment();
45 void UniformBlock::location_changed(Buffer *buf, unsigned off, unsigned) const
48 buf_range = new BufferRange(*buf, off, size);
51 void UniformBlock::attach(int index, const Uniform &uni)
54 throw invalid_operation("UniformBlock::attach");
56 uniforms[index] = &uni;
59 void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
63 uni.store(info, &data[info.location]);
67 uniforms[info.location] = &uni;
70 void UniformBlock::apply(int index) const
72 if((index>=0) != (size>0))
73 throw invalid_operation("UniformBlock::apply");
78 throw invalid_operation("UniformBlock::apply");
81 buf_range->bind_to(UNIFORM_BUFFER, index);
85 for(map<int, const Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
86 i->second->apply(i->first);