public void BindToDevice(GraphicsDevice device)
        {
            lock (syncRoot)
            {
                AssertNotDisposed();
                AssertNotLocked();

                if (locality == GraphicsLocality.SystemMemoryOnly)
                {
                    throw new InvalidOperationException("System memory buffer cannot be bound to device.");
                }

                if (driverPart == null)
                {
                    this.device = device;
                    driverPart  = device.DriverDevice.CreateBuffer(bufferUsage,
                                                                   usage, cpuAccess, byteSize, swData);

                    if (locality == GraphicsLocality.DeviceOrSystemMemory ||
                        locality == GraphicsLocality.DeviceMemoryOnly)
                    {
                        // Release RAM copy.
                        swData = null;
                    }
                }
            }
        }
        private void Dispose(bool finalizer)
        {
            if (cacheableState == CacheableState.Disposed)
            {
                return;
            }


            cacheableState = CacheableState.Disposed;
            device         = null;
            if (driverPart != null)
            {
                driverPart.Dispose();
                driverPart = null;
            }

            // To free asocaited data (if buffer still referenced).
            swData = null;

            if (!finalizer)
            {
                GC.SuppressFinalize(this);
            }


            Action <IResource> t = onDisposed;

            if (t != null)
            {
                t(this);
            }
        }
 private void ReleaseDriverPart()
 {
     if (driverPart != null)
     {
         driverPart.Dispose();
         driverPart = null;
     }
 }