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::offset_changed()
51 void UniformBlock::upload_data(char *target) const
54 buf_range = new BufferRange(*get_buffer(), get_offset(), size);
57 copy(data.begin(), data.end(), target);
59 buf_range->data(&data[0]);
62 void UniformBlock::attach(int index, const Uniform &uni)
65 throw invalid_operation("UniformBlock::attach");
67 uniforms[index] = &uni;
70 void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
74 uni.store(info, &data[info.location]);
78 uniforms[info.location] = &uni;
81 void UniformBlock::apply(int index) const
83 if((index>=0) != (size>0))
84 throw invalid_operation("UniformBlock::apply");
89 throw invalid_operation("UniformBlock::apply");
93 buf_range->bind_to(UNIFORM_BUFFER, index);
97 for(map<int, const Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
98 i->second->apply(i->first);