XNA Draw Calls

I've been tampering with how to construct the world.

Base Idea:

Step I:
Create a cube.

StepII:
Save the details in an XML File like -

<Blocks>
  <Block X="0" Y="0" Z="0" Height="1" Color="R" />
  <Block X="0" Y="0" Z="120" Height="1" Color="R" />
  <Block X="80" Y="0" Z="240" Height="1" Color="R" />
  <Block X="0" Y="0" Z="240" Height="1" Color="R" />
  <Block X="160" Y="0" Z="360" Height="1" Color="R" />
  <Block X="80" Y="0" Z="360" Height="1" Color="R" />
  <Block X="240" Y="0" Z="480" Height="1" Color="R" />
  <Block X="160" Y="0" Z="480" Height="1" Color="R" />
  <Block X="240" Y="0" Z="600" Height="1" Color="R" />
  <Block X="240" Y="0" Z="720" Height="1" Color="R" />
  <Block X="240" Y="0" Z="840" Height="1" Color="R" />


Step III:
Create and add blocks based on this. Set scales and Draw

Problem:
The problem with this approach is
I: We'll need around 100 - 300 blocks
II: Call mesh.Draw( ) for each of these
III: mesh.Draw( ) is an expensive operation

Solution:
Use heightmaps to generate terrain.
Although it may have more [lot more] Polys - its still a single mesh. Hence, just one Draw call.

NFS: Always create a single or may be just a few meshes for the level. As per NProf, mesh.Draw will consume 90% more CPU as compared to setting params like World, View, Projection, etc

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.