]> git.tdb.fi Git - libs/gl.git/commitdiff
Align uniform blocks properly
authorMikko Rasa <tdb@tdb.fi>
Sun, 26 Aug 2012 12:06:15 +0000 (15:06 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 26 Aug 2012 12:39:31 +0000 (15:39 +0300)
source/buffer.cpp
source/buffer.h
source/bufferable.cpp
source/bufferable.h
source/uniformblock.cpp
source/uniformblock.h

index f09268741fc7705e69432c6ee18e5f03edb069ec..f3b40da6ab469623f8d7e2a27a65a6964da657c1 100644 (file)
@@ -176,5 +176,11 @@ unsigned BufferRange::get_n_uniform_buffer_bindings()
        return count;
 }
 
+unsigned BufferRange::get_uniform_buffer_alignment()
+{
+       static unsigned align = get_i(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT);
+       return align;
+}
+
 } // namespace GL
 } // namespace Msp
index 6f0a9708e18069485460587d3295b63aaf6055b1..206cec8d0d2c580aef949b94acb4539c57a21a11 100644 (file)
@@ -135,6 +135,7 @@ private:
 
 public:
        static unsigned get_n_uniform_buffer_bindings();
+       static unsigned get_uniform_buffer_alignment();
 };
 
 } // namespace GL
index 12e0aef7d345da45e948820606211926c1de9b49..abd10b3a865baa44bbc078c0745b65cb5682fba6 100644 (file)
@@ -58,6 +58,9 @@ void Bufferable::update_buffer_offset()
        if(prev_in_buffer)
                offset = prev_in_buffer->buffer_offset+prev_in_buffer->get_data_size();
 
+       unsigned align = get_alignment();
+       offset += align-1;
+       offset -= offset%align;
        if(offset!=buffer_offset)
        {
                buffer_offset = offset;
index fa81554dd0090be867ddfc6ca905c6c68ab5d790..f5ae043cb5144b498cf08d389248f7a66f25eefa 100644 (file)
@@ -25,6 +25,7 @@ private:
 
 protected:
        virtual unsigned get_data_size() const = 0;
+       virtual unsigned get_alignment() const { return 1; }
 
        void update_buffer_offset();
        virtual void offset_changed() { }
index 6ea0d320c5b50d1f9e5cf352a0dd78871465b879..a87a6a42386ed39ee04b7368524796decd64ecfe 100644 (file)
@@ -27,6 +27,11 @@ UniformBlock::~UniformBlock()
        delete buf_range;
 }
 
+unsigned UniformBlock::get_alignment() const
+{
+       return BufferRange::get_uniform_buffer_alignment();
+}
+
 void UniformBlock::offset_changed()
 {
        delete buf_range;
index 66b3c7e0c1424b2b4fedc2bb7a15c8232881ed4a..12b24de3d06a810aa16040b49d2df973e53eba5d 100644 (file)
@@ -33,6 +33,7 @@ public:
 
 private:
        virtual unsigned get_data_size() const { return size; }
+       virtual unsigned get_alignment() const;
        virtual void offset_changed();
        virtual void upload_data() const;