/// <summary> /// Reloads the VertexBuffer for the TerrainPage. /// </summary> public void RefreshVertexBuffer_Page() { if (_page != null) { if (!_colorByHeight) { // Determine which list of vertices to build switch (_viewport.Device.DeviceCaps.MaxSimultaneousTextures) { case 0: BuildVertices_PositionNormal(); break; case 1: BuildVertices_PositionNormalTextured1(); break; case 2: BuildVertices_PositionNormalTextured2(); break; case 3: BuildVertices_PositionNormalTextured3(); break; case 4: BuildVertices_PositionNormalTextured4(); break; case 5: BuildVertices_PositionNormalTextured5(); break; case 6: BuildVertices_PositionNormalTextured6(); break; case 7: BuildVertices_PositionNormalTextured7(); break; case 8: default: BuildVertices_PositionNormalTextured8(); break; } } else { // Build non-textured vertex buffer GraphicsStream stream; int vertColor; D3D.CustomVertex.PositionNormalColored[] tri = new D3D.CustomVertex.PositionNormalColored[_page.TerrainPatch.NumVertices]; for (int i = 0; i < tri.Length; i++) { tri[i].Position = _page.TerrainPatch.Vertices[i].Position; tri[i].Normal = _page.TerrainPatch.Vertices[i].Normal; vertColor = (int)((tri[i].Position.Y / _page.MaximumVertexHeight) * 255.0f); tri[i].Color = Color.FromArgb(vertColor, vertColor, vertColor).ToArgb(); } if (_vbByHeight == null) { _vbByHeight = new D3D.VertexBuffer(typeof(D3D.CustomVertex.PositionNormalColored), tri.Length, _viewport.Device, D3D.Usage.Dynamic | D3D.Usage.WriteOnly, D3D.CustomVertex.PositionNormalColored.Format, D3D.Pool.Default); } stream = _vbByHeight.Lock(0, 0, D3D.LockFlags.Discard); stream.Write(tri); _vbByHeight.Unlock(); _vbSize = tri.Length; } _page.TerrainPatch.RefreshBuffers = false; } else { if (_vb != null) { if (!_vb.Disposed) { _vb.Dispose(); } _vb = null; _vbSize = 0; } if (_vbByHeight != null) { if (!_vbByHeight.Disposed) { _vbByHeight.Dispose(); } _vbByHeight = null; _vbSize = 0; } } }
/// <summary> /// Reloads the VertexBuffer for the TerrainPage. /// </summary> public void RefreshVertexBuffer_Page() { if ( _page != null ) { if ( !_colorByHeight ) { // Determine which list of vertices to build switch ( _viewport.Device.DeviceCaps.MaxSimultaneousTextures ) { case 0: BuildVertices_PositionNormal(); break; case 1: BuildVertices_PositionNormalTextured1(); break; case 2: BuildVertices_PositionNormalTextured2(); break; case 3: BuildVertices_PositionNormalTextured3(); break; case 4: BuildVertices_PositionNormalTextured4(); break; case 5: BuildVertices_PositionNormalTextured5(); break; case 6: BuildVertices_PositionNormalTextured6(); break; case 7: BuildVertices_PositionNormalTextured7(); break; case 8: default: BuildVertices_PositionNormalTextured8(); break; } } else { // Build non-textured vertex buffer GraphicsStream stream; int vertColor; D3D.CustomVertex.PositionNormalColored[] tri = new D3D.CustomVertex.PositionNormalColored[_page.TerrainPatch.NumVertices]; for ( int i = 0; i < tri.Length; i++ ) { tri[i].Position = _page.TerrainPatch.Vertices[i].Position; tri[i].Normal = _page.TerrainPatch.Vertices[i].Normal; vertColor = (int) ( ( tri[i].Position.Y / _page.MaximumVertexHeight ) * 255.0f ); tri[i].Color = Color.FromArgb( vertColor, vertColor, vertColor ).ToArgb(); } if ( _vbByHeight == null ) _vbByHeight = new D3D.VertexBuffer( typeof( D3D.CustomVertex.PositionNormalColored ), tri.Length, _viewport.Device, D3D.Usage.Dynamic | D3D.Usage.WriteOnly, D3D.CustomVertex.PositionNormalColored.Format, D3D.Pool.Default ); stream = _vbByHeight.Lock( 0, 0, D3D.LockFlags.Discard ); stream.Write( tri ); _vbByHeight.Unlock(); _vbSize = tri.Length; } _page.TerrainPatch.RefreshBuffers = false; } else { if ( _vb != null ) { if ( !_vb.Disposed ) _vb.Dispose(); _vb = null; _vbSize = 0; } if ( _vbByHeight != null ) { if ( !_vbByHeight.Disposed ) _vbByHeight.Dispose(); _vbByHeight = null; _vbSize = 0; } } }