Actually, it works pretty good with manual objects, you just have to use them correctly. Ogre creates a render operation for each begin/end pair, and you are creating one for each line. That's really expensive.
And you can grow/shrink the number of vertices while updating dynamic manual objects, you just can't change the render operations. That works perfectly here, as you should create three manual object segments: one for the points, one for the lines and one for the triangles.
So at initialization of you debug renderer class, you should do something like this (m_pObject is your manual object):
Code: Select all
// Create the 3 render types (will be filled in each frame)
m_pObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_POINT_LIST);
m_pObject->end();
m_pObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
m_pObject->end();
m_pObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
m_pObject->end();
Then your renderData function:
Code: Select all
void DebugRenderer::renderData(const NxDebugRenderable &data) const
{
// Calculate the total number of vertices
unsigned int numVertices = data.getNbPoints();
numVertices += data.getNbLines() * 2;
numVertices += data.getNbTriangles() * 3;
m_pObject->estimateVertexCount(numVertices);
// Debug points
m_pObject->beginUpdate(0);
for(unsigned int i = 0; i < data.getNbPoints(); ++i)
{
const NxVec3 &pos = data.getPoints()[i].p;
m_pObject->position(pos[0], pos[1], pos[2]);
float r,g,b;
convertColor(data.getPoints()[i].color, r,g,b);
m_pObject->colour(r,g,b);
}
m_pObject->end();
// Debug lines
m_pObject->beginUpdate(1);
for(unsigned int i = 0; i < data.getNbLines(); ++i)
{
// Get the line color (same for both vertices)
float r,g,b;
convertColor(data.getLines()[i].color, r,g,b);
const NxVec3 &pos1 = data.getLines()[i].p0;
m_pObject->position(pos1[0], pos1[1], pos1[2]);
m_pObject->colour(r,g,b);
const NxVec3 &pos2 = data.getLines()[i].p1;
m_pObject->position(pos2[0], pos2[1], pos2[2]);
m_pObject->colour(r,g,b);
}
m_pObject->end();
// Debug triangles
m_pObject->beginUpdate(2);
for(unsigned int i = 0; i < data.getNbTriangles(); ++i)
{
// Get the triangle color (same for all three vertices)
float r,g,b;
convertColor(data.getTriangles()[i].color, r,g,b);
const NxVec3 &pos1 = data.getTriangles()[i].p0;
m_pObject->position(pos1[0], pos1[1], pos1[2]);
m_pObject->colour(r,g,b);
const NxVec3 &pos2 = data.getTriangles()[i].p1;
m_pObject->position(pos2[0], pos2[1], pos2[2]);
m_pObject->colour(r,g,b);
const NxVec3 &pos3 = data.getTriangles()[i].p2;
m_pObject->position(pos3[0], pos3[1], pos3[2]);
m_pObject->colour(r,g,b);
}
m_pObject->end();
}
As you can see, this only generates three batches, which is a whole lot more efficient than what you were doing. I'm not sure about the estimateVertexCount though, it could be that that belongs inside each batch (so for points, lines and triangles seperate and inside the beginUpdate/end parts).
Good luck!
Greetz,
JeDi