コード例 #1
0
ファイル: GorgonGraphics.cs プロジェクト: tmp7701/Gorgon
        /// <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 convert a Gorgon feature level into a D3D feature level.
        /// </summary>
        /// <param name="featureLevel">Feature level to convert.</param>
        /// <returns>The D3D feature level.</returns>
        private D3DCommon.FeatureLevel[] GetFeatureLevel(DeviceFeatureLevel featureLevel)
        {
            if (HardwareFeatureLevel < featureLevel)
            {
                featureLevel = HardwareFeatureLevel;
            }

            SupportedFeatureLevel = featureLevel;

            switch (featureLevel)
            {
            case DeviceFeatureLevel.SM5:
                return(new[] {
                    D3DCommon.FeatureLevel.Level_11_0,
                    D3DCommon.FeatureLevel.Level_10_1,
                    D3DCommon.FeatureLevel.Level_10_0,
                    D3DCommon.FeatureLevel.Level_9_3,
                    D3DCommon.FeatureLevel.Level_9_2,
                    D3DCommon.FeatureLevel.Level_9_1
                });

            case DeviceFeatureLevel.SM4_1:
                return(new[] {
                    D3DCommon.FeatureLevel.Level_10_1,
                    D3DCommon.FeatureLevel.Level_10_0,
                    D3DCommon.FeatureLevel.Level_9_3,
                    D3DCommon.FeatureLevel.Level_9_2,
                    D3DCommon.FeatureLevel.Level_9_1
                });

            case DeviceFeatureLevel.SM4:
                return(new[] {
                    D3DCommon.FeatureLevel.Level_10_0,
                    D3DCommon.FeatureLevel.Level_9_3,
                    D3DCommon.FeatureLevel.Level_9_2,
                    D3DCommon.FeatureLevel.Level_9_1
                });

            default:
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_DEVICE_CANNOT_FIND_DEVICES);
            }
        }
コード例 #3
0
ファイル: GorgonGraphics.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Initializes the <see cref="GorgonGraphics"/> class.
 /// </summary>
 /// <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 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>If a feature level is not supported by the hardware, then Gorgon will not use that feature level.</para>
 /// </remarks>
 public GorgonGraphics(DeviceFeatureLevel featureLevel)
     : this(null, featureLevel)
 {
 }
コード例 #4
0
        /// <summary>
        /// Function to return a device object for this video device.
        /// </summary>
        /// <returns>The new device object, adapter and factory.</returns>
        internal Tuple <GI.Factory1, GI.Adapter1, D3D.Device> GetDevice(VideoDeviceType deviceType, DeviceFeatureLevel featureLevel)
        {
            GI.Factory1 factory;
            GI.Adapter1 adapter;
            D3D.Device  device;

            switch (deviceType)
            {
#if DEBUG
            case VideoDeviceType.ReferenceRasterizer:
                device = new D3D.Device(D3DCommon.DriverType.Reference,
                                        D3D.DeviceCreationFlags.Debug,
                                        D3DCommon.FeatureLevel.Level_11_0)
                {
                    DebugName = string.Format("{0} D3D11 Device", Name)
                };

                using (var giDevice = device.QueryInterface <GI.Device1>())
                {
                    adapter = giDevice.GetParent <GI.Adapter1>();   //giDevice.Adapter;
                    factory = adapter.GetParent <GI.Factory1>();
                }
                break;
#endif
            case VideoDeviceType.Software:
                // WARP devices can only do SM4_1 or lower.
                if (featureLevel >= DeviceFeatureLevel.SM5)
                {
                    featureLevel = DeviceFeatureLevel.SM4_1;
                }
#if DEBUG
                device = new D3D.Device(D3DCommon.DriverType.Warp,
                                        D3D.DeviceCreationFlags.Debug,
                                        GetFeatureLevel(featureLevel))
                {
                    DebugName = string.Format("{0} D3D11 Device", Name)
                };
#else
                device = new D3D.Device(D3DCommon.DriverType.Warp,
                                        D3D.DeviceCreationFlags.None,
                                        GetFeatureLevel(featureLevel));
#endif
                using (var giDevice = device.QueryInterface <GI.Device1>())
                {
                    adapter = giDevice.GetParent <GI.Adapter1>();
                    factory = adapter.GetParent <GI.Factory1>();
                }
                break;

            default:
                factory = new GI.Factory1();
                adapter = factory.GetAdapter1(Index);
#if DEBUG
                device = new D3D.Device(adapter,
                                        D3D.DeviceCreationFlags.Debug,
                                        GetFeatureLevel(featureLevel))
                {
                    DebugName = string.Format("{0} D3D11 Device", Name)
                };
#else
                device = new D3D.Device(adapter, D3D.DeviceCreationFlags.None, GetFeatureLevel(HardwareFeatureLevel));
#endif
                break;
            }

            return(new Tuple <GI.Factory1, GI.Adapter1, D3D.Device>(factory, adapter, device));
        }