C# XNA缓冲区最佳实践
我目前正在将2D游戏转换为3D,在我尝试边玩边学习之前,我从未使用过3D。我想知道使用顶点/索引缓冲区的最佳方式是什么 目前,我正在一个网格中循环,为每种瓷砖类型创建一组缓冲区,然后在draw方法中使用这些缓冲区。我想我不应该使用多组顶点缓冲区,但我不知道其他方法,因为每个瓷砖都是不同的纹理 网格环C# XNA缓冲区最佳实践,c#,xna,C#,Xna,我目前正在将2D游戏转换为3D,在我尝试边玩边学习之前,我从未使用过3D。我想知道使用顶点/索引缓冲区的最佳方式是什么 目前,我正在一个网格中循环,为每种瓷砖类型创建一组缓冲区,然后在draw方法中使用这些缓冲区。我想我不应该使用多组顶点缓冲区,但我不知道其他方法,因为每个瓷砖都是不同的纹理 网格环 for (int i = Convert.ToInt32(xPos / 2) - 30; i < Convert.ToInt32(xPos / 2) + 30; i++) {
for (int i = Convert.ToInt32(xPos / 2) - 30; i < Convert.ToInt32(xPos / 2) + 30; i++)
{
for (int a = Convert.ToInt32(yPos / 2); a < Convert.ToInt32(yPos / 2) + 50; a++)
{
if (mapXtile > 0 && mapYtile > 0 && mapXtile < Globals.mapsizex && mapYtile < Globals.mapsizey)
{
int currentTile = Globals.levelArray[level, mapXtile, mapYtile].TyleType;
if (currentTile == tyleType.grass)
{
createCubeVertices(i * 2, a * 2, 1, 0f, count, grassVertices);
SetUpBufferIndices(count, grassIndices);
count++;
}
if (currentTile == tyleType.water)
{
createCubeVertices(i * 2, a * 2, 1, 0f, count, waterVertices);
SetUpBufferIndices(count, waterIndices);
waterCount++;
}
}
mapYtile = mapYtile + 1;
//mapYtile++;
}
mapXtile = mapXtile + 1;
mapYtile = Convert.ToInt32(yPos / 2);
}
CopyToBuffers(grassVertices, grassIndices);
CopyToWaterBuffers(waterVertices, waterIndices);
非常感谢您的建议。如果您使用相同的效果绘制它们,您可以使用,并将所有基本体分组到一个唯一的vertexbuffer中,允许在一次调用中绘制所有基本体。您的选项:
foreach (EffectPass pass in grassEffect.CurrentTechnique.Passes)
{
pass.Apply();
device.Indices = myIndexBuffer;
device.SetVertexBuffer(myVertexBuffer);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, grassVertices.Length, 0, grassIndices.Length/3);
}
foreach (EffectPass pass in mouseEffect.CurrentTechnique.Passes)
{
pass.Apply();
device.Indices = myWaterIndexBuffer;
device.SetVertexBuffer(myWaterVertexBuffer);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 10000, 0, 10000);
}