Exemplo n.º 1
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    Gorgon.RemoveTrackedObject(this);

                    // Destroy any outstanding device instances.
                    DestroyDevices();
                }
            }

            _disposed = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                Gorgon.Log.Print("Gorgon Graphics Context shutting down...", LoggingLevel.Simple);

                if (!IsDeferred)
                {
                    _trackedObjects.ReleaseAll();
                }
                else
                {
                    Context.ClearState();
                }

                DestroyInterfaces();

                // Only clean up the context if the context is deferred.
                if (IsDeferred)
                {
                    if (_commands != null)
                    {
                        // Release any outstanding command lists.
                        while (_commands.Count > 0)
                        {
                            ReleaseCommands(_commands[_commands.Count - 1]);
                        }
                    }

                    if (Context != null)
                    {
                        Context.Flush();
                        Context.Dispose();
                    }

                    Context = null;

                    // Remove us from object tracking.
                    ImmediateContext.RemoveTrackedObject(this);
                }
                else
                {
                    Gorgon.Log.Print("Removing D3D11 Device object...", LoggingLevel.Verbose);

                    // Destroy the video device interface.
                    if (D3DDevice != null)
                    {
                        D3DDevice.Dispose();
                        D3DDevice = null;
                    }

                    if (Adapter != null)
                    {
                        Adapter.Dispose();
                        Adapter = null;
                    }

                    if (GIFactory != null)
                    {
                        GIFactory.Dispose();
                        GIFactory = null;
                    }

                    if (VideoDevice != null)
                    {
                        VideoDevice.Graphics = null;
                    }

                    Gorgon.Log.Print("Removing DXGI factory interface...", LoggingLevel.Verbose);
                    if (GIFactory != null)
                    {
                        GIFactory.Dispose();
                        GIFactory = null;
                    }

                    // Remove us from the object tracker.
                    Gorgon.RemoveTrackedObject(this);
                }

                Gorgon.Log.Print("Gorgon Graphics Context shut down successfully", LoggingLevel.Simple);
            }

            _disposed = true;
        }