Пример #1
0
        /// <summary>
        /// Initializes the <see cref="GorgonGraphics"/> class.
        /// </summary>
        /// <param name="device">Video device to use.</param>
        /// <param name="featureLevel">The maximum feature level to support for the devices enumerated.</param>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="featureLevel"/> parameter is invalid.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when Gorgon could not find any video devices that are Shader Model 5, or the down level interfaces (Shader Model 4, and lesser).
        /// <para>-or-</para>
        /// <para>Thrown if the operating system version is not supported.  Gorgon Graphics requires at least Windows Vista Service Pack 2 or higher.</para>
        /// </exception>
        /// <remarks>
        /// The <paramref name="device"/> parameter is the video device that should be used with Gorgon.  If the user passes NULL (Nothing in VB.Net), then the primary device will be used.
        /// To determine the devices on the system, check the <see cref="GorgonLibrary.Graphics.GorgonVideoDeviceEnumerator">GorgonVideoDeviceEnumerator</see> class.  The primary device will be the first device in this collection.
        /// <para>The user may pass in a feature level to the featureLevel parameter to limit the feature levels available.  Note that the feature levels imply all feature levels up until the feature level passed in, for example, passing <c>DeviceFeatureLevel.SM4</c> will only allow functionality
        /// for both Shader Model 4, and Shader Model 2/3 capable video devices, while DeviceFeatureLevel.SM4_1 will include Shader Model 4 with a 4.1 profile and Shader model 2/3 video devices.</para>
        /// <para>If a feature level is not supported by the hardware, then Gorgon will not use that feature level.  That is, passing a SM5 feature level with a SM4 card will only use a SM4 feature level.  If the user omits the feature level (in one of the constructor
        /// overloads), then Gorgon will use the best available feature level for the video device being used.</para>
        /// </remarks>
        public GorgonGraphics(GorgonVideoDevice device, DeviceFeatureLevel featureLevel)
        {
            ResetFullscreenOnFocus = true;
            ImmediateContext       = this;

            if (featureLevel == DeviceFeatureLevel.Unsupported)
            {
                throw new ArgumentException(Resources.GORGFX_FEATURE_LEVEL_UNKNOWN);
            }

            if (GorgonComputerInfo.OperatingSystemVersion.Major < 6)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_INVALID_OS);
            }

            Gorgon.Log.Print("Gorgon Graphics initializing...", LoggingLevel.Simple);

            // Track our objects.
            _trackedObjects = new GorgonDisposableObjectCollection();

#if DEBUG
            if (!SharpDX.Configuration.EnableObjectTracking)
            {
                SharpDX.Configuration.EnableObjectTracking = true;
            }
#else
            SharpDX.Configuration.EnableObjectTracking = false;
#endif

            if (device == null)
            {
                if (GorgonVideoDeviceEnumerator.VideoDevices.Count == 0)
                {
                    GorgonVideoDeviceEnumerator.Enumerate(false, false);
                }

                // Use the first device in the list.
                device = GorgonVideoDeviceEnumerator.VideoDevices[0];
            }

            VideoDevice = device;

            var D3DDeviceData = VideoDevice.GetDevice(VideoDevice.VideoDeviceType, featureLevel);

            // Create the DXGI factory for the video device.
            GIFactory = D3DDeviceData.Item1;
            Adapter   = D3DDeviceData.Item2;
            D3DDevice = D3DDeviceData.Item3;

            Context = D3DDevice.ImmediateContext;
            Context.ClearState();
            VideoDevice.Graphics = ImmediateContext;

            CreateStates();

            Gorgon.AddTrackedObject(this);

            Gorgon.Log.Print("Gorgon Graphics initialized.", LoggingLevel.Simple);
        }
Пример #2
0
        /// <summary>
        /// Function to return a new input device factory object.
        /// </summary>
        /// <param name="plugInType">Type name of the input device factory plug-in.</param>
        /// <returns>The input device factory object.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="plugInType"/> parameter was NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="plugInType"/> parameter is empty.</exception>
        /// <exception cref="System.InvalidCastException">Thrown when the input plug-in was not found or was not the correct type.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the input factory could not be created.</exception>
        public static GorgonInputFactory CreateInputFactory(string plugInType)
        {
            if (plugInType == null)
            {
                throw new ArgumentNullException("plugInType");
            }

            if (string.IsNullOrWhiteSpace(plugInType))
            {
                throw new ArgumentException(Resources.GORINP_PARAMETER_EMPTY, "plugInType");
            }

            var plugIn =
                Gorgon.PlugIns.FirstOrDefault(
                    item => string.Equals(item.Name, plugInType, StringComparison.OrdinalIgnoreCase)) as
                GorgonInputPlugIn;

            if (plugIn == null)
            {
                throw new InvalidCastException(string.Format(Resources.GORINP_PLUGIN_NOT_FOUND, plugInType));
            }

            GorgonInputFactory factory = plugIn.GetFactory();

            if (factory == null)
            {
                throw new GorgonException(GorgonResult.CannotCreate,
                                          string.Format(Resources.GORINP_CANNOT_CREATE, plugInType));
            }

            // Enumerate the devices.
            factory.EnumerateDevices();

            Gorgon.AddTrackedObject(factory);

            return(factory);
        }