In my previous post I posted my proposed class design for wrapping up the horrible display list code used in libnds. It has taken a lot longer than I expected to get this class working correctly due to other projects taking precedence for a while.That said I have finished finally and it works great for the most part.

One headache I had was due to the way the display lists are set out in libnds

A pack like this means that the next four values are going to be a vertex, colour, vertex and another colour. There are many different values that can be passed into the COMMAND_PACK such as normals and texture coordinates. The plan was to make it so that a COMMAND_PACK would be automatically added rather than a user having to explicitly call the COMMAND_PACK.

The solution was to create a vector to push temporary values into and also another vector which contained the commands to put into the COMMAND_PACK. The COMMAND_PACK values are really just #defines for int's.

std::vector<u32> m_tempDataTypes;
std::vector<u32> m_tempValues;

Now whenever a user adds a vertex or any other value then its type gets pushed into the m_tempDataTypes vector and its values get pushed into the m_tempValues vector, also a counter is incremented. Whenever the counter reaches 4 then the pack is created from the values in m_tempDataTypes and pushed into the main list. Then the next 4 values in the main display list are added from the m_tempValues vector.
Here are the AddVertex and AddPack functions for an example:

void DisplayList::AddPack()
{
// this loop makes sure that the pack gets padded out if there are not 4 values in it at the time
// according to the documentation for libnds FIFO_END has no use so I used it to pad out pack without it expecting any values
for (int i = m_tempDataTypes.size(); i < 4; i++)
{
m_tempDataTypes.push_back(FIFO_END);
}
m_list.push_back(FIFO_COMMAND_PACK(m_tempDataTypes[0], m_tempDataTypes[1], m_tempDataTypes[2], m_tempDataTypes[3]));
m_tempDataTypes.clear();
m_listCount++;
for (int i = 0; i < m_tempValues.size(); i++)
{
m_list.push_back(m_tempValues[i]);
m_listCount++;
}
m_tempValues.clear();
m_tempListCount = 0;
}

So my mesh drawing code now uses this display list class which is a lot faster and more efficient. It shows just how slow using GL_BEGIN and GL_END is when it is quicker to create a display list each frame than use it :s