1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Put all pieces together and clean up leftover code

This commit is contained in:
sfan5 2024-08-28 21:46:52 +02:00
parent 6b7fc1e9fe
commit 62131fe295
11 changed files with 105 additions and 169 deletions

View file

@ -24,7 +24,7 @@ public:
#endif
}
video::E_INDEX_TYPE getType() const
video::E_INDEX_TYPE getType() const override
{
static_assert(sizeof(T) == 2 || sizeof(T) == 4, "invalid index type");
return sizeof(T) == 2 ? video::EIT_16BIT : video::EIT_32BIT;

View file

@ -20,7 +20,7 @@ class CMeshBuffer : public IMeshBuffer
public:
//! Default constructor for empty meshbuffer
CMeshBuffer() :
HWBuffer(NULL), PrimitiveType(EPT_TRIANGLES)
PrimitiveType(EPT_TRIANGLES)
{
#ifdef _DEBUG
setDebugName("CMeshBuffer");
@ -69,18 +69,6 @@ public:
return Indices;
}
// TEMPORARY helper for direct buffer acess
inline auto &VertexBuffer()
{
return Vertices->Data;
}
// TEMPORARY helper for direct buffer acess
inline auto &IndexBuffer()
{
return Indices->Data;
}
//! Get the axis aligned bounding box
/** \return Axis aligned bounding box of this buffer. */
const core::aabbox3d<f32> &getBoundingBox() const override
@ -142,18 +130,6 @@ public:
return PrimitiveType;
}
void setHWBuffer(void *ptr) const override
{
HWBuffer = ptr;
}
void *getHWBuffer() const override
{
return HWBuffer;
}
mutable void *HWBuffer;
//! Material for this meshbuffer.
video::SMaterial Material;
//! Vertex buffer

View file

@ -7,6 +7,7 @@
#include "IReferenceCounted.h"
#include "irrArray.h"
#include "EHardwareBufferFlags.h"
#include "EPrimitiveTypes.h"
#include "SVertexIndex.h"
namespace irr
@ -50,6 +51,31 @@ public:
//! Used by the VideoDriver to remember the buffer link.
virtual void setHWBuffer(void *ptr) const = 0;
virtual void *getHWBuffer() const = 0;
//! Calculate how many geometric primitives would be drawn
u32 getPrimitiveCount(E_PRIMITIVE_TYPE primitiveType) const
{
const u32 indexCount = getCount();
switch (primitiveType) {
case scene::EPT_POINTS:
return indexCount;
case scene::EPT_LINE_STRIP:
return indexCount - 1;
case scene::EPT_LINE_LOOP:
return indexCount;
case scene::EPT_LINES:
return indexCount / 2;
case scene::EPT_TRIANGLE_STRIP:
return (indexCount - 2);
case scene::EPT_TRIANGLE_FAN:
return (indexCount - 2);
case scene::EPT_TRIANGLES:
return indexCount / 3;
case scene::EPT_POINT_SPRITES:
return indexCount;
}
return 0;
}
};
} // end namespace scene

View file

