我只能写一次到顶点缓冲区而不重新声明整个类。
原始写作
SlimDX.Direct3D11.Buffer vertexBuffer;
vertexBuffer = new SlimDX.Direct3D11.Buffer(DeviceManager.Instance.device,
vertices,
SizeOfVertexBufferInBytes,
ResourceUsage.Default,
BindFlags.VertexBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0);
用于重写缓冲区的代码。它目前没有动,只是想重写。
public void Move(Vector3 deltaVec)
{
this.vertexBuffer.Dispose();
vertexBuffer = new SlimDX.Direct3D11.Buffer(DeviceManager.Instance.device,
vertices,
SizeOfVertexBufferInBytes,
ResourceUsage.Default,
BindFlags.VertexBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0);
render();
}
我如何能够重写此缓冲区以更改顶点的位置。感谢
答案 0 :(得分:0)
对于碰巧遇到与我相同问题的其他人,我相信我找到了解决方案。在Move函数中,我从未将位置设置回0.(这导致它索引出来?)。这里的任何方式都是固定代码。
public void Move(Vector3 deltaVec)
{
this.vertices.Close();
vertices = new DataStream(SizeOfVertexBufferInBytes, true, true);
foreach (Vector3 vec in this.verticiesList)
{
vertices.Write(vec + deltaVec);
}
vertices.Position = 0;
// create the vertex layout and buffer
var elements = new[] {
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0)
};
layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements);
vertexBuffer = new SlimDX.Direct3D11.Buffer(DeviceManager.Instance.device,
vertices,
SizeOfVertexBufferInBytes,
ResourceUsage.Default,
BindFlags.VertexBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0);
render();
}
祝你好运!