コード例 #1
0
        /// <summary>
        /// Function to initialize the example and prepare the required components.
        /// </summary>
        private static void Initialize()
        {
            // We will need to access the graphics device in order to use compute functionality, so we'll use the first usable device in the system.
            // Find out which devices we have installed in the system.
            IReadOnlyList <IGorgonVideoAdapterInfo> deviceList = GorgonGraphics.EnumerateAdapters();

            Console.WriteLine("Enumerating video devices...");

            IGorgonVideoAdapterInfo firstDevice = deviceList.FirstOrDefault(item => item.FeatureSet >= FeatureSet.Level_12_0);

            // If a device with a feature set of at least 12.0 not found, then we cannot run this example. The compute engine requires a minimum
            // of feature level 12.0 to run.
            if (firstDevice == null)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("No Level 12.0 or better adapters found in the system. This example requires a FeatureLevel 12.0 or better adapter.");
                Console.ResetColor();
                return;
            }

            Console.WriteLine($"Using the '{firstDevice.Name}' video device.\n");

            // We have to create a graphics interface to allow the compute engine to communicate with the GPU.
            _graphics = new GorgonGraphics(firstDevice);

            // We will also need to compile a compute shader so we can actually perform the work.
            Console.WriteLine("Compiling the compute shader (SimpleCompute)...");
            _computeShader = GorgonShaderFactory.Compile <GorgonComputeShader>(_graphics, Resources.ComputeShader, "SimpleCompute");

            // Finally, the star of the show, the compute engine.
            Console.WriteLine("Creating compute engine...");
            _engine = new GorgonComputeEngine(_graphics);
        }
コード例 #2
0
        /// <summary>
        /// Function to create the primary graphics interface.
        /// </summary>
        /// <returns>A new graphics interface, or <b>null</b> if a suitable video device was not found on the system.</returns>
        /// <remarks>
        /// <para>
        /// This method will create a new graphics interface for our application to use. It will select the video device with the most suitable depth buffer available, and if it cannot find a suitable
        /// device, it will indicate that by returning <b>null</b>.
        /// </para>
        /// </remarks>
        private static GorgonGraphics CreateGraphicsInterface()
        {
            GorgonGraphics graphics = null;

            BufferFormat[] depthFormats =
            {
                BufferFormat.D32_Float,
                BufferFormat.D32_Float_S8X24_UInt,
                BufferFormat.D24_UNorm_S8_UInt,
                BufferFormat.D16_UNorm
            };

            // Find out which devices we have installed in the system.
            IReadOnlyList <IGorgonVideoAdapterInfo> deviceList = GorgonGraphics.EnumerateAdapters();

            if (deviceList.Count == 0)
            {
                GorgonDialogs.ErrorBox(_mainForm, "There are no suitable video adapters available in the system. This example is unable to continue and will now exit.");
                return(null);
            }

            int depthFormatIndex    = 0;
            int selectedDeviceIndex = 0;
            IGorgonVideoAdapterInfo selectedDevice = null;

            _selectedVideoMode = new GorgonVideoMode(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height, BufferFormat.R8G8B8A8_UNorm);

            while (selectedDeviceIndex < deviceList.Count)
            {
                // Reset back to a 32 bit floating point depth.
                _depthFormat = depthFormats[depthFormatIndex++];

                // Destroy the previous interface.
                graphics?.Dispose();

                // Create the main graphics interface.
                graphics = new GorgonGraphics(deviceList[selectedDeviceIndex++]);

                // Validate depth buffer for this device.
                // Odds are good that if this fails, you should probably invest in a better video card.  Preferably something created after 2005.
                if (!graphics.FormatSupport[_depthFormat].IsDepthBufferFormat)
                {
                    continue;
                }

                selectedDevice = graphics.VideoAdapter;
                break;
            }

            // If, somehow, we are on a device from the dark ages, then we can't continue.
            if (selectedDevice != null)
            {
                return(graphics);
            }

            GorgonDialogs.ErrorBox(_mainForm, $"The selected video device ('{deviceList[0].Name}') does not support a 32, 24 or 16 bit depth buffer.");
            return(null);
        }
コード例 #3
0
 /// <summary>Initializes a new instance of the <see cref="T:Gorgon.Editor.ImageEditor.ViewModels.DimensionSettingsParameters"/> class.</summary>
 /// <param name="videoAdapter">The video adapter.</param>
 /// <param name="commonServices">Common application services.</param>
 /// <exception cref="ArgumentNullException">Thrown when any parameter is <b>null</b>.</exception>
 public DimensionSettingsParameters(IGorgonVideoAdapterInfo videoAdapter, IViewModelInjection commonServices)
     : base(commonServices) => VideoAdapter = videoAdapter ?? throw new ArgumentNullException(nameof(videoAdapter));