From 8cd7e4650688c96bec57298bca4ea94eea809e7b Mon Sep 17 00:00:00 2001 From: cutealien Date: Wed, 20 Apr 2022 11:03:23 +0000 Subject: [PATCH] Add non-const version of IVertexBuffer::operator[] Yeah, setValue is not enough and if getLast() works then this should work as well (when users are very careful...) git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6345 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/CVertexBuffer.h | 9 +++++++++ include/IVertexBuffer.h | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/CVertexBuffer.h b/include/CVertexBuffer.h index 40a4d03..cf569e6 100644 --- a/include/CVertexBuffer.h +++ b/include/CVertexBuffer.h @@ -26,6 +26,7 @@ namespace scene virtual void push_back (const video::S3DVertex &element) =0; virtual void setValue(u32 index, const video::S3DVertex &value) =0; + virtual video::S3DVertex& operator [](u32 index) = 0; virtual video::S3DVertex& operator [](const u32 index) const =0; virtual video::S3DVertex& getLast() =0; virtual void set_used(u32 usedNow) =0; @@ -51,6 +52,9 @@ namespace scene virtual void setValue(u32 index, const video::S3DVertex &value) IRR_OVERRIDE {Vertices[index] = (T&)value;} + virtual video::S3DVertex& operator [](u32 index) IRR_OVERRIDE + {return (video::S3DVertex&)Vertices[index];} + virtual video::S3DVertex& operator [](const u32 index) const IRR_OVERRIDE {return (video::S3DVertex&)Vertices[index];} @@ -158,6 +162,11 @@ namespace scene Vertices->setValue(index, value); } + virtual video::S3DVertex& operator [](u32 index) IRR_OVERRIDE + { + return (*Vertices)[index]; + } + virtual video::S3DVertex& operator [](const u32 index) const IRR_OVERRIDE { return (*Vertices)[index]; diff --git a/include/IVertexBuffer.h b/include/IVertexBuffer.h index 0fc3b23..e201a5b 100644 --- a/include/IVertexBuffer.h +++ b/include/IVertexBuffer.h @@ -37,12 +37,14 @@ namespace scene //* Note that depending on vertex type reference has to be one of the types derived from video::S3DVertex. */ virtual void push_back(const video::S3DVertex &element) =0; - //! Set value at index. - /** Depending on vertex type reference has to be one of the types derived from video::S3DVertex. - Buffer must be already large enough. This is basically the non const version of operator [] */ + //! Set value at index. Buffer must be already large enough that element exists. + /** Depending on vertex type reference has to be one of the types derived from video::S3DVertex */ virtual void setValue(u32 index, const video::S3DVertex &value) =0; - // Note that the reference can also be to one of the derived types + // Note that the reference can also be to one of the types derived from video::S3DVertex. + // This is especially important for the non const access version - you need to have the correct type and do some casting + // if you write vertices. + virtual video::S3DVertex& operator [](u32 index) = 0; virtual video::S3DVertex& operator [](const u32 index) const =0; virtual video::S3DVertex& getLast() =0;