Пример #1
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
            {
                return;
            }

            inputAssembler.InputLayout = inputLayout;

            if (lineArray.Length != lines.Count)
            {
                lineArray = new PositionColored[lines.Count];
                lines.CopyTo(lineArray);

                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                }
                vertexBufferDesc.SizeInBytes = PositionColored.Stride * lines.Count;
                using (var data = new DataStream(vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(lineArray);
                    data.Position = 0;
                    vertexBuffer  = new Buffer(device, data, vertexBufferDesc);
                }
                vertexBufferBinding.Buffer = vertexBuffer;
            }
            else
            {
                lines.CopyTo(lineArray);
                using (var map = vertexBuffer.Map(MapMode.WriteDiscard))
                {
                    map.WriteRange(lineArray);
                }
                vertexBuffer.Unmap();
            }

            inputAssembler.SetVertexBuffers(0, vertexBufferBinding);
            inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            device.Draw(lines.Count, 0);

            lines.Clear();
        }
Пример #2
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
                return;

            inputAssembler.InputLayout = inputLayout;

            if (lineArray.Length != lines.Count)
            {
                lineArray = new PositionColored[lines.Count];
                lines.CopyTo(lineArray);

                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                }
                vertexBufferDesc.SizeInBytes = PositionColored.Stride * lines.Count;
                using (var data = new DataStream(vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(lineArray);
                    data.Position = 0;
                    vertexBuffer = new Buffer(device, data, vertexBufferDesc);
                }
                vertexBufferBinding.Buffer = vertexBuffer;
            }
            else
            {
                lines.CopyTo(lineArray);
                DataStream data;
                device.ImmediateContext.MapSubresource(vertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out data);
                data.WriteRange(lineArray);
                device.ImmediateContext.UnmapSubresource(vertexBuffer, 0);
                data.Dispose();
            }

            inputAssembler.SetVertexBuffers(0, vertexBufferBinding);
            inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            device.ImmediateContext.Draw(lines.Count, 0);

            lines.Clear();
        }
        /*
         * protected override void Dispose(bool disposing)
         * {
         *  if (disposing)
         *  {
         *      if (vertexBuffer != null)
         *      {
         *          vertexBuffer.Dispose();
         *          vertexBuffer = null;
         *      }
         *  }
         *
         *  base.Dispose(disposing);
         * }
         */
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (LineIndex == 0)
            {
                return;
            }

            _inputAssembler.InputLayout = _inputLayout;

            if (_vertexCount != LineIndex)
            {
                if (_vertexBuffer != null)
                {
                    _vertexBuffer.Dispose();
                }
                _vertexCount = LineIndex;
                _vertexBufferDesc.SizeInBytes = PositionColored.Stride * _vertexCount;
                using (var data = new DataStream(_vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(Lines, 0, _vertexCount);
                    data.Position = 0;
                    _vertexBuffer = new Buffer(_device, data, _vertexBufferDesc);
                }
                _vertexBufferBinding.Buffer = _vertexBuffer;
            }
            else
            {
                using (var map = _vertexBuffer.Map(MapMode.WriteDiscard))
                {
                    map.WriteRange(Lines, 0, _vertexCount);
                }
                _vertexBuffer.Unmap();
            }

            _inputAssembler.SetVertexBuffers(0, _vertexBufferBinding);
            _inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            _device.Draw(_vertexCount, 0);

            LineIndex = 0;
        }
        /*
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                    vertexBuffer = null;
                }
            }

            base.Dispose(disposing);
        }
        */
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (LineIndex == 0)
                return;

            _inputAssembler.InputLayout = _inputLayout;

            if (_vertexCount != LineIndex)
            {
                if (_vertexBuffer != null)
                {
                    _vertexBuffer.Dispose();
                }
                _vertexCount = LineIndex;
                _vertexBufferDesc.SizeInBytes = PositionColored.Stride * _vertexCount;
                using (var data = new DataStream(_vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(Lines, 0, _vertexCount);
                    data.Position = 0;
                    _vertexBuffer = new Buffer(_device, data, _vertexBufferDesc);
                }
                _vertexBufferBinding.Buffer = _vertexBuffer;
            }
            else
            {
                using (var map = _vertexBuffer.Map(MapMode.WriteDiscard))
                {
                    map.WriteRange(Lines, 0, _vertexCount);
                }
                _vertexBuffer.Unmap();
            }

            _inputAssembler.SetVertexBuffers(0, _vertexBufferBinding);
            _inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            _device.Draw(_vertexCount, 0);

            LineIndex = 0;
        }
        /*
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                    vertexBuffer = null;
                }
            }

            base.Dispose(disposing);
        }
        */
        public void DrawDebugWorld(CollisionWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
                return;

            inputAssembler.InputLayout = inputLayout;

            if (lineArray.Length != lines.Count)
            {
                lineArray = new PositionColored[lines.Count];
                lines.CopyTo(lineArray);

                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                }
                vertexBufferDesc.SizeInBytes = PositionColored.Stride * lines.Count;
                using (var data = new DataStream(vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(lineArray);
                    data.Position = 0;
                    vertexBuffer = new Buffer(device, data, vertexBufferDesc);
                }
                vertexBufferBinding.Buffer = vertexBuffer;
            }
            else
            {
                lines.CopyTo(lineArray);
                using (var map = vertexBuffer.Map(MapMode.WriteDiscard))
                {
                    map.WriteRange(lineArray);
                }
                vertexBuffer.Unmap();
            }

            inputAssembler.SetVertexBuffers(0, vertexBufferBinding);
            inputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.LineList;

            device.Draw(lines.Count, 0);

            lines.Clear();
        }