diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 13:17:05 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 13:17:05 +0100 |
commit | bcd0e98739974248e6d29f72e8b281e21fd59657 (patch) | |
tree | 5330fdad5736032034d57592c59819dad26d239e | |
parent | Streamline the instancing maintenance (diff) | |
download | ilt-bcd0e98739974248e6d29f72e8b281e21fd59657.tar.bz2 ilt-bcd0e98739974248e6d29f72e8b281e21fd59657.tar.xz ilt-bcd0e98739974248e6d29f72e8b281e21fd59657.zip |
Test instancing automatic unmap when count is called, add some nodiscard
-rw-r--r-- | gfx/gl/instanceVertices.h | 27 | ||||
-rw-r--r-- | test/test-instancing.cpp | 19 |
2 files changed, 31 insertions, 15 deletions
diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h index cf4f0ae..edcaef4 100644 --- a/gfx/gl/instanceVertices.h +++ b/gfx/gl/instanceVertices.h @@ -14,7 +14,7 @@ public: allocBuffer(initialSize); } - class InstanceProxy { + class [[nodiscard]] InstanceProxy { public: InstanceProxy(InstanceVertices * iv, std::size_t idx) : instances {iv}, index {idx} { } InstanceProxy(InstanceProxy && other) : instances {std::exchange(other.instances, nullptr)}, index {other.index} @@ -46,41 +46,41 @@ public: return instances->at(index) = std::forward<U>(v); } + [[nodiscard]] operator T &() { return instances->at(index); } - operator const T &() const + [[nodiscard]] operator const T &() const { return instances->at(index); } - - T * + [[nodiscard]] T * get() { return &instances->at(index); } - const T * + [[nodiscard]] const T * get() const { return &instances->at(index); } - T * + [[nodiscard]] T * operator->() { return get(); } - const T * + [[nodiscard]] const T * operator->() const { return get(); } - T & + [[nodiscard]] T & operator*() { return instances->at(index); } - const T & + [[nodiscard]] const T & operator*() const { return instances->at(index); @@ -92,7 +92,7 @@ public: }; template<typename... Params> - InstanceProxy + [[nodiscard]] InstanceProxy acquire(Params &&... params) { map(); @@ -111,14 +111,13 @@ public: return InstanceProxy {this, index.size() - 1}; } - const auto & + [[nodiscard]] const auto & bufferName() const { - unmap(); return buffer; } - auto + [[nodiscard]] auto count() const { unmap(); @@ -173,7 +172,7 @@ protected: capacity = newCapacity; } - T & + [[nodiscard]] T & at(size_t pindex) { map(); diff --git a/test/test-instancing.cpp b/test/test-instancing.cpp index 8837071..70b20fa 100644 --- a/test/test-instancing.cpp +++ b/test/test-instancing.cpp @@ -50,8 +50,9 @@ BOOST_AUTO_TEST_CASE(acquireReleaseMove) *proxy1 = 20; BOOST_CHECK_EQUAL(1, next); auto proxy2 = std::move(proxy1); - *proxy2 = 40; + proxy2 = 40; BOOST_CHECK_EQUAL(1, next); + BOOST_CHECK_EQUAL(data[0], 40); } BOOST_CHECK_EQUAL(0, next); BOOST_CHECK_EQUAL(1, unused.size()); @@ -59,10 +60,26 @@ BOOST_AUTO_TEST_CASE(acquireReleaseMove) BOOST_CHECK_EQUAL(1, index.size()); } +BOOST_AUTO_TEST_CASE(autoMapUnmap) +{ + { + auto proxy = acquire(); + BOOST_CHECK(data); + std::ignore = bufferName(); + BOOST_CHECK(data); + BOOST_CHECK_EQUAL(1, count()); + BOOST_CHECK(!data); + } + BOOST_CHECK_EQUAL(0, count()); +} + BOOST_AUTO_TEST_CASE(initialize) { auto proxy = acquire(5); + const auto & constProxy = proxy; BOOST_CHECK_EQUAL(*proxy, 5); + BOOST_CHECK_EQUAL(*constProxy, 5); + BOOST_CHECK_EQUAL(constProxy.get(), constProxy.get()); } BOOST_AUTO_TEST_CASE(resize) |