From 97818e67b2543a6075c13e6bf22c296757b975e5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 19 Dec 2021 00:16:10 +0200 Subject: [PATCH] Use a member function to set the dirty flag in Bufferable --- source/core/batch.cpp | 8 ++++---- source/core/bufferable.cpp | 15 ++++++++++----- source/core/bufferable.h | 10 ++++++---- source/core/uniformblock.cpp | 2 +- source/core/vertexarray.cpp | 4 ++-- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/source/core/batch.cpp b/source/core/batch.cpp index 4fb2720d..c68beab9 100644 --- a/source/core/batch.cpp +++ b/source/core/batch.cpp @@ -70,7 +70,7 @@ void Batch::set_index_type(DataType t) index_type = t; BatchBackend::set_index_type(t); update_offset(); - dirty = true; + mark_dirty(); } Batch &Batch::append(unsigned i) @@ -78,7 +78,7 @@ Batch &Batch::append(unsigned i) append_index(i); update_offset(); - dirty = true; + mark_dirty(); return *this; } @@ -93,7 +93,7 @@ Batch &Batch::append(const vector &ind) append_index(i); update_offset(); - dirty = true; + mark_dirty(); return *this; } @@ -142,7 +142,7 @@ Batch &Batch::append(const Batch &other) append_index(other.get_index(i)); update_offset(); - dirty = true; + mark_dirty(); return *this; } diff --git a/source/core/bufferable.cpp b/source/core/bufferable.cpp index 374c4eeb..fcedc5be 100644 --- a/source/core/bufferable.cpp +++ b/source/core/bufferable.cpp @@ -50,7 +50,7 @@ void Bufferable::use_buffer(Buffer *buf, Bufferable *prev) } location_dirty = true; - dirty = true; + mark_dirty(); update_offset(); } @@ -60,13 +60,13 @@ void Bufferable::change_buffer(Buffer *buf) { b->buffer = buf; b->location_dirty = true; - b->dirty = true; + b->mark_dirty(); } for(Bufferable *b=prev_in_buffer; b; b=b->prev_in_buffer) { b->buffer = buf; b->location_dirty = true; - b->dirty = true; + b->mark_dirty(); } } @@ -105,7 +105,7 @@ void Bufferable::update_offset() { offset = new_offset; location_dirty = true; - dirty = true; + mark_dirty(); } if(next_in_buffer) @@ -113,10 +113,15 @@ void Bufferable::update_offset() else if(buffer && offset+get_data_size()>buffer->get_size()) { location_dirty = true; - dirty = true; + mark_dirty(); } } +void Bufferable::mark_dirty() +{ + dirty = true; +} + void Bufferable::upload_data(char *target) const { if(!buffer) diff --git a/source/core/bufferable.h b/source/core/bufferable.h index 53d493a0..b430b726 100644 --- a/source/core/bufferable.h +++ b/source/core/bufferable.h @@ -12,9 +12,7 @@ class Buffer; Base class for things that can store data in buffers. Multiple Bufferables may be put in the same buffer. -A dirty flag is provided for derived classes. It should be set when the data -in the buffer is considered out of date, and is cleared by Bufferable after -uploading fresh data to the buffer. +Derived classes should call mark_dirty() when the stored data has changed. */ class Bufferable: public NonCopyable { @@ -43,9 +41,9 @@ private: Bufferable *next_in_buffer = 0; Bufferable *prev_in_buffer = 0; mutable bool location_dirty = false; -protected: mutable bool dirty = false; +protected: Bufferable() = default; Bufferable(Bufferable &&); public: @@ -94,6 +92,10 @@ protected: changes. */ void update_offset(); + /* Indicates that the data of the bufferable has changed and should be + uploaded to the buffer again. */ + void mark_dirty(); + public: /** Returns the offset of the data from the beginning of the buffer. */ std::size_t get_offset() const { return offset; } diff --git a/source/core/uniformblock.cpp b/source/core/uniformblock.cpp index ebaed2a6..952fd2fd 100644 --- a/source/core/uniformblock.cpp +++ b/source/core/uniformblock.cpp @@ -79,7 +79,7 @@ void UniformBlock::store(const ReflectData::UniformInfo &info, size_t array_size } } - dirty = true; + mark_dirty(); } void UniformBlock::check_store_range(size_t offs, size_t size) diff --git a/source/core/vertexarray.cpp b/source/core/vertexarray.cpp index db88e13c..beffa64e 100644 --- a/source/core/vertexarray.cpp +++ b/source/core/vertexarray.cpp @@ -37,7 +37,7 @@ char *VertexArray::append() throw invalid_operation("VertexArray::append"); data.insert(data.end(), stride, 0.0f); update_offset(); - dirty = true; + mark_dirty(); return &*(data.end()-stride); } @@ -45,7 +45,7 @@ char *VertexArray::modify(size_t i) { if(format.empty()) throw invalid_operation("VertexArray::modify"); - dirty = true; + mark_dirty(); return &data[0]+i*stride; } -- 2.45.2