2 #include <msp/gl/extensions/arb_shader_objects.h>
3 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
9 #include "uniformblock.h"
17 DefaultUniformBlock::DefaultUniformBlock()
19 static Require _req(ARB_shader_objects);
22 void DefaultUniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
24 if(info.block->bind_point>=0)
25 throw invalid_argument("DefaultUniformBlock::attach");
27 attach(info.location, uni);
30 void DefaultUniformBlock::attach(int index, const Uniform &uni)
35 if(static_cast<unsigned>(index)>=uniforms.size())
36 uniforms.resize(index+1, 0);
37 uniforms[index] = &uni;
40 void DefaultUniformBlock::apply(int index) const
43 throw invalid_argument("DefaultUniformBlock::apply");
45 for(unsigned i=0; i<uniforms.size(); ++i)
47 uniforms[i]->apply(i);
51 BufferBackedUniformBlock::BufferBackedUniformBlock(unsigned s):
56 static Require _req(ARB_shader_objects);
57 static Require _req2(ARB_uniform_buffer_object);
60 throw invalid_argument("BufferBackedUniformBlock::BufferBackedUniformBlock");
63 BufferBackedUniformBlock::~BufferBackedUniformBlock()
68 unsigned BufferBackedUniformBlock::get_alignment() const
70 return BufferRange::get_uniform_buffer_alignment();
73 void BufferBackedUniformBlock::location_changed(Buffer *buf, unsigned off, unsigned) const
76 buf_range = buf->create_range(off, size);
79 void BufferBackedUniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
81 if(info.block->bind_point<0)
82 throw invalid_argument("BufferBackedUniformBlock::attach");
84 uni.store(info, &data[info.offset]);
88 void BufferBackedUniformBlock::apply(int index) const
91 throw invalid_argument("BufferBackedUniformBlock::apply");
93 throw invalid_operation("UniformBlock::apply");
96 buf_range->bind_to(UNIFORM_BUFFER, index);