MeLLe
2004-08-24, 21:28:26
Hallo ihrs ;)
hab ein kleines Problemchen. Eigentlich wollte ich nur "fix mal" eine kleine Terrain-Rendering-Studie betreiben, und mit der Verwendung von Vertex-Buffers klappts auch ganz gut. Nun wollt ich mal sehen, wie das mit Index-Buffers klappt, schon alleine wegen LODing, was ich später dann angedacht habe. Aber selbst der simpelste Code bringt DX zum würgen ...
Schaut her:
Const MAP_SIZE = 1024
Const TILING_TERRAIN = 16
Private iIndexCount As Long = 0
Private vbTerrain As VertexBuffer
Private ibTerrain As IndexBuffer
[...]
Dim X, Z As Long
vbTerrain = New VertexBuffer(GetType(CustomVertex.PositionTextured), MAP_SIZE * MAP_SIZE, D3DDev, 0, CustomVertex.PositionTextured.Format, Pool.Managed)
Dim vTerrain As CustomVertex.PositionTextured() = CType(vbTerrain.Lock(0, 0), CustomVertex.PositionTextured())
For X = 0 To MAP_SIZE - 1
For Z = 0 To MAP_SIZE - 1
vTerrain(X + Z * MAP_SIZE) = New CustomVertex.PositionTextured(X, Height(gHeightMap, X, Z), Z, TILING_TERRAIN * X / (Floor(MAP_SIZE / STEP_SIZE) * STEP_SIZE - STEP_SIZE), TILING_TERRAIN * Z / (Floor(MAP_SIZE / STEP_SIZE) * STEP_SIZE - STEP_SIZE))
Next
Next
vbTerrain.Unlock()
ibTerrain = New IndexBuffer(GetType(Integer), (MAP_SIZE - 1) * (MAP_SIZE - 1) * 2 * 2 * 3, D3DDev, 0, Pool.Managed)
Dim iTerrain As Integer() = CType(ibTerrain.Lock(0, 0), Integer())
For X = 0 To MAP_SIZE - 1 - 1
For Z = 0 To MAP_SIZE - 1 - 1
iTerrain((X + Z * (MAP_SIZE - 1)) * 6) = (X + 1) + (Z + 1) * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 1) = (X + 1) + Z * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 2) = X + Z * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 3) = (X + 1) + (Z + 1) * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 4) = X + Z * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 5) = X + (Z + 1) * MAP_SIZE
iIndexCount += 6
Next
Next
ibTerrain.Unlock()
[...]
D3DDev.SetStreamSource(0, vbTerrain, 0)
D3DDev.VertexFormat = CustomVertex.PositionTextured.Format
D3DDev.Indices = ibTerrain
D3DDev.SetTexture(0, texTerrain)
D3DDev.Transform.World = matTerrain
D3DDev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, MAP_SIZE * MAP_SIZE, 0, iIndexCount / 3)
Und genau in der letzten Zeile steigt die Anwendung mit einem "unknown error" aus.
Warum?
hab ein kleines Problemchen. Eigentlich wollte ich nur "fix mal" eine kleine Terrain-Rendering-Studie betreiben, und mit der Verwendung von Vertex-Buffers klappts auch ganz gut. Nun wollt ich mal sehen, wie das mit Index-Buffers klappt, schon alleine wegen LODing, was ich später dann angedacht habe. Aber selbst der simpelste Code bringt DX zum würgen ...
Schaut her:
Const MAP_SIZE = 1024
Const TILING_TERRAIN = 16
Private iIndexCount As Long = 0
Private vbTerrain As VertexBuffer
Private ibTerrain As IndexBuffer
[...]
Dim X, Z As Long
vbTerrain = New VertexBuffer(GetType(CustomVertex.PositionTextured), MAP_SIZE * MAP_SIZE, D3DDev, 0, CustomVertex.PositionTextured.Format, Pool.Managed)
Dim vTerrain As CustomVertex.PositionTextured() = CType(vbTerrain.Lock(0, 0), CustomVertex.PositionTextured())
For X = 0 To MAP_SIZE - 1
For Z = 0 To MAP_SIZE - 1
vTerrain(X + Z * MAP_SIZE) = New CustomVertex.PositionTextured(X, Height(gHeightMap, X, Z), Z, TILING_TERRAIN * X / (Floor(MAP_SIZE / STEP_SIZE) * STEP_SIZE - STEP_SIZE), TILING_TERRAIN * Z / (Floor(MAP_SIZE / STEP_SIZE) * STEP_SIZE - STEP_SIZE))
Next
Next
vbTerrain.Unlock()
ibTerrain = New IndexBuffer(GetType(Integer), (MAP_SIZE - 1) * (MAP_SIZE - 1) * 2 * 2 * 3, D3DDev, 0, Pool.Managed)
Dim iTerrain As Integer() = CType(ibTerrain.Lock(0, 0), Integer())
For X = 0 To MAP_SIZE - 1 - 1
For Z = 0 To MAP_SIZE - 1 - 1
iTerrain((X + Z * (MAP_SIZE - 1)) * 6) = (X + 1) + (Z + 1) * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 1) = (X + 1) + Z * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 2) = X + Z * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 3) = (X + 1) + (Z + 1) * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 4) = X + Z * MAP_SIZE
iTerrain((X + Z * (MAP_SIZE - 1)) * 6 + 5) = X + (Z + 1) * MAP_SIZE
iIndexCount += 6
Next
Next
ibTerrain.Unlock()
[...]
D3DDev.SetStreamSource(0, vbTerrain, 0)
D3DDev.VertexFormat = CustomVertex.PositionTextured.Format
D3DDev.Indices = ibTerrain
D3DDev.SetTexture(0, texTerrain)
D3DDev.Transform.World = matTerrain
D3DDev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, MAP_SIZE * MAP_SIZE, 0, iIndexCount / 3)
Und genau in der letzten Zeile steigt die Anwendung mit einem "unknown error" aus.
Warum?