本文整理汇总了C#中DynamicVertexBuffer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicVertexBuffer.Dispose方法的具体用法?C# DynamicVertexBuffer.Dispose怎么用?C# DynamicVertexBuffer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicVertexBuffer
的用法示例。
在下文中一共展示了DynamicVertexBuffer.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawInstancedTowers
private static void DrawInstancedTowers(int playerNum, int towerType, int amount)
{
//int amount = units[playerNum][unitType].Count;
if (amount == 0)
return;
instanceVertexBuffer = null; ///////////////////////////////////////////////////////////////////FIX THIS!
// If we have more instances than room in our vertex buffer, grow it to the neccessary size.
if ((instanceVertexBuffer == null) ||
(amount > instanceVertexBuffer.VertexCount))
{
if (instanceVertexBuffer != null)
instanceVertexBuffer.Dispose();
instanceVertexBuffer = new DynamicVertexBuffer(ScreenManager.Game.GraphicsDevice, instanceVertexDeclaration,
amount, BufferUsage.WriteOnly);
}
// Transfer the latest instance transform matrices into the instanceVertexBuffer.
instanceVertexBuffer.SetData(towerTransforms, 0, amount, SetDataOptions.Discard);
for (int i = 0; i < instancedModels[towerType][playerNum].Meshes.Count; i++)
{
for (int j = 0; j < instancedModels[towerType][playerNum].Meshes[i].MeshParts.Count; j++)
{
// Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer.
ScreenManager.Game.GraphicsDevice.SetVertexBuffers(
new VertexBufferBinding(instancedModels[towerType][playerNum].Meshes[i].MeshParts[j].VertexBuffer,
instancedModels[towerType][playerNum].Meshes[i].MeshParts[j].VertexOffset, 0),
new VertexBufferBinding(instanceVertexBuffer, 0, 1)
);
ScreenManager.Game.GraphicsDevice.Indices = instancedModels[towerType][playerNum].Meshes[i].MeshParts[j].IndexBuffer;
// Set up the instance rendering effect.
Effect effect = instancedModels[towerType][playerNum].Meshes[i].MeshParts[j].Effect;
effect.CurrentTechnique = effect.Techniques["HardwareInstancing"];
effect.Parameters["World"].SetValue(instancedModelBones[towerType][playerNum][instancedModels[towerType][playerNum].Meshes[i].ParentBone.Index]);
effect.Parameters["View"].SetValue(cameraManager.ViewMatrix);
effect.Parameters["Projection"].SetValue(cameraManager.ProjectionMatrix);
// Draw all the instance copies in a single call.
for (int k = 0; k < effect.CurrentTechnique.Passes.Count; k++)
{
effect.CurrentTechnique.Passes[k].Apply();
ScreenManager.Game.GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0,
instancedModels[towerType][playerNum].Meshes[i].MeshParts[j].NumVertices,
instancedModels[towerType][playerNum].Meshes[i].MeshParts[j].StartIndex,
instancedModels[towerType][playerNum].Meshes[i].MeshParts[j].PrimitiveCount,
amount);
}
}
}
}