mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-18 00:08:20 +01:00
CDynamicMeshBuffer::append can now handle appending meshbuffers with different vertex/index types
Doesn't change it's own type - so can still drop data. Or overflow 16-bit buffers (which creates broken models, but no crashes). But it no longer has a problem adding 16-bit index-buffers to a 32-bit index-buffer for example. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6494 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
01588b58eb
commit
428fcca7fb
@ -109,6 +109,19 @@ namespace scene
|
|||||||
\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) IRR_OVERRIDE
|
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
|
||||||
|
{
|
||||||
|
// We simply assume it has the same vertex and index type as this object. If other types are passed this will crash
|
||||||
|
append(getVertexType(), vertices, numVertices, getIndexType(), indices, numIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Append the meshbuffer to the current buffer
|
||||||
|
/** \param other Buffer to append to this one. */
|
||||||
|
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
|
||||||
|
{
|
||||||
|
append(other->getVertexType(), other->getVertices(), other->getVertexCount(), other->getIndexType(), other->getIndices(), other->getIndexCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
void append(video::E_VERTEX_TYPE vertexType, const void* const vertices, u32 numVertices, video::E_INDEX_TYPE indexType, const void* const indices, u32 numIndices)
|
||||||
{
|
{
|
||||||
if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks
|
if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks
|
||||||
return;
|
return;
|
||||||
@ -116,7 +129,7 @@ namespace scene
|
|||||||
const u32 vertexCount = getVertexCount();
|
const u32 vertexCount = getVertexCount();
|
||||||
|
|
||||||
VertexBuffer->reallocate(vertexCount+numVertices);
|
VertexBuffer->reallocate(vertexCount+numVertices);
|
||||||
switch ( VertexBuffer->getType() )
|
switch ( vertexType )
|
||||||
{
|
{
|
||||||
case video::EVT_STANDARD:
|
case video::EVT_STANDARD:
|
||||||
for (u32 i=0; i<numVertices; ++i)
|
for (u32 i=0; i<numVertices; ++i)
|
||||||
@ -142,36 +155,32 @@ namespace scene
|
|||||||
}
|
}
|
||||||
|
|
||||||
IndexBuffer->reallocate(getIndexCount()+numIndices);
|
IndexBuffer->reallocate(getIndexCount()+numIndices);
|
||||||
switch ( IndexBuffer->getType() )
|
switch ( indexType )
|
||||||
{
|
{
|
||||||
case video::EIT_16BIT:
|
case video::EIT_16BIT:
|
||||||
|
{
|
||||||
|
const irr::u16* indices16 = reinterpret_cast<const irr::u16*>(indices);
|
||||||
for (u32 i=0; i<numIndices; ++i)
|
for (u32 i=0; i<numIndices; ++i)
|
||||||
{
|
{
|
||||||
IndexBuffer->push_back(indices[i]+vertexCount);
|
// Note: This can overflow, not checked. Will result in broken models, but no crashes.
|
||||||
|
IndexBuffer->push_back(indices16[i]+vertexCount);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case video::EIT_32BIT:
|
case video::EIT_32BIT:
|
||||||
|
{
|
||||||
|
const irr::u32* indices32 = reinterpret_cast<const irr::u32*>(indices);
|
||||||
for (u32 i=0; i<numIndices; ++i)
|
for (u32 i=0; i<numIndices; ++i)
|
||||||
{
|
{
|
||||||
IndexBuffer->push_back(reinterpret_cast<const irr::u32*>(indices)[i]+vertexCount);
|
IndexBuffer->push_back(indices32[i]+vertexCount);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setDirty();
|
setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Append the meshbuffer to the current buffer
|
|
||||||
/** 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
|
|
||||||
{
|
|
||||||
if ( getVertexType() != other->getVertexType() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
append(other->getVertices(), other->getVertexCount(), other->getIndices(), other->getIndexCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! Describe what kind of primitive geometry is used by the meshbuffer
|
//! Describe what kind of primitive geometry is used by the meshbuffer
|
||||||
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) IRR_OVERRIDE
|
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) IRR_OVERRIDE
|
||||||
|
Loading…
Reference in New Issue
Block a user