Reputation: 34036
I am using SharpDX to render some textured quads. What is the recommended way to change the data of the vertices (position, color, texture)?
I allocate the buffer like this:
var vertexBuffer = SharpDX.Toolkit.Graphics.Buffer.Vertex.New(graphicsdevice, vertecpositiontexturecolor);
var vertexInputLayout = VertexInputLayout.FromBuffer(0, vertexBuffer);
And then draw it like this:
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsdevice.Draw(PrimitiveType.TriangleStrip, vertexBuffer.ElementCount);
}
now i want to reuse the existing vertexbuffer, change the values for position, color and texture and draw again.
so far i did it with GetData() and SetData() but this has a big negative impact on performance :(
Upvotes: 0
Views: 999
Reputation: 2418
Do not use GetData to fetch the existing data, just push new data to the VertexBuffer each time using SetData. If you need to know what's in the VertexBuffer, keep a copy of the data in memory in C# rather than fetching it using GetData.
Usually data is pushed from the CPU to the GPU not the other way around. This allows the two systems to operate in parallel. With the GPU lagging slightly behind the CPU.
If you fetch data from the GPU and return it to the CPU you create a situation where the CPU must wait for the data to arrive before it can proceed. This has the knock effect that the GPU is then left waiting for further instructions from the CPU. This situation is known as a 'stall'.
Upvotes: 4