diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-13 15:09:38 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-13 15:09:38 +0000 |
commit | 3529eba77e2e5af672369e73d73c1084616c10e9 (patch) | |
tree | eda097c081a6c15945f5a681afbc39bba1f33741 /lib/glContainer.h | |
parent | Use std::span for iterator/data pointer in glContainer (diff) | |
download | ilt-3529eba77e2e5af672369e73d73c1084616c10e9.tar.bz2 ilt-3529eba77e2e5af672369e73d73c1084616c10e9.tar.xz ilt-3529eba77e2e5af672369e73d73c1084616c10e9.zip |
Add glContainer::at override to update a single item
Diffstat (limited to 'lib/glContainer.h')
-rw-r--r-- | lib/glContainer.h | 16 |
1 files changed, 16 insertions, 0 deletions
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<GLintptr>(pos * sizeof(T)), sizeof(value), &value); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + } + [[nodiscard]] reference_type at(size_type pos) { |