From 49d0393775d49db58f48cad6953d5cb8cd225431 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 30 Mar 2026 00:50:50 +0100 Subject: Use uint32_t for indexes in InstanceVertices Passable to GLSL and more than big enough --- gfx/gl/instanceVertices.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h index d984938..e31fa83 100644 --- a/gfx/gl/instanceVertices.h +++ b/gfx/gl/instanceVertices.h @@ -9,11 +9,12 @@ template class InstanceVertices : protected glVector { using base = glVector; + using IndexT = uint32_t; public: class [[nodiscard]] InstanceProxy { public: - InstanceProxy(InstanceVertices * iv, std::size_t idx) : instances {iv}, index {idx} { } + InstanceProxy(InstanceVertices * iv, IndexT idx) : instances {iv}, index {idx} { } InstanceProxy(InstanceProxy && other) noexcept : instances {std::exchange(other.instances, nullptr)}, index {other.index} @@ -98,9 +99,9 @@ public: return instances->lookup(index); } - private: + // private: InstanceVertices * instances; - std::size_t index; + IndexT index; }; template @@ -110,15 +111,15 @@ public: if (!unused.empty()) { auto idx = unused.back(); unused.pop_back(); - index[idx] = base::size(); + index[idx] = static_cast(base::size()); reverseIndex.emplace_back(idx); base::emplace_back(std::forward(params)...); return InstanceProxy {this, idx}; } - index.emplace_back(base::size()); - reverseIndex.push_back(base::size()); + index.emplace_back(static_cast(base::size())); + reverseIndex.push_back(static_cast(base::size())); base::emplace_back(std::forward(params)...); - return InstanceProxy {this, index.size() - 1}; + return InstanceProxy {this, static_cast(index.size() - 1)}; } [[nodiscard]] GLuint @@ -176,7 +177,7 @@ public: } protected: - static constexpr auto npos = static_cast(-1); + static constexpr auto npos = static_cast(-1); friend InstanceProxy; base::size_type @@ -186,9 +187,9 @@ protected: } void - release(const size_t pidx) + release(const IndexT pidx) { - if (const size_t last = base::size() - 1; last != index[pidx]) { + if (const auto last = static_cast(base::size() - 1); last != index[pidx]) { lookup(pidx) = std::move(base::back()); const auto movedKey = reverseIndex[last]; index[movedKey] = std::exchange(index[pidx], npos); @@ -207,7 +208,7 @@ protected: } [[nodiscard]] T & - lookup(size_t pindex) + lookup(IndexT pindex) { return base::data()[index[pindex]]; } @@ -231,8 +232,8 @@ protected: } // Index into buffer given to nth proxy - std::vector index; - std::vector reverseIndex; + std::vector index; + std::vector reverseIndex; // List of free spaces in index - std::vector unused; + std::vector unused; }; -- cgit v1.3