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():
20 static Require _req(ARB_shader_objects);
23 UniformBlock::UniformBlock(unsigned s):
28 static Require _req(ARB_uniform_buffer_object);
31 UniformBlock::~UniformBlock()
36 unsigned UniformBlock::get_alignment() const
38 return BufferRange::get_uniform_buffer_alignment();
41 void UniformBlock::offset_changed()
47 void UniformBlock::upload_data() const
50 buf_range = new BufferRange(*get_buffer(), get_offset(), size);
51 buf_range->data(&data[0]);
54 void UniformBlock::attach(int index, const Uniform &uni)
56 uniforms[index] = &uni;
59 void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
61 uniforms[info.location] = &uni;
64 uni.store(info, &data[info.location]);
69 void UniformBlock::apply(int index) const
71 if((index>=0) != (get_buffer()!=0))
72 throw invalid_operation("UniformBlock::apply");
78 buf_range->bind_to(UNIFORM_BUFFER, index);
82 for(map<int, const Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
83 i->second->apply(i->first);