mirror of
https://github.com/minetest/irrlicht.git
synced 2024-12-24 23:22:26 +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. */
|
\param numIndices Number of indices in array. */
|
||||||
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
|
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
|
//! 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. */
|
\param other Buffer to append to this one. */
|
||||||
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
|
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
|
//! Append the vertices and indices to the current buffer
|
||||||
/** Only works for compatible types, i.e. either the same type
|
/** Only works for compatible types, i.e. either the same type
|
||||||
or the main buffer is of standard type. Otherwise, behavior is
|
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
|
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;
|
return;
|
||||||
|
|
||||||
const u32 vertexCount = getVertexCount();
|
const u32 vertexCount = getVertexCount();
|
||||||
@ -213,37 +213,18 @@ namespace scene
|
|||||||
{
|
{
|
||||||
Indices.push_back(indices[i]+vertexCount);
|
Indices.push_back(indices[i]+vertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Append the meshbuffer to the current buffer
|
//! 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
|
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
|
||||||
{
|
{
|
||||||
/*
|
if ( getVertexType() != other->getVertexType() )
|
||||||
if (this==other)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const u32 vertexCount = getVertexCount();
|
append(other->getVertices(), other->getVertexCount(), other->getIndices(), other->getIndexCount());
|
||||||
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());
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,17 +126,17 @@ namespace scene
|
|||||||
virtual const video::SColor& getColor(u32 i) const = 0;
|
virtual const video::SColor& getColor(u32 i) const = 0;
|
||||||
|
|
||||||
//! Append the vertices and indices to the current buffer
|
//! Append the vertices and indices to the current buffer
|
||||||
/** Only works for compatible vertex types
|
/** Only works for compatible vertex and index types
|
||||||
and not implemented for most buffers for now.
|
and not implemented for some buffers for now.
|
||||||
\param vertices Pointer to a vertex array.
|
\param vertices Pointer to a vertex array.
|
||||||
\param numVertices Number of vertices in the array.
|
\param numVertices Number of vertices in the array.
|
||||||
\param indices Pointer to index array.
|
\param indices Pointer to index array.
|
||||||
\param numIndices Number of indices in array. */
|
\param numIndices Number of indices in array. */
|
||||||
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) = 0;
|
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
|
//! 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. */
|
\param other Buffer to append to this one. */
|
||||||
virtual void append(const IMeshBuffer* const other) = 0;
|
virtual void append(const IMeshBuffer* const other) = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user