From b59c47a7ed2ed3f69a3349a2d76ef02891f0c685 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 17 Jun 2019 23:29:59 +0300 Subject: [PATCH] Make a const pointer to a Bufferable's buffer publicly accessible --- source/batch.cpp | 2 +- source/bufferable.h | 6 +++++- source/uniformblock.cpp | 2 +- source/vertexarray.cpp | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/batch.cpp b/source/batch.cpp index 89b8f48f..37e4801e 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -242,7 +242,7 @@ void Batch::draw() const else if(restart_index && restart_index<=max_index) set_restart_index(0); - Buffer *ibuf = get_buffer(); + const Buffer *ibuf = get_buffer(); const void *data_ptr; BindRestore _bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER); if(ibuf) diff --git a/source/bufferable.h b/source/bufferable.h index a88f7b07..66a6db18 100644 --- a/source/bufferable.h +++ b/source/bufferable.h @@ -53,9 +53,13 @@ public: private: void unlink_from_buffer(); +public: + /** Returns the buffer in which the data is stored. */ + const Buffer *get_buffer() const { return buffer; } + protected: /** Returns the buffer in which the data is stored. */ - Buffer *get_buffer() const { return buffer; } + Buffer *get_mutable_buffer() const { return buffer; } /** Returns the amount of data to be stored in the buffer, in bytes. */ virtual unsigned get_data_size() const = 0; diff --git a/source/uniformblock.cpp b/source/uniformblock.cpp index be30ce5b..ff8033a0 100644 --- a/source/uniformblock.cpp +++ b/source/uniformblock.cpp @@ -51,7 +51,7 @@ void UniformBlock::offset_changed() void UniformBlock::upload_data(char *target) const { if(!buf_range) - buf_range = new BufferRange(*get_buffer(), get_offset(), size); + buf_range = new BufferRange(*get_mutable_buffer(), get_offset(), size); if(target) copy(data.begin(), data.end(), target); diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 0ebd4f0f..a4dffbb7 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -135,7 +135,7 @@ void VertexArray::apply(bool use_legacy) const if(!set_current(this) && !dirty) return; - Buffer *vbuf = get_buffer(); + const Buffer *vbuf = get_buffer(); Bind _bind_vbuf(vbuf, ARRAY_BUFFER); if(vbuf && dirty) update_buffer(); -- 2.45.2