mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-08 16:53:52 +01:00
Get (more) append functions working for CMeshBuffer and CDynamicMeshBuffer
Some in CMeshBuffer got disabled in svn r1515 (before Irrlicht 1.7) without comment. I suspect reason might have been that they are a bit unsafe and it was meant to be reworked. Maybe was planned to put that into MeshManipulator? And CDynamicMeshBuffer never had them. Anyway, it's useful stuff and having functions do nothing doesn't help. So now they do at least basic work. Meaning - as long as index and vertex types are identical it's possible to attach meshbuffers again. While totally ignoring things like 16-bit index overflow for now (so could be improved). It would probably be better if attach functions had info about vertex/index types, but just keeping interface as it is/was for now. This also fixes Bug #310 reported by Gaz. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6493 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
31931b0455
commit
01588b58eb
@ -110,15 +110,66 @@ namespace scene
|
||||
\param numIndices Number of indices in array. */
|
||||
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
|
||||
{
|
||||
// TODO
|
||||
if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks
|
||||
return;
|
||||
|
||||
const u32 vertexCount = getVertexCount();
|
||||
|
||||
VertexBuffer->reallocate(vertexCount+numVertices);
|
||||
switch ( VertexBuffer->getType() )
|
||||
{
|
||||
case video::EVT_STANDARD:
|
||||
for (u32 i=0; i<numVertices; ++i)
|
||||
{
|
||||
VertexBuffer->push_back(static_cast<const video::S3DVertex*>(vertices)[i]);
|
||||
BoundingBox.addInternalPoint(static_cast<const video::S3DVertex*>(vertices)[i].Pos);
|
||||
}
|
||||
break;
|
||||
case video::EVT_2TCOORDS:
|
||||
for (u32 i=0; i<numVertices; ++i)
|
||||
{
|
||||
VertexBuffer->push_back(static_cast<const video::S3DVertex2TCoords*>(vertices)[i]);
|
||||
BoundingBox.addInternalPoint(static_cast<const video::S3DVertex2TCoords*>(vertices)[i].Pos);
|
||||
}
|
||||
break;
|
||||
case video::EVT_TANGENTS:
|
||||
for (u32 i=0; i<numVertices; ++i)
|
||||
{
|
||||
VertexBuffer->push_back(static_cast<const video::S3DVertexTangents*>(vertices)[i]);
|
||||
BoundingBox.addInternalPoint(static_cast<const video::S3DVertexTangents*>(vertices)[i].Pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
IndexBuffer->reallocate(getIndexCount()+numIndices);
|
||||
switch ( IndexBuffer->getType() )
|
||||
{
|
||||
case video::EIT_16BIT:
|
||||
for (u32 i=0; i<numIndices; ++i)
|
||||
{
|
||||
IndexBuffer->push_back(indices[i]+vertexCount);
|
||||
}
|
||||
break;
|
||||
case video::EIT_32BIT:
|
||||
for (u32 i=0; i<numIndices; ++i)
|
||||
{
|
||||
IndexBuffer->push_back(reinterpret_cast<const irr::u32*>(indices)[i]+vertexCount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
setDirty();
|
||||
}
|
||||
|
||||
//! Append the meshbuffer to the current buffer
|
||||
/** Only works for compatible vertex types
|
||||
/** Only works for compatible vertex and index types
|
||||
\param other Buffer to append to this one. */
|
||||
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
|
||||
{
|
||||
// TODO
|
||||
if ( getVertexType() != other->getVertexType() )
|
||||
return;
|
||||
|
||||
append(other->getVertices(), other->getVertexCount(), other->getIndices(), other->getIndexCount());
|
||||
}
|
||||
|
||||
|
||||
|
@ -191,11 +191,11 @@ namespace scene
|
||||
//! Append the vertices and indices to the current buffer
|
||||
/** Only works for compatible types, i.e. either the same type
|
||||
or the main buffer is of standard type. Otherwise, behavior is
|
||||
undefined.
|
||||
undefined. Also can't append it's own vertices/indices to itself.
|
||||
*/
|
||||
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
|
||||
{
|
||||
if (vertices == getVertices())
|
||||
if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks
|
||||
return;
|
||||
|
||||
const u32 vertexCount = getVertexCount();
|
||||
@ -213,37 +213,18 @@ namespace scene
|
||||
{
|
||||
Indices.push_back(indices[i]+vertexCount);
|
||||
}
|
||||
|
||||
setDirty();
|
||||
}
|
||||
|
||||
|
||||
//! Append the meshbuffer to the current buffer
|
||||
/** Only works for compatible types, i.e. either the same type
|
||||
or the main buffer is of standard type. Otherwise, behavior is
|
||||
undefined.
|
||||
\param other Meshbuffer to be appended to this one.
|
||||
*/
|
||||
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
|
||||
{
|
||||
/*
|
||||
if (this==other)
|
||||
if ( getVertexType() != other->getVertexType() )
|
||||
return;
|
||||
|
||||
const u32 vertexCount = getVertexCount();
|
||||
u32 i;
|
||||
|
||||
Vertices.reallocate(vertexCount+other->getVertexCount());
|
||||
for (i=0; i<other->getVertexCount(); ++i)
|
||||
{
|
||||
Vertices.push_back(reinterpret_cast<const T*>(other->getVertices())[i]);
|
||||
}
|
||||
|
||||
Indices.reallocate(getIndexCount()+other->getIndexCount());
|
||||
for (i=0; i<other->getIndexCount(); ++i)
|
||||
{
|
||||
Indices.push_back(other->getIndices()[i]+vertexCount);
|
||||
}
|
||||
BoundingBox.addInternalBox(other->getBoundingBox());
|
||||
*/
|
||||
append(other->getVertices(), other->getVertexCount(), other->getIndices(), other->getIndexCount());
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,17 +126,17 @@ namespace scene
|
||||
virtual const video::SColor& getColor(u32 i) const = 0;
|
||||
|
||||
//! Append the vertices and indices to the current buffer
|
||||
/** Only works for compatible vertex types
|
||||
and not implemented for most buffers for now.
|
||||
/** Only works for compatible vertex and index types
|
||||
and not implemented for some buffers for now.
|
||||
\param vertices Pointer to a vertex array.
|
||||
\param numVertices Number of vertices in the array.
|
||||
\param indices Pointer to index array.
|
||||
\param numIndices Number of indices in array. */
|
||||
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) = 0;
|
||||
|
||||
//! Not supported right now by any meshbuffer
|
||||
//! Not supported right now by all meshbuffer
|
||||
//! In theory: Append the meshbuffer to the current buffer
|
||||
/** Only works for compatible vertex types
|
||||
/** Only works for compatible vertex and index types
|
||||
\param other Buffer to append to this one. */
|
||||
virtual void append(const IMeshBuffer* const other) = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user