2 #include <msp/gl/extensions/arb_shader_objects.h>
3 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
6 #include "deviceinfo.h"
10 #include "uniformblock.h"
18 DefaultUniformBlock::DefaultUniformBlock()
20 static Require _req(ARB_shader_objects);
23 void DefaultUniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
25 if(info.block->bind_point>=0)
26 throw invalid_argument("DefaultUniformBlock::attach");
28 attach(info.location, uni);
31 void DefaultUniformBlock::attach(int index, const Uniform &uni)
36 if(static_cast<unsigned>(index)>=uniforms.size())
37 uniforms.resize(index+1, 0);
38 uniforms[index] = &uni;
41 void DefaultUniformBlock::apply(int index) const
44 throw invalid_argument("DefaultUniformBlock::apply");
46 for(unsigned i=0; i<uniforms.size(); ++i)
48 uniforms[i]->apply(i);
52 BufferBackedUniformBlock::BufferBackedUniformBlock(unsigned s):
57 static Require _req(ARB_shader_objects);
58 static Require _req2(ARB_uniform_buffer_object);
61 throw invalid_argument("BufferBackedUniformBlock::BufferBackedUniformBlock");
64 BufferBackedUniformBlock::~BufferBackedUniformBlock()
69 unsigned BufferBackedUniformBlock::get_alignment() const
71 return Limits::get_global().uniform_buffer_alignment;
74 void BufferBackedUniformBlock::location_changed(Buffer *buf, unsigned off, unsigned) const
77 buf_range = buf->create_range(off, size);
80 void BufferBackedUniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
82 if(info.block->bind_point<0)
83 throw invalid_argument("BufferBackedUniformBlock::attach");
85 uni.store(info, &data[info.offset]);
89 void BufferBackedUniformBlock::apply(int index) const
92 throw invalid_argument("BufferBackedUniformBlock::apply");
94 throw invalid_operation("UniformBlock::apply");
97 buf_range->bind_to(UNIFORM_BUFFER, index);