From: Mikko Rasa Date: Sun, 26 Aug 2012 12:06:15 +0000 (+0300) Subject: Align uniform blocks properly X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c21d4de686e7abd51b0a779af00f06ce459e18d6;p=libs%2Fgl.git Align uniform blocks properly --- diff --git a/source/buffer.cpp b/source/buffer.cpp index f0926874..f3b40da6 100644 --- a/source/buffer.cpp +++ b/source/buffer.cpp @@ -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 diff --git a/source/buffer.h b/source/buffer.h index 6f0a9708..206cec8d 100644 --- a/source/buffer.h +++ b/source/buffer.h @@ -135,6 +135,7 @@ private: public: static unsigned get_n_uniform_buffer_bindings(); + static unsigned get_uniform_buffer_alignment(); }; } // namespace GL diff --git a/source/bufferable.cpp b/source/bufferable.cpp index 12e0aef7..abd10b3a 100644 --- a/source/bufferable.cpp +++ b/source/bufferable.cpp @@ -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; diff --git a/source/bufferable.h b/source/bufferable.h index fa81554d..f5ae043c 100644 --- a/source/bufferable.h +++ b/source/bufferable.h @@ -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() { } diff --git a/source/uniformblock.cpp b/source/uniformblock.cpp index 6ea0d320..a87a6a42 100644 --- a/source/uniformblock.cpp +++ b/source/uniformblock.cpp @@ -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; diff --git a/source/uniformblock.h b/source/uniformblock.h index 66b3c7e0..12b24de3 100644 --- a/source/uniformblock.h +++ b/source/uniformblock.h @@ -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;