1
\$\begingroup\$

If I'm going to draw cubes effectively, I need to get rid of the numerous amounts of draw calls I have and what has been suggested is that I create a "mesh" of my cubes. I already have them being stored in a single vertex buffer, but the issue lies in my draw method where I am still looping through every cube in order to draw them. I thought this was necessary as each cube will have a set position, but it lowers the frame rate incredibly. What's the easiest way to go about this? I have a class CubeChunk that inherits Microsoft.Stuff.DrawableGameComponent, but I don't know what comes next. I suppose I could just use the chunk of cubes created in my cube class, but that would just keep me going in circles and drawing each cube individually.

The goal here is to create a draw method that draws my chunk as a whole, and to not draw individual cubes as I've been doing.

\$\endgroup\$
  • 3
    \$\begingroup\$ You create one mesh that contains the vertices for all the visible faces of each cube in that chunk. You will have to loop through all the cubes at some point to see which faces are visible and add their vertices to the mesh, but you'll only have to do it once (and again whenever something in the chunk changes, you'll want to rebuild the mesh). \$\endgroup\$ – MichaelHouse Jul 2 '13 at 20:42
  • \$\begingroup\$ The part I'm having trouble with is telling which sides of my cube are visible. I have both vertices and indices that I'm using to draw the cube so I'm assuming that means looping through both those arrays. How do I tell if a face is visible when the cubes don't have faces defined by my code? \$\endgroup\$ – Christian Frantz Jul 2 '13 at 20:52
  • \$\begingroup\$ It sounds like you might want to reconsider your choice of data structures, and the data you're choosing to store in them. Head to chat sometime to talk about it. Also check out this question as it's very similar to yours. \$\endgroup\$ – MichaelHouse Jul 2 '13 at 20:58
  • \$\begingroup\$ Thanks for the link!! Can you explain the isSolidAt method you mentioned in the question? \$\endgroup\$ – Christian Frantz Jul 2 '13 at 21:16
  • \$\begingroup\$ We can discuss it in chat. \$\endgroup\$ – MichaelHouse Jul 2 '13 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.