]> git.tdb.fi Git - libs/gl.git/blobdiff - source/uniformblock.cpp
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / uniformblock.cpp
index a87a6a42386ed39ee04b7368524796decd64ecfe..cc8945cf2093358d7df19ccebfe5e92ee9fffa61 100644 (file)
@@ -1,4 +1,6 @@
 #include <stdexcept>
+#include <msp/gl/extensions/arb_shader_objects.h>
+#include <msp/gl/extensions/arb_uniform_buffer_object.h>
 #include "buffer.h"
 #include "color.h"
 #include "error.h"
@@ -13,14 +15,22 @@ namespace Msp {
 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()
 {
@@ -32,43 +42,42 @@ unsigned UniformBlock::get_alignment() const
        return BufferRange::get_uniform_buffer_alignment();
 }
 
-void UniformBlock::offset_changed()
+void UniformBlock::location_changed(Buffer *buf, unsigned off, unsigned) const
 {
        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]);
+       buf_range = new BufferRange(*buf, off, size);
 }
 
 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(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) != (buffer!=0))
+       if((index>=0) != (size>0))
                throw invalid_operation("UniformBlock::apply");
 
-       if(buffer)
+       if(size)
        {
-               if(dirty)
-                       update_buffer_data();
+               if(!get_buffer())
+                       throw invalid_operation("UniformBlock::apply");
+
+               refresh();
                buf_range->bind_to(UNIFORM_BUFFER, index);
        }
        else