@ -176,18 +176,6 @@ public:
return getVertexBuffer()->getTCoords(i);
}
//! get the current hardware mapping hint
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
inline void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX)
{
@ -206,26 +194,8 @@ public:
getIndexBuffer()->setDirty();
}
//! Get the currently used ID for identification of changes.
/** This shouldn't be used for anything outside the VideoDriver. */
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. */
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;
virtual void *getHWBuffer() const = 0;
//! Describe what kind of primitive geometry is used by the meshbuffer
/** Note: Default is EPT_TRIANGLES. Using other types is fine for rendering.
But meshbuffer manipulation functions might expect type EPT_TRIANGLES
@ -237,32 +207,13 @@ public:
virtual E_PRIMITIVE_TYPE getPrimitiveType() const = 0;
//! Calculate how many geometric primitives are used by this meshbuffer
virtual u32 getPrimitiveCount() const
u32 getPrimitiveCount() const
{
const u32 indexCount = getIndexCount();
switch (getPrimitiveType()) {
case scene::EPT_POINTS:
return indexCount;
case scene::EPT_LINE_STRIP:
return indexCount - 1;
case scene::EPT_LINE_LOOP:
return indexCount;
case scene::EPT_LINES:
return indexCount / 2;
case scene::EPT_TRIANGLE_STRIP:
return (indexCount - 2);
case scene::EPT_TRIANGLE_FAN:
return (indexCount - 2);
case scene::EPT_TRIANGLES:
return indexCount / 3;
case scene::EPT_POINT_SPRITES:
return indexCount;
}
return 0;
return getIndexBuffer()->getPrimitiveCount(getPrimitiveType());
}
//! Calculate size of vertices and indices in memory
virtual size_t getSize() const
size_t getSize() const
{
size_t ret = 0;
switch (getVertexType()) {

View file

@ -21,7 +21,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
//! Default constructor
SSkinMeshBuffer(video::E_VERTEX_TYPE vt = video::EVT_STANDARD) :
VertexType(vt), PrimitiveType(EPT_TRIANGLES),
HWBuffer(nullptr), BoundingBoxNeedsRecalculated(true)
BoundingBoxNeedsRecalculated(true)
{
#ifdef _DEBUG
setDebugName("SSkinMeshBuffer");
@ -72,7 +72,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
}
}
scene::IVertexBuffer *getVertexBuffer()
scene::IVertexBuffer *getVertexBuffer() override
{
switch (VertexType) {
case video::EVT_2TCOORDS:
@ -119,6 +119,28 @@ struct SSkinMeshBuffer : public IMeshBuffer
BoundingBox = box;
}
private:
template <typename T> void recalculateBoundingBox(const CVertexBuffer<T> *buf)
{
if (!buf->getCount()) {
BoundingBox.reset(0, 0, 0);
} else {
auto &vertices = buf->Data;
BoundingBox.reset(vertices[0].Pos);
for (size_t i = 1; i < vertices.size(); ++i)
BoundingBox.addInternalPoint(vertices[i].Pos);
}
}
template <typename T1, typename T2> static void copyVertex(const T1 &src, T2 &dst)
{
dst.Pos = src.Pos;
dst.Normal = src.Normal;
dst.Color = src.Color;
dst.TCoords = src.TCoords;
}
public:
//! Recalculate bounding box
void recalculateBoundingBox() override
{
@ -129,36 +151,15 @@ struct SSkinMeshBuffer : public IMeshBuffer
switch (VertexType) {
case video::EVT_STANDARD: {
if (!Vertices_Standard->getCount())
BoundingBox.reset(0, 0, 0);
else {
auto &vertices = Vertices_Standard->Data;
BoundingBox.reset(vertices[0].Pos);
for (size_t i = 1; i < vertices.size(); ++i)
BoundingBox.addInternalPoint(vertices[i].Pos);
}
recalculateBoundingBox(Vertices_Standard);
break;
}
case video::EVT_2TCOORDS: {
if (!Vertices_2TCoords->getCount())
BoundingBox.reset(0, 0, 0);
else {
auto &vertices = Vertices_2TCoords->Data;
BoundingBox.reset(vertices[0].Pos);
for (size_t i = 1; i < vertices.size(); ++i)
BoundingBox.addInternalPoint(vertices[i].Pos);
}
recalculateBoundingBox(Vertices_2TCoords);
break;
}
case video::EVT_TANGENTS: {
if (!Vertices_Tangents->getCount())
BoundingBox.reset(0, 0, 0);
else {
auto &vertices = Vertices_Tangents->Data;
BoundingBox.reset(vertices[0].Pos);
for (size_t i = 1; i < vertices.size(); ++i)
BoundingBox.addInternalPoint(vertices[i].Pos);
}
recalculateBoundingBox(Vertices_Tangents);
break;
}
}
@ -170,10 +171,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
if (VertexType == video::EVT_STANDARD) {
video::S3DVertex2TCoords Vertex;
for (const auto &Vertex_Standard : Vertices_Standard->Data) {
Vertex.Color = Vertex_Standard.Color;
Vertex.Pos = Vertex_Standard.Pos;
Vertex.Normal = Vertex_Standard.Normal;
Vertex.TCoords = Vertex_Standard.TCoords;
copyVertex(Vertex_Standard, Vertex);
Vertices_2TCoords->Data.push_back(Vertex);
}
Vertices_Standard->Data.clear();
@ -185,12 +183,9 @@ struct SSkinMeshBuffer : public IMeshBuffer
void convertToTangents()
{
if (VertexType == video::EVT_STANDARD) {
video::S3DVertexTangents Vertex;
video::S3DVertexTangents Vertex;
for (const auto &Vertex_Standard : Vertices_Standard->Data) {
Vertex.Color = Vertex_Standard.Color;
Vertex.Pos = Vertex_Standard.Pos;
Vertex.Normal = Vertex_Standard.Normal;
Vertex.TCoords = Vertex_Standard.TCoords;
copyVertex(Vertex_Standard, Vertex);
Vertices_Tangents->Data.push_back(Vertex);
}
Vertices_Standard->Data.clear();
@ -198,10 +193,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
} else if (VertexType == video::EVT_2TCOORDS) {
video::S3DVertexTangents Vertex;
for (const auto &Vertex_2TCoords : Vertices_2TCoords->Data) {
Vertex.Color = Vertex_2TCoords.Color;
Vertex.Pos = Vertex_2TCoords.Pos;
Vertex.Normal = Vertex_2TCoords.Normal;
Vertex.TCoords = Vertex_2TCoords.TCoords;
copyVertex(Vertex_2TCoords, Vertex);
Vertices_Tangents->Data.push_back(Vertex);
}
Vertices_2TCoords->Data.clear();
@ -227,16 +219,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return PrimitiveType;
}
void setHWBuffer(void *ptr) const override
{
HWBuffer = ptr;
}
void *getHWBuffer() const override
{
return HWBuffer;
}
//! Call this after changing the positions of any vertex.
void boundingBoxNeedsRecalculated(void) { BoundingBoxNeedsRecalculated = true; }
@ -255,8 +237,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
//! Primitive type used for rendering (triangles, lines, ...)
E_PRIMITIVE_TYPE PrimitiveType;
mutable void *HWBuffer;
bool BoundingBoxNeedsRecalculated;
};