public Result CreateParticles() { try { ReleaseCom(_vb); _vb = new VertexBuffer(_device, _hm.Size.X * _hm.Size.Y * Particle.Size, Usage.Dynamic | Usage.Points | Usage.WriteOnly, Particle.FVF, Pool.Default); var ds = _vb.Lock(0, 0, LockFlags.Discard); for (var y = 0; y < _hm.Size.Y; y++) { for (var x = 0; x < _hm.Size.X; x++) { var prc = _hm[x + y * _hm.Size.X] / _hm.MaxHeight; //Debug.Print("prc: {0}", prc); var red = prc; var green = 1.0f - prc; bool contains = false; if (Editor != null) { contains = x >= Editor.SelectionRect.Left && x <= Editor.SelectionRect.Right && y >= Editor.SelectionRect.Top && y <= Editor.SelectionRect.Bottom; } var v = new Particle { Position = new Vector3(x, _hm[x + y * _hm.Size.X], -y), Color = (ShowSelection && contains) ? new Color4(1.0f, 0, 0, 1.0f).ToArgb() : new Color4(1.0f, red, green, 0.0f).ToArgb() }; ds.Write(v); } } _vb.Unlock(); } catch (Exception ex) { Debug.Print("Error in {0} - {1}\n{2}", ex.TargetSite, ex.Message, ex.StackTrace); return ResultCode.Failure; } return ResultCode.Success; }
private void BuildVB(Device device) { var vbd = new BufferDescription( Particle.Stride, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); var p = new Particle { Age = 0, Type = 0 }; _initVB = new Buffer(device, new DataStream(new[] { p }, true, true), vbd); vbd.SizeInBytes = Particle.Stride * _maxParticles; vbd.BindFlags = BindFlags.VertexBuffer | BindFlags.StreamOutput; _drawVB = new Buffer(device, vbd); _streamOutVB = new Buffer(device, vbd); }