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(char *target) const
50 buf_range = new BufferRange(*get_buffer(), get_offset(), size);
53 copy(data.begin(), data.end(), target);
55 buf_range->data(&data[0]);
58 void UniformBlock::attach(int index, const Uniform &uni)
60 uniforms[index] = &uni;
63 void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
65 uniforms[info.location] = &uni;
68 uni.store(info, &data[info.location]);
73 void UniformBlock::apply(int index) const
75 if((index>=0) != (get_buffer()!=0))
76 throw invalid_operation("UniformBlock::apply");
82 buf_range->bind_to(UNIFORM_BUFFER, index);
86 for(map<int, const Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
87 i->second->apply(i->first);