管理Direct3DX网格顶点/索引限制?

时间:2011-01-13 12:07:51

标签: c# directx rendering mesh vertex

我有一些生成景观的代码,将其转换为网格然后呈现它。

横向基于三维表,每个正表条目生成4个顶点。我在开始时定义了表格大小。

问题在于

Mesh mesh = new Mesh(indexes.Count/3,vertexes.Count, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, device);

其中index是索引和顶点的短路数组,是一个包含顶点的CustomVertex.PositionNormalTextured数组。

我的代码适用于小尺寸(例如32x32x32),但对于像64x64x64这样的东西,它会在上面一行崩溃并出现以下错误

Microsoft.DirectX.Direct3D.Direct3DXException was unhandled
Message=Error in the application.
Source=Microsoft.DirectX.Direct3DX
ErrorCode=-2005530516
ErrorString=D3DERR_INVALIDCALL
StackTrace:
   at Microsoft.DirectX.Direct3D.Mesh..ctor(Int32 numFaces, Int32 numVertices, MeshFlags options, VertexFormats vertexFormat, Device device)
   at mycode.Form1.Landscape() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 488
   at mycode.Form1.GenerateGeometry() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 223
   at mycode.Form1..ctor() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 40
   at mycode.Program.Main() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

在崩溃时,索引的计数为231,480,顶点的计数为154,320

最好将它分成64个网格,每个Z级别一个?

1 个答案:

答案 0 :(得分:0)

听起来你的网格默认为16位索引缓冲区。我找不到Managed DirectX的文档了(MS在任何地方都删除了它),但看看你是否可以明确告诉它使用32位索引缓冲区。