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
This commit is contained in:
cutealien 2022-04-20 11:03:23 +00:00
parent 57bcc52ca1
commit 8cd7e46506
2 changed files with 15 additions and 4 deletions

@ -26,6 +26,7 @@ namespace scene
virtual void push_back (const video::S3DVertex &element) =0; virtual void push_back (const video::S3DVertex &element) =0;
virtual void setValue(u32 index, const video::S3DVertex &value) =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& operator [](const u32 index) const =0;
virtual video::S3DVertex& getLast() =0; virtual video::S3DVertex& getLast() =0;
virtual void set_used(u32 usedNow) =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 virtual void setValue(u32 index, const video::S3DVertex &value) IRR_OVERRIDE
{Vertices[index] = (T&)value;} {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 virtual video::S3DVertex& operator [](const u32 index) const IRR_OVERRIDE
{return (video::S3DVertex&)Vertices[index];} {return (video::S3DVertex&)Vertices[index];}
@ -158,6 +162,11 @@ namespace scene
Vertices->setValue(index, value); 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 virtual video::S3DVertex& operator [](const u32 index) const IRR_OVERRIDE
{ {
return (*Vertices)[index]; return (*Vertices)[index];

@ -37,12 +37,14 @@ namespace scene
//* Note that depending on vertex type reference has to be one of the types derived from video::S3DVertex. */ //* 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; virtual void push_back(const video::S3DVertex &element) =0;
//! Set value at index. //! 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. /** 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 [] */
virtual void setValue(u32 index, const video::S3DVertex &value) =0; 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& operator [](const u32 index) const =0;
virtual video::S3DVertex& getLast() =0; virtual video::S3DVertex& getLast() =0;