Sunday, April 22, 2007

Memory feeds imagination - Amy Tan

Problems with Vertex and Index buffers are fixed. It took a long round-about way to get there. To isolate the issue I created a software renderer for the Vertex and Index Buffers. This involved parsing the vertex and index data during the render loop and using individual glTexCoord2f, glVertex3 etc... calls to render each face. This immediately showed that the vertex data was correct however the index data was only half populated.

ASE Mesh incorrectly rendered with Index Buffers

Terain Segment incorrectly rendered with Index Buffers

e.g. In a terrain segment of of 8x8 there are 64 vertices, 128 faces and 384 indices. During the software rendering of the vertex and index buffers Decade engine crashed when the offset into the index buffer reached 147. It caused incorrect rendering or an Access violation because the value of the index buffer was 52685, but the vertex array has only 384 elements. Further investigation showed this to be an error with the memory copy functionality in the index buffer create function.

Instead of
memcpy( this->m_pusIndices, p_pusIndices, p_iNumberOfIndices );
it should have been
memcpy( this->m_pusIndices, p_pusIndices, p_iNumberOfIndices * sizeof(unsigned short) );

Problem fixed.

No comments:

Post a Comment