+++ /dev/null
-#include <stdexcept>
-#include "buffer.h"
-#include "color.h"
-#include "error.h"
-#include "matrix.h"
-#include "uniform.h"
-#include "uniformblock.h"
-#include "vector.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GL {
-
-UniformBlock::UniformBlock():
- buf_range(0)
-{ }
-
-UniformBlock::UniformBlock(unsigned s):
- size(s),
- data(size),
- buf_range(0)
-{ }
-
-UniformBlock::~UniformBlock()
-{
- delete buf_range;
-}
-
-unsigned UniformBlock::get_alignment() const
-{
- return BufferRange::get_uniform_buffer_alignment();
-}
-
-void UniformBlock::offset_changed()
-{
- delete buf_range;
- buf_range = 0;
-}
-
-void UniformBlock::upload_data() const
-{
- if(!buf_range)
- buf_range = new BufferRange(*buffer, buffer_offset, size);
- buf_range->data(&data[0]);
-}
-
-void UniformBlock::attach(int index, const Uniform &uni)
-{
- uniforms[index] = &uni;
-}
-
-void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni)
-{
- uniforms[info.location] = &uni;
- if(buffer)
- {
- uni.store(info, &data[info.location]);
- dirty = true;
- }
-}
-
-void UniformBlock::apply(int index) const
-{
- if((index>=0) != (buffer!=0))
- throw invalid_operation("UniformBlock::apply");
-
- if(buffer)
- {
- if(dirty)
- update_buffer_data();
- buf_range->bind_to(UNIFORM_BUFFER, index);
- }
- else
- {
- for(map<int, const Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
- i->second->apply(i->first);
- }
-}
-
-} // namespace GL
-} // namespace Msp