irr: Add support for non-triangle VBOs
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@13548 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -9,3 +9,4 @@ The following changes have been made:
|
||||
- a workaround for every other RTTs flipping
|
||||
- aabbox intersection support
|
||||
- texture override
|
||||
- non-triangle VBO support
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace scene
|
||||
return Material;
|
||||
}
|
||||
|
||||
virtual scene::E_PRIMITIVE_TYPE getPrimitiveType() const
|
||||
{
|
||||
return scene::EPT_TRIANGLES;
|
||||
}
|
||||
|
||||
//! Get bounding box
|
||||
virtual const core::aabbox3d<f32>& getBoundingBox() const
|
||||
{
|
||||
|
||||
@@ -18,7 +18,9 @@ namespace scene
|
||||
{
|
||||
public:
|
||||
//! Default constructor for empty meshbuffer
|
||||
CMeshBuffer():ChangedID_Vertex(1),ChangedID_Index(1),MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER)
|
||||
CMeshBuffer(): ChangedID_Vertex(1), ChangedID_Index(1),
|
||||
MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
|
||||
Primitive(EPT_TRIANGLES)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("SMeshBuffer");
|
||||
@@ -171,6 +173,10 @@ namespace scene
|
||||
return Vertices[i].TCoords;
|
||||
}
|
||||
|
||||
virtual scene::E_PRIMITIVE_TYPE getPrimitiveType() const
|
||||
{
|
||||
return Primitive;
|
||||
}
|
||||
|
||||
//! Append the vertices and indices to the current buffer
|
||||
/** Only works for compatible types, i.e. either the same type
|
||||
@@ -285,6 +291,9 @@ namespace scene
|
||||
core::array<u16> Indices;
|
||||
//! Bounding box of this meshbuffer.
|
||||
core::aabbox3d<f32> BoundingBox;
|
||||
|
||||
//! What kind of primitives does this buffer contain? Default triangles
|
||||
scene::E_PRIMITIVE_TYPE Primitive;
|
||||
};
|
||||
|
||||
//! Standard meshbuffer
|
||||
|
||||
@@ -112,6 +112,9 @@ namespace scene
|
||||
//! returns texture coord of vertex i
|
||||
virtual core::vector2df& getTCoords(u32 i) = 0;
|
||||
|
||||
//! Returns the primitive type of this buffer
|
||||
virtual scene::E_PRIMITIVE_TYPE getPrimitiveType() const = 0;
|
||||
|
||||
//! Append the vertices and indices to the current buffer
|
||||
/** Only works for compatible vertex types.
|
||||
\param vertices Pointer to a vertex array.
|
||||
|
||||
@@ -1459,6 +1459,9 @@ namespace video
|
||||
//! Get the maximum texture size supported.
|
||||
virtual core::dimension2du getMaxTextureSize() const =0;
|
||||
|
||||
//! Convert the number of indices to the number of primitives
|
||||
virtual u32 indiceToPrimitiveCount(scene::E_PRIMITIVE_TYPE pType, u32 count) const = 0;
|
||||
|
||||
//! Color conversion convenience function
|
||||
/** Convert an image (as array of pixels) from source to destination
|
||||
array, thereby converting the color format. The pixel size is
|
||||
|
||||
@@ -22,7 +22,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
|
||||
SSkinMeshBuffer(video::E_VERTEX_TYPE vt=video::EVT_STANDARD) :
|
||||
ChangedID_Vertex(1), ChangedID_Index(1), VertexType(vt),
|
||||
MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
|
||||
BoundingBoxNeedsRecalculated(true)
|
||||
BoundingBoxNeedsRecalculated(true), Primitive(EPT_TRIANGLES)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("SSkinMeshBuffer");
|
||||
@@ -325,6 +325,12 @@ struct SSkinMeshBuffer : public IMeshBuffer
|
||||
}
|
||||
}
|
||||
|
||||
virtual scene::E_PRIMITIVE_TYPE getPrimitiveType() const
|
||||
{
|
||||
return Primitive;
|
||||
}
|
||||
|
||||
|
||||
//! append the vertices and indices to the current buffer
|
||||
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
|
||||
|
||||
@@ -394,6 +400,9 @@ struct SSkinMeshBuffer : public IMeshBuffer
|
||||
E_HARDWARE_MAPPING MappingHint_Index:3;
|
||||
|
||||
bool BoundingBoxNeedsRecalculated:1;
|
||||
|
||||
//! What kind of primitives does this buffer contain? Default triangles
|
||||
scene::E_PRIMITIVE_TYPE Primitive;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1518,7 +1518,7 @@ void CNullDriver::drawMeshBuffer(const scene::IMeshBuffer* mb)
|
||||
if (HWBuffer)
|
||||
drawHardwareBuffer(HWBuffer);
|
||||
else
|
||||
drawVertexPrimitiveList(mb->getVertices(), mb->getVertexCount(), mb->getIndices(), mb->getIndexCount()/3, mb->getVertexType(), scene::EPT_TRIANGLES, mb->getIndexType());
|
||||
drawVertexPrimitiveList(mb->getVertices(), mb->getVertexCount(), mb->getIndices(), indiceToPrimitiveCount(mb->getPrimitiveType(), mb->getIndexCount()), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType());
|
||||
}
|
||||
|
||||
|
||||
@@ -2444,6 +2444,32 @@ void CNullDriver::convertColor(const void* sP, ECOLOR_FORMAT sF, s32 sN,
|
||||
video::CColorConverter::convert_viaFormat(sP, sF, sN, dP, dF);
|
||||
}
|
||||
|
||||
u32 CNullDriver::indiceToPrimitiveCount(scene::E_PRIMITIVE_TYPE ptype, u32 count) const
|
||||
{
|
||||
switch (ptype)
|
||||
{
|
||||
case scene::EPT_POINTS:
|
||||
case scene::EPT_POINT_SPRITES:
|
||||
case scene::EPT_LINE_LOOP:
|
||||
case scene::EPT_POLYGON:
|
||||
return count;
|
||||
case scene::EPT_LINE_STRIP:
|
||||
return count - 1;
|
||||
case scene::EPT_LINES:
|
||||
return count/2;
|
||||
case scene::EPT_TRIANGLE_STRIP:
|
||||
case scene::EPT_TRIANGLE_FAN:
|
||||
return count - 2;
|
||||
case scene::EPT_TRIANGLES:
|
||||
return count/3;
|
||||
case scene::EPT_QUAD_STRIP:
|
||||
return (count - 2) / 2;
|
||||
case scene::EPT_QUADS:
|
||||
return count/4;
|
||||
default:
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
||||
@@ -94,6 +94,8 @@ namespace video
|
||||
//! Returns amount of textures currently loaded
|
||||
virtual u32 getTextureCount() const;
|
||||
|
||||
virtual u32 indiceToPrimitiveCount(scene::E_PRIMITIVE_TYPE pType, u32 count) const;
|
||||
|
||||
//! Renames a texture
|
||||
virtual void renameTexture(ITexture* texture, const io::path& newName);
|
||||
|
||||
|
||||
@@ -1301,7 +1301,7 @@ void COpenGLDriver::drawHardwareBuffer(SHWBufferLink *_HWBuffer)
|
||||
indexList=0;
|
||||
}
|
||||
|
||||
drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, mb->getIndexCount()/3, mb->getVertexType(), scene::EPT_TRIANGLES, mb->getIndexType());
|
||||
drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, indiceToPrimitiveCount(mb->getPrimitiveType(), mb->getIndexCount()), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType());
|
||||
|
||||
if (HWBuffer->Mapped_Vertex!=scene::EHM_NEVER)
|
||||
extGlBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
Reference in New Issue
Block a user