Example #1
0
        public ReturnSet <bool> Initialize(Logger logger)
        {
            try
            {
                var instanceCreationResult = VulkanInstance.Create();

                if (instanceCreationResult.IsError)
                {
                    throw instanceCreationResult.Error;
                }

                _instance = instanceCreationResult.Value;

                logger.AddMessage("Instance created successfully");

                var surfaceCreationResult = VulkanSurface.Create(_instance, _form);

                if (surfaceCreationResult.IsError)
                {
                    throw surfaceCreationResult.Error;
                }

                _surface = surfaceCreationResult.Value;

                logger.AddMessage("Surface created successfully");

                return(new ReturnSet <bool>(true));
            }
            catch (Exception ex)
            {
                return(new ReturnSet <bool>(ex));
            }
        }
        public VulkanSurfaceRenderTarget(VulkanPlatformInterface platformInterface, VulkanSurface surface)
        {
            _platformInterface = platformInterface;

            var device = VulkanInitialization.CreateDevice(platformInterface.Api,
                                                           platformInterface.PhysicalDevice.InternalHandle,
                                                           platformInterface.PhysicalDevice.QueueFamilyIndex,
                                                           VulkanInitialization.GetSupportedExtensions(platformInterface.Api, platformInterface.PhysicalDevice.InternalHandle),
                                                           platformInterface.PhysicalDevice.QueueCount);

            Device = new VulkanDevice(device, platformInterface.PhysicalDevice, platformInterface.Api);

            Display = VulkanDisplay.CreateDisplay(
                platformInterface.Instance,
                Device,
                platformInterface.PhysicalDevice,
                surface);
            Surface = surface;

            // Skia seems to only create surfaces from images with unorm format
            IsRgba = Display.SurfaceFormat.Format >= Format.R8G8B8A8Unorm &&
                     Display.SurfaceFormat.Format <= Format.R8G8B8A8Srgb;

            _format = IsRgba ? Format.R8G8B8A8Unorm : Format.B8G8R8A8Unorm;
        }