]> git.tdb.fi Git - libs/gl.git/commitdiff
Use a member function to set the dirty flag in Bufferable
authorMikko Rasa <tdb@tdb.fi>
Sat, 18 Dec 2021 22:16:10 +0000 (00:16 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 Dec 2021 10:29:50 +0000 (12:29 +0200)
source/core/batch.cpp
source/core/bufferable.cpp
source/core/bufferable.h
source/core/uniformblock.cpp
source/core/vertexarray.cpp

index 4fb2720df4cb9f2dcc27fa05de4f7bdc9fdd9597..c68beab908f8dc2a07c699a8b7bd6a9e41b5f35c 100644 (file)
@@ -70,7 +70,7 @@ void Batch::set_index_type(DataType t)
        index_type = t;
        BatchBackend::set_index_type(t);
        update_offset();
        index_type = t;
        BatchBackend::set_index_type(t);
        update_offset();
-       dirty = true;
+       mark_dirty();
 }
 
 Batch &Batch::append(unsigned i)
 }
 
 Batch &Batch::append(unsigned i)
@@ -78,7 +78,7 @@ Batch &Batch::append(unsigned i)
        append_index(i);
 
        update_offset();
        append_index(i);
 
        update_offset();
-       dirty = true;
+       mark_dirty();
 
        return *this;
 }
 
        return *this;
 }
@@ -93,7 +93,7 @@ Batch &Batch::append(const vector<unsigned> &ind)
                append_index(i);
 
        update_offset();
                append_index(i);
 
        update_offset();
-       dirty = true;
+       mark_dirty();
 
        return *this;
 }
 
        return *this;
 }
@@ -142,7 +142,7 @@ Batch &Batch::append(const Batch &other)
                append_index(other.get_index(i));
 
        update_offset();
                append_index(other.get_index(i));
 
        update_offset();
-       dirty = true;
+       mark_dirty();
 
        return *this;
 }
 
        return *this;
 }
index 374c4eeb3b83ee5d1617b9249383696a9f7aa15f..fcedc5becd666efb16ef780a73c4bc8fa24fe5c5 100644 (file)
@@ -50,7 +50,7 @@ void Bufferable::use_buffer(Buffer *buf, Bufferable *prev)
        }
 
        location_dirty = true;
        }
 
        location_dirty = true;
-       dirty = true;
+       mark_dirty();
        update_offset();
 }
 
        update_offset();
 }
 
@@ -60,13 +60,13 @@ void Bufferable::change_buffer(Buffer *buf)
        {
                b->buffer = buf;
                b->location_dirty = true;
        {
                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;
        }
        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;
        {
                offset = new_offset;
                location_dirty = true;
-               dirty = true;
+               mark_dirty();
        }
 
        if(next_in_buffer)
        }
 
        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;
        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)
 void Bufferable::upload_data(char *target) const
 {
        if(!buffer)
index 53d493a0713d75a7205ede2ecfd04135902c7e15..b430b726277c657fac569fb334bf5c69f624409e 100644 (file)
@@ -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.
 
 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
 {
 */
 class Bufferable: public NonCopyable
 {
@@ -43,9 +41,9 @@ private:
        Bufferable *next_in_buffer = 0;
        Bufferable *prev_in_buffer = 0;
        mutable bool location_dirty = false;
        Bufferable *next_in_buffer = 0;
        Bufferable *prev_in_buffer = 0;
        mutable bool location_dirty = false;
-protected:
        mutable bool dirty = false;
 
        mutable bool dirty = false;
 
+protected:
        Bufferable() = default;
        Bufferable(Bufferable &&);
 public:
        Bufferable() = default;
        Bufferable(Bufferable &&);
 public:
@@ -94,6 +92,10 @@ protected:
        changes. */
        void update_offset();
 
        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; }
 public:
        /** Returns the offset of the data from the beginning of the buffer. */
        std::size_t get_offset() const { return offset; }
index ebaed2a6872d6067d19113fc0f9e51436bbf1045..952fd2fde0f736bfab861938a0682a411d1e5389 100644 (file)
@@ -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)
 }
 
 void UniformBlock::check_store_range(size_t offs, size_t size)
index db88e13cd013176defba7b8663a035e783d7de17..beffa64e0873fa66ee3d8f4228a76922abf1355c 100644 (file)
@@ -37,7 +37,7 @@ char *VertexArray::append()
                throw invalid_operation("VertexArray::append");
        data.insert(data.end(), stride, 0.0f);
        update_offset();
                throw invalid_operation("VertexArray::append");
        data.insert(data.end(), stride, 0.0f);
        update_offset();
-       dirty = true;
+       mark_dirty();
        return &*(data.end()-stride);
 }
 
        return &*(data.end()-stride);
 }
 
@@ -45,7 +45,7 @@ char *VertexArray::modify(size_t i)
 {
        if(format.empty())
                throw invalid_operation("VertexArray::modify");
 {
        if(format.empty())
                throw invalid_operation("VertexArray::modify");
-       dirty = true;
+       mark_dirty();
        return &data[0]+i*stride;
 }
 
        return &data[0]+i*stride;
 }