From 3529eba77e2e5af672369e73d73c1084616c10e9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 13 Jan 2024 15:09:38 +0000 Subject: Add glContainer::at override to update a single item --- lib/glContainer.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') diff --git a/lib/glContainer.h b/lib/glContainer.h index e5f53e2..ce88916 100644 --- a/lib/glContainer.h +++ b/lib/glContainer.h @@ -136,6 +136,22 @@ public: return size_; } + void + at(size_type pos, const T & value) + { + if (pos >= size()) { + throw std::out_of_range {__FUNCTION__}; + } + if (data_.data()) { + data_[pos] = value; + } + else { + glBindBuffer(GL_ARRAY_BUFFER, buffer_); + glBufferSubData(GL_ARRAY_BUFFER, static_cast(pos * sizeof(T)), sizeof(value), &value); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + } + [[nodiscard]] reference_type at(size_type pos) { -- cgit v1.2.3