namespace GL {
UniformBlock::UniformBlock():
+ size(0),
buf_range(0)
{
static Require _req(ARB_shader_objects);
UniformBlock::UniformBlock(unsigned s):
size(s),
- data(size),
buf_range(0)
{
static Require _req(ARB_uniform_buffer_object);
+
+ if(!size)
+ throw invalid_argument("UniformBlock::UniformBlock");
+ data.resize(size);
}
UniformBlock::~UniformBlock()
void UniformBlock::attach(int index, const Uniform &uni)
{
+ if(size)
+ throw invalid_operation("UniformBlock::attach");
+
uniforms[index] = &uni;
}
void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
{
- uniforms[info.location] = &uni;
- if(get_buffer())
+ if(size)
{
uni.store(info, &data[info.location]);
dirty = true;
}
+ else
+ uniforms[info.location] = &uni;
}
void UniformBlock::apply(int index) const
{
- if((index>=0) != (get_buffer()!=0))
+ if((index>=0) != (size>0))
throw invalid_operation("UniformBlock::apply");
- if(get_buffer())
+ if(size)
{
+ if(!get_buffer())
+ throw invalid_operation("UniformBlock::apply");
+
if(dirty)
update_buffer();
buf_range->bind_to(UNIFORM_BUFFER, index);