Hello everyone, I'm currently instancing a set of primitives (cubes, spheres, etc) with modulo arithmetic and I'm having wit the DataStream.WriteRange<> method.
I'm using this to write to the InstanceBuffer:
DataStream dsInstances = instanceBuffer.Map(MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None);
if (instancesStart + instancesCount < instancesMax)
{
dsInstances.Position = instancesStart;
dsInstances.WriteRange<VertexPrimitiveInstance>(instances, instancesStart, instancesCount);
}
else
{
dsInstances.Position = instancesStart;
dsInstances.WriteRange<VertexPrimitiveInstance>(instances, instancesStart, instancesMax - instancesStart);
dsInstances.Position = 0;
dsInstances.WriteRange<VertexPrimitiveInstance>(instances, 0, instancesCount - (instancesMax - instancesStart));
}
instanceBuffer.Unmap();
I see nothing the first loop around from 0 to InstancesMax. However, I start seeing my objects once I've written all values to the buffer at least once. Then I get some very strange flicker and occasionally deformed geometry.
If I change the above to write the entire array of VertexPrimitiveInstances to the buffer, I get no flicker.
DataStream dsInstances = instanceBuffer.Map(MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None);
dsInstances.Position = 0;
dsInstances.WriteRange<VertexPrimitiveInstance>(instances);
instanceBuffer.Unmap();
I presume that the second method is far slower than the first (if if worked) and is thus undesirable. Am I using WriteRange wrong, or am I wrong in thinking I should only set the vertices that are changing (like I did in XNA)?