Example #1
0
        public void Initialize(GraphicsContext context)
        {
            _vertexBuffer?.Dispose();

            _context = context;
            LoadShader();
            CreateGrid();
        }
Example #2
0
 public void Dispose()
 {
     if (VertexBuffer != null)
     {
         VertexBuffer.Dispose();
         VertexBuffer = null;
     }
     if (IndexBuffer != null)
     {
         IndexBuffer.Dispose();
         IndexBuffer = null;
     }
     if (InstanceDataBuffer != null)
     {
         InstanceDataBuffer.Dispose();
         InstanceDataBuffer = null;
     }
 }
Example #3
0
        // Used with soft bodies
        public void SetDynamicVertexBuffer(Device device, Vector3[] vectors)
        {
            if (VertexBuffer != null && VertexCount * 2 == vectors.Length)
            {
                // Update existing buffer
                using (var data = VertexBuffer.Map(MapMode.WriteDiscard))
                {
                    data.WriteRange(vectors, 0, vectors.Length);
                    VertexBuffer.Unmap();
                }
            }
            else
            {
                // Create new buffer
                if (VertexBuffer != null)
                {
                    VertexBuffer.Dispose();
                }

                BufferDescription vertexBufferDesc = new BufferDescription()
                {
                    SizeInBytes    = Vector3.SizeInBytes * vectors.Length,
                    Usage          = ResourceUsage.Dynamic,
                    BindFlags      = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write
                };

                using (var data = new DataStream(vertexBufferDesc.SizeInBytes, false, true))
                {
                    data.WriteRange(vectors);
                    data.Position = 0;
                    VertexBuffer  = new Buffer(device, data, vertexBufferDesc);
                }

                VertexCount       = vectors.Length / 2;
                BufferBindings[0] = new VertexBufferBinding(VertexBuffer, 24, 0);
            }
        }
Example #4
0
        void releaseDirect3D()
        {
            if (_vertexBuffer != null)
            {
                _vertexBuffer.Dispose();
            }
            if (_indexBuffer != null)
            {
                _indexBuffer.Dispose();
            }
            if (_texture != null)
            {
                _texture.Dispose();
            }

            if (_surfaceVertexBuffer != null)
            {
                _surfaceVertexBuffer.Dispose();
            }
            if (_surfaceIndexBuffer != null)
            {
                _surfaceIndexBuffer.Dispose();
            }
            if (_background != null)
            {
                _background.Dispose();
            }

            if (_effect != null)
            {
                _effect.Dispose();
            }
            if (_device != null)
            {
                _device.Dispose();
            }
        }