我有生以来第一次看到 XNA,我对我读到的例子感到困惑。它们包含一个我不明白的重复:
protected override void LoadContent()
{
_verts1 = new VertexPositionTexture[6];
_vertexBuffer1 = new VertexBuffer(
GraphicsDevice,
typeof(VertexPositionTexture),
_verts1.Length,
BufferUsage.None);
_vertexBuffer1.SetData(_verts1);
...
}
protected override void Draw(GameTime gameTime)
{
...
GraphicsDevice.SetVertexBuffer(_vertexBuffer1);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(
PrimitiveType.TriangleStrip,
_verts1,
0,
4);
}
...
}
我不明白为什么在绘图方法中同时使用 VertexBuffer 和 VertexPositionTexture。保留 VertexBuffer 还不够吗?
如果我删除对 GraphicsDevice.SetVertexBuffer 的调用并仅依赖 GraphicsDevice.DrawUserPrimitives - 一切看起来都一样!那么:当我只使用 VertexPositionTexture[] 就可以相处时,拥有 VertexBuffer 有什么意义呢?:-)
(我敢肯定这是一个重点——请帮我看看!!!:)
问题解决了:蹩脚的 XNA 书!谢谢@dowhilefor