XNA: When does "stuff" go into VRAM?

Started by
1 comment, last by NickW 10 years, 7 months ago

I'm going to be generating a lot of primitives and meshes programmatically. For example, a huge terrain object which is based off of a height map. This terrain object will have thousands and thousands of verticies. Let's assume that I've got the height map and it's able to fill a vertex buffer in RAM with all of the pertinent vertex information. Now, I need to draw it. To do that, I'd call something like this:


public void Render()
{
     foreach (EffectPass pass in m_effect.CurrentTechnique.Passes)
     {
          pass.Apply();
          m_gd.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
          m_verticies, 0, 4, m_indicies, 0, 2);
     }
}

In this case, all of the verticies are stored inside of a "VertexPositionNormalTexture[] m_verticies" array. By calling the "DrawUserIndexedPrimitives", I'm assuming that in this render frame, it's copying the data from RAM into VRAM and the graphics card takes over the rendering from there. However, if my verticies don't ever change, it seems like it'd be a waste of RAM->VRAM bandwidth to keep copying the same data every frame. It'd be better if I could store the data directly on the graphics card as some sort of object in VRAM and then tell the graphics card when I want to render the stored object. Ideally, if I ever need to update the object in VRAM, I could do it on my own time instead of updating every object every frame. I feel like this is totally possible but none of the XNA documentation gives any hints at how to do it. My initial thought was that I could convert my user created primitive into a mesh object and then store the mesh in VRAM and render it like a mesh object, but I don't know how to do this either (documentation isn't helpful). I'm wondering if its possible or if this is just a limitation of the XNA API?

Advertisement
You're right: You're burning bandwidth for no reason. You want to explicitly use a VertexBuffer and IndexBuffer (or several of them). Here's a tutorial.

Use a VertexBuffer/IndexBuffer

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/VertexBuffer_and_IndexBuffer.php

If you need to update the data in the buffer frequently, use a DynamicVertexBuffer

This topic is closed to new replies.

Advertisement