在我们开始之前,先澄清一下您的思维方式。在 XNA 中 - 您绘制线框(轮廓)三角形、填充三角形或带纹理的三角形。没有任何“现在绘制”和“稍后填充”的内容。您只能在帧缓冲区中已有的内容之上绘制其他内容。
这里还有一些关于什么是索引网格的背景。这是馈入 DrawUserIndexedPrimitives 的数据(由顶点集的索引组成的顶点和三角形)。
鉴于此,以下是绘图调用的工作方式
_effect.Texture = texture; // This sets the texture up so the
// shaders associated with this effect can access it
// The color in each vertex is modulated with the texture color
// and linearly interpolated across vertices
_effect.VertexColorEnabled = true;
foreach (var pass in _effect.CurrentTechnique.Passes)
{
pass.Apply(); // This sets up the shaders and their state
// TriangleList means that the indices are understood to be
// multiples of 3, where the 3 vertices pointed to are comprise
// one triangle
_device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
// The vertices. Note that there can be any number of vertices in here.
// What's important is the indices array (and the vertexOffset, primitivecount, vertexCount) that determine
// how many of the provided vertices will actually matter for this draw call
_vertices,
// The offset to the first vertex that the index 0 in the index array will refer to
// This is used to render a "part" of a bigger set of vertices, perhaps shared across
// different objects
0,
// The number of vertices to pick starting from vertexOffset. If the index array
// tried to index a vertex out of this range then the draw call will fail.
_vertices.Count,
// The indices (count = multiple of 3) that comprise separate triangle (because we said TriangleList -
// the rules are different depending on the primitive type)
_indices,
// Again, an offset inside the indices array so a part of a larger index array can be used
0,
// Number of indices. This HAS to be a multiple of 3 because we said we're rendering
// a list of triangles (TrangleList).
kvp.Value.Indices.Count / 3);
}
我希望这很清楚。如果您对每个参数和/或概念有任何具体问题,请告诉我,我可以编辑这篇文章以澄清这些观点。
希望这可以帮助!