From be9aa19208a46ee3dccdad9890aed69656079489 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 28 Aug 2024 18:08:59 +0200 Subject: [PATCH] Propagate changes to IMeshBuffer parent class --- irr/include/CMeshBuffer.h | 132 ++--------------------- irr/include/IMeshBuffer.h | 198 ++++++++++++++++++++++++---------- irr/include/SSkinMeshBuffer.h | 139 ++---------------------- 3 files changed, 163 insertions(+), 306 deletions(-) diff --git a/irr/include/CMeshBuffer.h b/irr/include/CMeshBuffer.h index 0b47494cd..6b13a8982 100644 --- a/irr/include/CMeshBuffer.h +++ b/irr/include/CMeshBuffer.h @@ -49,25 +49,24 @@ public: return Material; } - //! Get pointer to vertices - /** \return Pointer to vertices. */ - const void *getVertices() const override + const scene::IVertexBuffer *getVertexBuffer() const override { - return Vertices->getData(); + return Vertices; } - //! Get pointer to vertices - /** \return Pointer to vertices. */ - void *getVertices() override + scene::IVertexBuffer *getVertexBuffer() override { - return Vertices->getData(); + return Vertices; } - //! Get number of vertices - /** \return Number of vertices. */ - u32 getVertexCount() const override + const scene::IIndexBuffer *getIndexBuffer() const override { - return Vertices->getCount(); + return Indices; + } + + scene::IIndexBuffer *getIndexBuffer() override + { + return Indices; } // TEMPORARY helper for direct buffer acess @@ -76,34 +75,6 @@ public: return Vertices->Data; } - //! Get type of index data which is stored in this meshbuffer. - /** \return Index type of this buffer. */ - video::E_INDEX_TYPE getIndexType() const override - { - return Indices->getType(); - } - - //! Get pointer to indices - /** \return Pointer to indices. */ - const u16 *getIndices() const override - { - return static_cast(Indices->getData()); - } - - //! Get pointer to indices - /** \return Pointer to indices. */ - u16 *getIndices() override - { - return static_cast(Indices->getData()); - } - - //! Get number of indices - /** \return Number of indices. */ - u32 getIndexCount() const override - { - return Indices->getCount(); - } - // TEMPORARY helper for direct buffer acess inline auto &IndexBuffer() { @@ -138,49 +109,6 @@ public: BoundingBox.reset(0, 0, 0); } - //! Get type of vertex data stored in this buffer. - /** \return Type of vertex data. */ - video::E_VERTEX_TYPE getVertexType() const override - { - return Vertices->getType(); - } - - //! returns position of vertex i - const core::vector3df &getPosition(u32 i) const override - { - return Vertices->getPosition(i); - } - - //! returns position of vertex i - core::vector3df &getPosition(u32 i) override - { - return Vertices->getPosition(i); - } - - //! returns normal of vertex i - const core::vector3df &getNormal(u32 i) const override - { - return Vertices->getNormal(i); - } - - //! returns normal of vertex i - core::vector3df &getNormal(u32 i) override - { - return Vertices->getNormal(i); - } - - //! returns texture coord of vertex i - const core::vector2df &getTCoords(u32 i) const override - { - return Vertices->getTCoords(i); - } - - //! returns texture coord of vertex i - core::vector2df &getTCoords(u32 i) override - { - return Vertices->getTCoords(i); - } - //! Append the vertices and indices to the current buffer void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) override { @@ -202,27 +130,6 @@ public: } } - //! get the current hardware mapping hint - E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override - { - return Vertices->getHardwareMappingHint(); - } - - //! get the current hardware mapping hint - E_HARDWARE_MAPPING getHardwareMappingHint_Index() const override - { - return Indices->getHardwareMappingHint(); - } - - //! set the hardware mapping hint, for driver - void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer = EBT_VERTEX_AND_INDEX) override - { - if (Buffer == EBT_VERTEX_AND_INDEX || Buffer == EBT_VERTEX) - Vertices->setHardwareMappingHint(NewMappingHint); - if (Buffer == EBT_VERTEX_AND_INDEX || Buffer == EBT_INDEX) - Indices->setHardwareMappingHint(NewMappingHint); - } - //! Describe what kind of primitive geometry is used by the meshbuffer void setPrimitiveType(E_PRIMITIVE_TYPE type) override { @@ -235,23 +142,6 @@ public: return PrimitiveType; } - //! flags the mesh as changed, reloads hardware buffers - void setDirty(E_BUFFER_TYPE Buffer = EBT_VERTEX_AND_INDEX) override - { - if (Buffer == EBT_VERTEX_AND_INDEX || Buffer == EBT_VERTEX) - Vertices->setDirty(); - if (Buffer == EBT_VERTEX_AND_INDEX || Buffer == EBT_INDEX) - Indices->setDirty(); - } - - //! Get the currently used ID for identification of changes. - /** This shouldn't be used for anything outside the VideoDriver. */ - u32 getChangedID_Vertex() const override { return Vertices->getChangedID(); } - - //! Get the currently used ID for identification of changes. - /** This shouldn't be used for anything outside the VideoDriver. */ - u32 getChangedID_Index() const override { return Indices->getChangedID(); } - void setHWBuffer(void *ptr) const override { HWBuffer = ptr; diff --git a/irr/include/IMeshBuffer.h b/irr/include/IMeshBuffer.h index c69a12d1d..8a43db87e 100644 --- a/irr/include/IMeshBuffer.h +++ b/irr/include/IMeshBuffer.h @@ -7,8 +7,8 @@ #include "IReferenceCounted.h" #include "SMaterial.h" #include "aabbox3d.h" -#include "S3DVertex.h" -#include "SVertexIndex.h" +#include "IVertexBuffer.h" +#include "IIndexBuffer.h" #include "EHardwareBufferFlags.h" #include "EPrimitiveTypes.h" @@ -46,39 +46,17 @@ public: /** \return Material of this buffer. */ virtual const video::SMaterial &getMaterial() const = 0; - //! Get type of vertex data which is stored in this meshbuffer. - /** \return Vertex type of this buffer. */ - virtual video::E_VERTEX_TYPE getVertexType() const = 0; + /// Get the vertex buffer + virtual const scene::IVertexBuffer *getVertexBuffer() const = 0; - //! Get access to vertex data. The data is an array of vertices. - /** Which vertex type is used can be determined by getVertexType(). - \return Pointer to array of vertices. */ - virtual const void *getVertices() const = 0; + /// Get the vertex buffer + virtual scene::IVertexBuffer *getVertexBuffer() = 0; - //! Get access to vertex data. The data is an array of vertices. - /** Which vertex type is used can be determined by getVertexType(). - \return Pointer to array of vertices. */ - virtual void *getVertices() = 0; + /// Get the index buffer + virtual const scene::IIndexBuffer *getIndexBuffer() const = 0; - //! Get amount of vertices in meshbuffer. - /** \return Number of vertices in this buffer. */ - virtual u32 getVertexCount() const = 0; - - //! Get type of index data which is stored in this meshbuffer. - /** \return Index type of this buffer. */ - virtual video::E_INDEX_TYPE getIndexType() const = 0; - - //! Get access to indices. - /** \return Pointer to indices array. */ - virtual const u16 *getIndices() const = 0; - - //! Get access to indices. - /** \return Pointer to indices array. */ - virtual u16 *getIndices() = 0; - - //! Get amount of indices in this meshbuffer. - /** \return Number of indices in this buffer. */ - virtual u32 getIndexCount() const = 0; + /// Get the index buffer + virtual scene::IIndexBuffer *getIndexBuffer() = 0; //! Get the axis aligned bounding box of this meshbuffer. /** \return Axis aligned bounding box of this buffer. */ @@ -92,24 +70,6 @@ public: //! Recalculates the bounding box. Should be called if the mesh changed. virtual void recalculateBoundingBox() = 0; - //! returns position of vertex i - virtual const core::vector3df &getPosition(u32 i) const = 0; - - //! returns position of vertex i - virtual core::vector3df &getPosition(u32 i) = 0; - - //! returns normal of vertex i - virtual const core::vector3df &getNormal(u32 i) const = 0; - - //! returns normal of vertex i - virtual core::vector3df &getNormal(u32 i) = 0; - - //! returns texture coord of vertex i - virtual const core::vector2df &getTCoords(u32 i) const = 0; - - //! returns texture coord of vertex i - virtual core::vector2df &getTCoords(u32 i) = 0; - //! Append the vertices and indices to the current buffer /** Only works for compatible vertex types. \param vertices Pointer to a vertex array. @@ -118,25 +78,149 @@ public: \param numIndices Number of indices in array. */ virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) = 0; - //! get the current hardware mapping hint - virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const = 0; + /* Leftover functions that are now just helpers for accessing the respective buffer. */ + + //! Get type of vertex data which is stored in this meshbuffer. + /** \return Vertex type of this buffer. */ + inline video::E_VERTEX_TYPE getVertexType() const + { + return getVertexBuffer()->getType(); + } + + //! Get access to vertex data. The data is an array of vertices. + /** Which vertex type is used can be determined by getVertexType(). + \return Pointer to array of vertices. */ + inline const void *getVertices() const + { + return getVertexBuffer()->getData(); + } + + //! Get access to vertex data. The data is an array of vertices. + /** Which vertex type is used can be determined by getVertexType(). + \return Pointer to array of vertices. */ + inline void *getVertices() + { + return getVertexBuffer()->getData(); + } + + //! Get amount of vertices in meshbuffer. + /** \return Number of vertices in this buffer. */ + inline u32 getVertexCount() const + { + return getVertexBuffer()->getCount(); + } + + //! Get type of index data which is stored in this meshbuffer. + /** \return Index type of this buffer. */ + inline video::E_INDEX_TYPE getIndexType() const + { + return getIndexBuffer()->getType(); + } + + //! Get access to indices. + /** \return Pointer to indices array. */ + inline const u16 *getIndices() const + { + _IRR_DEBUG_BREAK_IF(getIndexBuffer()->getType() != video::EIT_16BIT); + return static_cast(getIndexBuffer()->getData()); + } + + //! Get access to indices. + /** \return Pointer to indices array. */ + inline u16 *getIndices() + { + _IRR_DEBUG_BREAK_IF(getIndexBuffer()->getType() != video::EIT_16BIT); + return static_cast(getIndexBuffer()->getData()); + } + + //! Get amount of indices in this meshbuffer. + /** \return Number of indices in this buffer. */ + inline u32 getIndexCount() const + { + return getIndexBuffer()->getCount(); + } + + //! returns position of vertex i + inline const core::vector3df &getPosition(u32 i) const + { + return getVertexBuffer()->getPosition(i); + } + + //! returns position of vertex i + inline core::vector3df &getPosition(u32 i) + { + return getVertexBuffer()->getPosition(i); + } + + //! returns normal of vertex i + inline const core::vector3df &getNormal(u32 i) const + { + return getVertexBuffer()->getNormal(i); + } + + //! returns normal of vertex i + inline core::vector3df &getNormal(u32 i) + { + return getVertexBuffer()->getNormal(i); + } + + //! returns texture coord of vertex i + inline const core::vector2df &getTCoords(u32 i) const + { + return getVertexBuffer()->getTCoords(i); + } + + //! returns texture coord of vertex i + inline core::vector2df &getTCoords(u32 i) + { + return getVertexBuffer()->getTCoords(i); + } //! get the current hardware mapping hint - virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const = 0; + inline E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const + { + return getVertexBuffer()->getHardwareMappingHint(); + } + + //! get the current hardware mapping hint + inline E_HARDWARE_MAPPING getHardwareMappingHint_Index() const + { + return getIndexBuffer()->getHardwareMappingHint(); + } //! set the hardware mapping hint, for driver - virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) = 0; + inline void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) + { + if (buffer == EBT_VERTEX_AND_INDEX || buffer == EBT_VERTEX) + getVertexBuffer()->setHardwareMappingHint(newMappingHint); + if (buffer == EBT_VERTEX_AND_INDEX || buffer == EBT_INDEX) + getIndexBuffer()->setHardwareMappingHint(newMappingHint); + } //! flags the meshbuffer as changed, reloads hardware buffers - virtual void setDirty(E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) = 0; + inline void setDirty(E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) + { + if (buffer == EBT_VERTEX_AND_INDEX || buffer == EBT_VERTEX) + getVertexBuffer()->setDirty(); + if (buffer == EBT_VERTEX_AND_INDEX || buffer == EBT_INDEX) + getIndexBuffer()->setDirty(); + } //! Get the currently used ID for identification of changes. /** This shouldn't be used for anything outside the VideoDriver. */ - virtual u32 getChangedID_Vertex() const = 0; + inline u32 getChangedID_Vertex() const + { + return getVertexBuffer()->getChangedID(); + } //! Get the currently used ID for identification of changes. /** This shouldn't be used for anything outside the VideoDriver. */ - virtual u32 getChangedID_Index() const = 0; + inline u32 getChangedID_Index() const + { + return getIndexBuffer()->getChangedID(); + } + + /* End helpers */ //! Used by the VideoDriver to remember the buffer link. virtual void setHWBuffer(void *ptr) const = 0; diff --git a/irr/include/SSkinMeshBuffer.h b/irr/include/SSkinMeshBuffer.h index abe077076..949551161 100644 --- a/irr/include/SSkinMeshBuffer.h +++ b/irr/include/SSkinMeshBuffer.h @@ -60,8 +60,7 @@ struct SSkinMeshBuffer : public IMeshBuffer return Material; } -protected: - const scene::IVertexBuffer *getVertexBuffer() const + const scene::IVertexBuffer *getVertexBuffer() const override { switch (VertexType) { case video::EVT_2TCOORDS: @@ -84,7 +83,16 @@ protected: return Vertices_Standard; } } -public: + + const scene::IIndexBuffer *getIndexBuffer() const override + { + return Indices; + } + + scene::IIndexBuffer *getIndexBuffer() override + { + return Indices; + } //! Get standard vertex at given index virtual video::S3DVertex *getVertex(u32 index) @@ -99,49 +107,6 @@ public: } } - //! Get pointer to vertex array - const void *getVertices() const override - { - return getVertexBuffer()->getData(); - } - - //! Get pointer to vertex array - void *getVertices() override - { - return getVertexBuffer()->getData(); - } - - //! Get vertex count - u32 getVertexCount() const override - { - return getVertexBuffer()->getCount(); - } - - //! Get type of index data which is stored in this meshbuffer. - /** \return Index type of this buffer. */ - video::E_INDEX_TYPE getIndexType() const override - { - return Indices->getType(); - } - - //! Get pointer to index array - const u16 *getIndices() const override - { - return static_cast(Indices->getData()); - } - - //! Get pointer to index array - u16 *getIndices() override - { - return static_cast(Indices->getData()); - } - - //! Get index count - u32 getIndexCount() const override - { - return Indices->getCount(); - } - //! Get bounding box const core::aabbox3d &getBoundingBox() const override { @@ -199,12 +164,6 @@ public: } } - //! Get vertex type - video::E_VERTEX_TYPE getVertexType() const override - { - return VertexType; - } - //! Convert to 2tcoords vertex type void convertTo2TCoords() { @@ -250,69 +209,12 @@ public: } } - //! returns position of vertex i - const core::vector3df &getPosition(u32 i) const override - { - return getVertexBuffer()->getPosition(i); - } - - //! returns position of vertex i - core::vector3df &getPosition(u32 i) override - { - return getVertexBuffer()->getPosition(i); - } - - //! returns normal of vertex i - const core::vector3df &getNormal(u32 i) const override - { - return getVertexBuffer()->getNormal(i); - } - - //! returns normal of vertex i - core::vector3df &getNormal(u32 i) override - { - return getVertexBuffer()->getNormal(i); - } - - //! returns texture coords of vertex i - const core::vector2df &getTCoords(u32 i) const override - { - return getVertexBuffer()->getTCoords(i); - } - - //! returns texture coords of vertex i - core::vector2df &getTCoords(u32 i) override - { - return getVertexBuffer()->getTCoords(i); - } - //! append the vertices and indices to the current buffer void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) override { _IRR_DEBUG_BREAK_IF(true); } - //! get the current hardware mapping hint for vertex buffers - E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override - { - return getVertexBuffer()->getHardwareMappingHint(); - } - - //! get the current hardware mapping hint for index buffers - E_HARDWARE_MAPPING getHardwareMappingHint_Index() const override - { - return Indices->getHardwareMappingHint(); - } - - //! set the hardware mapping hint, for driver - void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer = EBT_VERTEX_AND_INDEX) override - { - if (Buffer == EBT_VERTEX || Buffer == EBT_VERTEX_AND_INDEX) - getVertexBuffer()->setHardwareMappingHint(NewMappingHint); - if (Buffer == EBT_INDEX || Buffer == EBT_VERTEX_AND_INDEX) - Indices->setHardwareMappingHint(NewMappingHint); - } - //! Describe what kind of primitive geometry is used by the meshbuffer void setPrimitiveType(E_PRIMITIVE_TYPE type) override { @@ -325,25 +227,6 @@ public: return PrimitiveType; } - //! flags the mesh as changed, reloads hardware buffers - void setDirty(E_BUFFER_TYPE Buffer = EBT_VERTEX_AND_INDEX) override - { - if (Buffer == EBT_VERTEX_AND_INDEX || Buffer == EBT_VERTEX) - getVertexBuffer()->setDirty(); - if (Buffer == EBT_VERTEX_AND_INDEX || Buffer == EBT_INDEX) - Indices->setDirty(); - } - - u32 getChangedID_Vertex() const override - { - return getVertexBuffer()->getChangedID(); - } - - u32 getChangedID_Index() const override - { - return Indices->getChangedID(); - } - void setHWBuffer(void *ptr) const override { HWBuffer = ptr;