Ejemplo n.º 1
0
        protected SwapchainData CreateSwapchain(PhysicalDevice physicalDevice, SurfaceKHR surface, uint windowWidth, uint windowHeight)
        {
            var data = new SwapchainData();

            var surfaceFormats = physicalDevice.GetSurfaceFormatsKHR(surface);
            var surfaceFormat  = surfaceFormats[0].Format;

            var surfaceCapabilities = physicalDevice.GetSurfaceCapabilitiesKHR(surface);

            var desiredImageCount = Math.Min(surfaceCapabilities.MinImageCount + 1, surfaceCapabilities.MaxImageCount);

            SurfaceTransformFlagsKHR preTransform;

            if ((surfaceCapabilities.SupportedTransforms & SurfaceTransformFlagsKHR.Identity) != 0)
            {
                preTransform = SurfaceTransformFlagsKHR.Identity;
            }
            else
            {
                preTransform = surfaceCapabilities.CurrentTransform;
            }

            var presentModes = physicalDevice.GetSurfacePresentModesKHR(surface);

            var swapChainPresentMode = PresentModeKHR.Fifo;

            if (presentModes.Contains(PresentModeKHR.Mailbox))
            {
                swapChainPresentMode = PresentModeKHR.Mailbox;
            }
            else if (presentModes.Contains(PresentModeKHR.Immediate))
            {
                swapChainPresentMode = PresentModeKHR.Immediate;
            }

            var imageExtent         = new Extent2D(windowWidth, windowHeight);
            var swapchainCreateInfo = new SwapchainCreateInfoKHR
            {
                Surface       = surface,
                MinImageCount = desiredImageCount,

                ImageFormat      = surfaceFormat,
                ImageExtent      = imageExtent,
                ImageArrayLayers = 1,
                ImageUsage       = ImageUsageFlags.ColorAttachment,
                ImageSharingMode = SharingMode.Exclusive,
                //ImageColorSpace    = ColorSpaceKHR.SrgbNonlinear,

                QueueFamilyIndices = null,
                PreTransform       = preTransform,
                CompositeAlpha     = CompositeAlphaFlagsKHR.Opaque,
                PresentMode        = swapChainPresentMode,
                Clipped            = true,
            };

            data.Swapchain   = device.CreateSwapchainKHR(swapchainCreateInfo);
            data.ImageFormat = surfaceFormat;

            return(data);
        }
Ejemplo n.º 2
0
        Extent2D GetSwapChainExtent(ref SurfaceCapabilitiesKHR surface_capabilities)
        {
            // Special value of surface extent is width == height == -1
            // If this is so we define the size by ourselves but it must fit within defined confines
            if (surface_capabilities.currentExtent.width == unchecked ((uint)(-1)))
            {
                Extent2D swap_chain_extent = new Extent2D {
                    width = 640, height = 480
                };
                if (swap_chain_extent.width < surface_capabilities.minImageExtent.width)
                {
                    swap_chain_extent.width = surface_capabilities.minImageExtent.width;
                }
                if (swap_chain_extent.height < surface_capabilities.minImageExtent.height)
                {
                    swap_chain_extent.height = surface_capabilities.minImageExtent.height;
                }
                if (swap_chain_extent.width > surface_capabilities.maxImageExtent.width)
                {
                    swap_chain_extent.width = surface_capabilities.maxImageExtent.width;
                }
                if (swap_chain_extent.height > surface_capabilities.maxImageExtent.height)
                {
                    swap_chain_extent.height = surface_capabilities.maxImageExtent.height;
                }
                return(swap_chain_extent);
            }

            // Most of the cases we define size of the swap_chain images equal to current window's size
            return(surface_capabilities.currentExtent);
        }
Ejemplo n.º 3
0
        public MipMap2D(IntPtr dataPtr, int stride, Extent2D extent, bool flip = true)
        {
            Extent = extent;
            var totalBytes = stride * extent.Height;

            Data = new byte[totalBytes];
            unsafe
            {
                var src = (byte *)dataPtr;
                fixed(byte *destStart = Data)
                {
                    if (flip)
                    {
                        var dest = destStart + totalBytes - stride;
                        for (var i = 0; i < extent.Height; i++)
                        {
                            System.Buffer.MemoryCopy(src, dest, stride, stride);
                            dest -= stride;
                            src  += stride;
                        }
                    }
                    else
                    {
                        System.Buffer.MemoryCopy(src, destStart, totalBytes, totalBytes);
                    }
                }
            }
        }
        public List <Point2D> GetPointsInExtents(Extent2D extents)
        {
            var xs = XS.Where(x => x >= extents.min.x && x <= extents.max.x).ToList();
            var ys = YS.Where(y => y >= extents.min.y && y <= extents.max.y).ToList();

            return(BuildGrid(xs, ys));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SwapchainCreateInfoKhr"/> structure.
 /// </summary>
 /// <param name="surface">
 /// The <see cref="SurfaceKhr"/> that the swapchain will present images to.
 /// </param>
 /// <param name="imageFormat">A format that is valid for swapchains on the specified surface.</param>
 /// <param name="imageExtent">
 /// The size (in pixels) of the swapchain.
 /// <para>
 /// Behavior is platform-dependent when the image extent does not match the surface's <see
 /// cref="SurfaceCapabilitiesKhr.CurrentExtent"/> as returned by <see cref="PhysicalDeviceExtensions.GetSurfaceCapabilitiesKhr"/>.
 /// </para>
 /// </param>
 /// <param name="minImageCount">
 /// The minimum number of presentable images that the application needs. The platform will
 /// either create the swapchain with at least that many images, or will fail to create the swapchain.
 /// </param>
 /// <param name="imageColorSpace">Color space value specifying the way the swapchain interprets image data.</param>
 /// <param name="imageArrayLayers">
 /// The number of views in a multiview/stereo surface.
 /// <para>For non-stereoscopic-3D applications, this value is 1.</para>
 /// </param>
 /// <param name="imageUsage">A bitmask describing the intended usage of the (acquired) swapchain images.</param>
 /// <param name="imageSharingMode">The sharing mode used for the image(s) of the swapchain.</param>
 /// <param name="queueFamilyIndices">
 /// Queue family indices having access to the image(s) of the swapchain when <see
 /// cref="ImageSharingMode"/> is <see cref="SharingMode.Concurrent"/>.
 /// </param>
 /// <param name="preTransform">
 /// A value describing the transform, relative to the presentation engine's natural
 /// orientation, applied to the image content prior to presentation.
 /// <para>
 /// If it does not match the <see cref="SurfaceCapabilitiesKhr.CurrentTransform"/> value
 /// returned by <see cref="PhysicalDeviceExtensions.GetSurfaceCapabilitiesKhr"/>, the
 /// presentation engine will transform the image content as part of the presentation operation.
 /// </para>
 /// </param>
 /// <param name="compositeAlpha">
 /// A bitmask indicating the alpha compositing mode to use when this surface is composited
 /// together with other surfaces on certain window systems.
 /// </param>
 /// <param name="presentMode">
 /// The presentation mode the swapchain will use.
 /// <para>
 /// A swapchain's present mode determines how incoming present requests will be processed and
 /// queued internally.
 /// </para>
 /// </param>
 /// <param name="clipped">
 /// Indicates whether the Vulkan implementation is allowed to discard rendering operations
 /// that affect regions of the surface which are not visible.</param>
 /// <param name="oldSwapchain">Existing swapchain to replace, if any.</param>
 public SwapchainCreateInfoKhr(
     SurfaceKhr surface,
     Format imageFormat,
     Extent2D imageExtent,
     int minImageCount                 = 2,
     ColorSpaceKhr imageColorSpace     = ColorSpaceKhr.SRgbNonlinear,
     int imageArrayLayers              = 1,
     ImageUsages imageUsage            = ImageUsages.ColorAttachment | ImageUsages.TransferDst,
     SharingMode imageSharingMode      = SharingMode.Exclusive,
     int[] queueFamilyIndices          = null,
     SurfaceTransformsKhr preTransform = SurfaceTransformsKhr.Identity,
     CompositeAlphasKhr compositeAlpha = CompositeAlphasKhr.Opaque,
     PresentModeKhr presentMode        = PresentModeKhr.Fifo,
     bool clipped = true,
     SwapchainKhr oldSwapchain = null)
 {
     Flags              = SwapchainCreateFlagsKhr.None;
     Surface            = surface;
     MinImageCount      = minImageCount;
     ImageFormat        = imageFormat;
     ImageColorSpace    = imageColorSpace;
     ImageExtent        = imageExtent;
     ImageArrayLayers   = imageArrayLayers;
     ImageUsage         = imageUsage;
     ImageSharingMode   = imageSharingMode;
     QueueFamilyIndices = queueFamilyIndices;
     PreTransform       = preTransform;
     CompositeAlpha     = compositeAlpha;
     PresentMode        = presentMode;
     Clipped            = clipped;
     OldSwapchain       = oldSwapchain;
 }
Ejemplo n.º 6
0
 public VKImage(Image image, Format format, Extent2D extent, ImageSubresourceRange subresourceRange)
 {
     Image            = image;
     Format           = format;
     Extent           = extent;
     SubresourceRange = subresourceRange;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SwapchainCreateInfoKhr"/> structure.
 /// </summary>
 /// <param name="surface">
 /// The <see cref="SurfaceKhr"/> that the swapchain will present images to.
 /// </param>
 /// <param name="imageExtent">
 /// The size (in pixels) of the swapchain.
 /// <para>
 /// Behavior is platform-dependent when the image extent does not match the surface's <see
 /// cref="SurfaceCapabilitiesKhr.CurrentExtent"/> as returned by <see cref="PhysicalDeviceExtensions.GetSurfaceCapabilitiesKhr"/>.
 /// </para>
 /// </param>
 /// <param name="preTransform">
 /// A bitmask describing the transform, relative to the presentation engine's natural
 /// orientation, applied to the image content prior to presentation.
 /// <para>
 /// If it does not match the <see cref="SurfaceCapabilitiesKhr.CurrentTransform"/> value
 /// returned by <see cref="PhysicalDeviceExtensions.GetSurfaceCapabilitiesKhr"/>, the
 /// presentation engine will transform the image content as part of the presentation operation.
 /// </para>
 /// </param>
 /// <param name="imageUsage">
 /// A bitmask indicating how the application will use the swapchain's presentable images.
 /// </param>
 /// <param name="flags">A bitmask indicating parameters of swapchain creation.</param>
 /// <param name="minImageCount">
 /// The minimum number of presentable images that the application needs. The platform will
 /// either create the swapchain with at least that many images, or will fail to create the swapchain.
 /// </param>
 /// <param name="imageFormat">A format that is valid for swapchains on the specified surface.</param>
 /// <param name="compositeAlpha">
 /// A bitmask indicating the alpha compositing mode to use when this surface is composited
 /// together with other surfaces on certain window systems.
 /// </param>
 /// <param name="imageArrayLayers">
 /// The number of views in a multiview/stereo surface. For non-stereoscopic-3D applications,
 /// this value is 1.
 /// </param>
 /// <param name="presentMode">
 /// The presentation mode the swapchain will use.
 /// <para>
 /// A swapchain's present mode determines how incoming present requests will be processed and
 /// queued internally.
 /// </para>
 /// </param>
 /// <param name="clipped">
 /// Indicates whether the Vulkan implementation is allowed to discard rendering operations
 /// that affect regions of the surface which are not visible.
 /// </param>
 /// <param name="oldSwapchain">Existing swapchain to replace, if any.</param>
 public SwapchainCreateInfoKhr(
     SurfaceKhr surface,
     Format imageFormat,
     Extent2D imageExtent,
     SurfaceTransformsKhr preTransform,
     PresentModeKhr presentMode,
     SwapchainCreateFlagsKhr flags     = 0,
     int minImageCount                 = 2,
     ImageUsages imageUsage            = ImageUsages.ColorAttachment | ImageUsages.TransferDst,
     CompositeAlphasKhr compositeAlpha = CompositeAlphasKhr.Opaque,
     int imageArrayLayers              = 1,
     bool clipped = true,
     SwapchainKhr oldSwapchain = null)
 {
     Flags              = flags;
     Surface            = surface;
     ImageUsage         = imageUsage;
     MinImageCount      = minImageCount;
     ImageFormat        = imageFormat;
     ImageColorSpace    = 0;
     ImageExtent        = imageExtent;
     ImageArrayLayers   = imageArrayLayers;
     ImageSharingMode   = 0;
     QueueFamilyIndices = null;
     PreTransform       = preTransform;
     CompositeAlpha     = compositeAlpha;
     PresentMode        = presentMode;
     Clipped            = clipped;
     OldSwapchain       = oldSwapchain;
 }
Ejemplo n.º 8
0
        public Extent2D CircumCircleExtent()
        {
            if (m_circumCircleExtent == null)
                m_circumCircleExtent = DelaunayGeometry.Circumcircle(m_v[0], m_v[1], m_v[2], centroidX, centroidY);

            return m_circumCircleExtent;
        }
 public void Insert(T item, Extent2D extents)
 {
     if (IsLeaf)
     {
         Data[item] = extents;
         if (Data.Count > SplitThreshold)
         {
             Split();
         }
     }
     else
     {
         bool inserted = false;
         foreach (var quad in ChildrenExtents)
         {
             if (quad.Value.IsExtentsIn(extents))
             {
                 Children[quad.Key].Insert(item, extents);
                 inserted = true;
                 break;
             }
         }
         if (!inserted)
         {
             Data[item] = extents;
         }
     }
 }
Ejemplo n.º 10
0
 public Frame(Image image, Device device, Extent2D imageSize, RenderPass renderpass)
 {
     Image     = image;
     ImageView = device.CreateImageView(new ImageViewCreateInfo
     {
         Image            = image,
         SubresourceRange = new ImageSubresourceRange
         {
             BaseMipLevel   = 0,
             LevelCount     = 1,
             LayerCount     = 1,
             BaseArrayLayer = 0,
             AspectMask     = ImageAspectFlags.Color
         },
         Components = new ComponentMapping
         {
             B = ComponentSwizzle.B,
             G = ComponentSwizzle.G,
             R = ComponentSwizzle.R,
             A = ComponentSwizzle.A
         },
         Format   = Format.B8G8R8A8Unorm,
         ViewType = ImageViewType.View2D,
     });
     Framebuffer = device.CreateFramebuffer(new FramebufferCreateInfo
     {
         Attachments = new[] {
             ImageView
         },
         Height     = imageSize.Height,
         Width      = imageSize.Width,
         RenderPass = renderpass,
         Layers     = 1
     });
 }
        public List <Point3D> GetDEMPoints(double gridSize)
        {
            var extents    = new Extent2D(Points.Keys);
            var demPoints  = new Dictionary <Point2D, double>();
            var sampleGrid = new SampleGrid(extents, gridSize);

            for (double x = extents.min.x; x < extents.max.x; x += gridSize)
            {
                for (double y = extents.min.y; y < extents.max.y; y += gridSize)
                {
                    demPoints[new Point2D(x, y)] = 0;
                }
            }
            //var p2ds = demPoints.Keys.ToList();
            foreach (var tri in Triangles)
            {
                var tri2 = tri.ToTriangle2();
                var pts  = sampleGrid.GetPointsInExtents(new Extent2D(tri2.P));
                foreach (var p in pts)
                {
                    if (tri2.IsPointIn(p))
                    {
                        demPoints[p] = Algorithms.TriangleInterpolate(p.x, p.y, tri.A, tri.B, tri.C);
                    }
                }
            }
            return(demPoints.Select(p => new Point3D(p.Key.x, p.Key.y, p.Value)).ToList());
        }
Ejemplo n.º 12
0
        public static Extent2D ToExtent2D(System.Drawing.Size size)
        {
            Extent2D extent = new Extent2D();

            extent.Width  = (uint)size.Width;
            extent.Height = (uint)size.Height;
            return(extent);
        }
Ejemplo n.º 13
0
        protected override CityEntity[] HandleWindowOrCross()
        {
            Point    p1     = _draggingStartPoint;
            Point    p2     = _draggingEndPoint;
            Extent2D extent = new Extent2D(DisplayManager.Current.CityCoordinate(p1.X, p1.Y), DisplayManager.Current.CityCoordinate(p2.X, p2.Y));

            return(DisplayManager.Current.CityModel.CitySpots.Where(x => extent.IsPointIn(x.Position)).ToArray());
        }
Ejemplo n.º 14
0
 public void GetRenderAreaGranularity()
 {
     using (RenderPass renderPass = CreateRenderPass())
     {
         Extent2D granularity = renderPass.GetRenderAreaGranularity();
         Assert.True(granularity.Width > 0);
         Assert.True(granularity.Height > 0);
     }
 }
Ejemplo n.º 15
0
   public ShapeCollection()
     : base()
 {
     _patternName = string.Empty;
     _patternType = PatternType.NONE;
     _items = new ObservableCollection<Shape>();
     _items.CollectionChanged += _items_CollectionChanged;
     _extent = new Extent2D();
 }
Ejemplo n.º 16
0
 public ShapeCollection()
     : base()
 {
     _patternName              = string.Empty;
     _patternType              = PatternType.NONE;
     _items                    = new ObservableCollection <Shape>();
     _items.CollectionChanged += _items_CollectionChanged;
     _extent                   = new Extent2D();
 }
Ejemplo n.º 17
0
        bool IsContainedBy(Extent2D extent)
        {
            if (extent.Contains(m_v[0].X, m_v[0].Y) && extent.Contains(m_v[1].X, m_v[1].Y) && extent.Contains(m_v[2].X, m_v[2].Y))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 18
0
        public Extent2D CircumCircleExtent()
        {
            if (m_circumCircleExtent == null)
            {
                m_circumCircleExtent = DelaunayGeometry.Circumcircle(m_v[0], m_v[1], m_v[2], centroidX, centroidY);
            }

            return(m_circumCircleExtent);
        }
Ejemplo n.º 19
0
 /// <param name="Display">Handle of the display object</param>
 /// <param name="DisplayName">Name of the display</param>
 /// <param name="PhysicalDimensions">In millimeters?</param>
 /// <param name="PhysicalResolution">Max resolution for CRT?</param>
 /// <param name="PlaneReorderPossible">VK_TRUE if the overlay plane's z-order can be changed on this display.</param>
 /// <param name="PersistentContent">VK_TRUE if this is a "smart" display that supports self-refresh/internal buffering.</param>
 public DisplayPropertiesKHR(DisplayKHR Display, String DisplayName, Extent2D PhysicalDimensions, Extent2D PhysicalResolution, Bool32 PlaneReorderPossible, Bool32 PersistentContent) : this()
 {
     this.Display              = Display;
     this.DisplayName          = DisplayName;
     this.PhysicalDimensions   = PhysicalDimensions;
     this.PhysicalResolution   = PhysicalResolution;
     this.PlaneReorderPossible = PlaneReorderPossible;
     this.PersistentContent    = PersistentContent;
 }
Ejemplo n.º 20
0
 public CityDistrict()
 {
     Extents     = new Extent2D("0,0|1000,1000");
     Roads       = new List <CityRoad>();
     Parcels     = new List <CityParcel>();
     CitySpots   = new List <SpotEntity>();
     CityLinears = new List <LinearEntity>();
     CityRegions = new List <RegionEntity>();
 }
        public QuadTreeNode(Extent2D extents)
        {
            Extents         = extents;
            IsLeaf          = true;
            Children        = new Dictionary <Quad, QuadTreeNode <T> >();
            ChildrenExtents = new Dictionary <Quad, Extent2D>();
            Data            = new Dictionary <T, Extent2D>();

            _quads.ForEach(q => ChildrenExtents[q] = GetChildExtents(extents, q));
        }
Ejemplo n.º 22
0
 /// <param name="DisplayMode">The mode to use when displaying this surface</param>
 /// <param name="PlaneIndex">The plane on which this surface appears. Must be between 0 and the value returned by vkGetPhysicalDeviceDisplayPlanePropertiesKHR() in pPropertyCount.</param>
 /// <param name="PlaneStackIndex">The z-order of the plane.</param>
 /// <param name="Transform">Transform to apply to the images as part of the scannout operation</param>
 /// <param name="GlobalAlpha">Global alpha value. Must be between 0 and 1, inclusive. Ignored if alphaMode is not VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR</param>
 /// <param name="AlphaMode">What type of alpha blending to use. Must be a bit from vkGetDisplayPlanePropertiesKHR::supportedAlpha.</param>
 /// <param name="ImageExtent">Size of the images to use with this surface</param>
 public DisplaySurfaceCreateInfoKHR(DisplayModeKHR DisplayMode, UInt32 PlaneIndex, UInt32 PlaneStackIndex, SurfaceTransformFlagsKHR Transform, Single GlobalAlpha, DisplayPlaneAlphaFlagsKHR AlphaMode, Extent2D ImageExtent) : this()
 {
     this.DisplayMode     = DisplayMode;
     this.PlaneIndex      = PlaneIndex;
     this.PlaneStackIndex = PlaneStackIndex;
     this.Transform       = Transform;
     this.GlobalAlpha     = GlobalAlpha;
     this.AlphaMode       = AlphaMode;
     this.ImageExtent     = ImageExtent;
 }
        public ArrayInitiate(Extent2D extents)
        {
            _extents = extents;

            double a = _extents.min.x;
            double b = _extents.max.x;
            double c = _extents.min.y;
            double d = _extents.max.y;

            _formula = p => this[(int)((p.x - a) / (b - a) * Width * 0.999), (int)((p.y - c) / (d - c) * Height * 0.999)];
        }
Ejemplo n.º 24
0
 private void CentrePolygon(ref Windows.UI.Xaml.Shapes.Polygon poly)
 {
     var CurrentExtent = new Extent2D(double.MaxValue, double.MinValue, double.MaxValue, double.MinValue);
     foreach (Point p in poly.Points)
         CurrentExtent.Update(p);
     Point cntr = CurrentExtent.Centre;
     for (var i = 0; i < poly.Points.Count(); i++)
     {
         poly.Points[i] = new Point(poly.Points[i].X - cntr.X,
                                     poly.Points[i].Y - cntr.Y);
     }
 }
Ejemplo n.º 25
0
        public Triangle(DelaunayPoint v1, DelaunayPoint v2, DelaunayPoint v3)
        {
            m_v = new DelaunayPoint[] { v1, v2, v3 };

            ForceClockwise();

            adjacentFace = new Triangle[3];

            centroidX = (float)(v1.X + v2.X + v3.X) / 3.0f;
            centroidY = (float)(v1.Y + v2.Y + v3.Y) / 3.0f;

            m_extent = new Extent2D(m_v[0], m_v[1], m_v[2]);
        }
Ejemplo n.º 26
0
        public void Extent2DEquals()
        {
            var val1 = new Extent2D(0, 1);
            var val2 = new Extent2D(2, 3);

            Assert.True(val1.Equals(val1));
            Assert.False(val1.Equals(val2));
            Assert.True(val1 == val1);
            Assert.False(val1 == val2);
            Assert.False(val1 != val1);
            Assert.True(val1 != val2);
            Assert.NotEqual(val1.GetHashCode(), val2.GetHashCode());
        }
Ejemplo n.º 27
0
        public Triangle(DelaunayPoint v1, DelaunayPoint v2, DelaunayPoint v3)
        {
            m_v = new DelaunayPoint[] { v1, v2, v3 };

            ForceClockwise();

            adjacentFace = new Triangle[3];

            centroidX = (float)(v1.X + v2.X + v3.X) / 3.0f;
            centroidY = (float)(v1.Y + v2.Y + v3.Y) / 3.0f;

            m_extent = new Extent2D(m_v[0], m_v[1], m_v[2]);
        }
        private void CreateSwapChain()
        {
            var swapChainSupport = new SwapChainSupportDetails(vkPhysicalDevice, vkSurface);

            SurfaceFormatKhr surfaceFormat = ChooseSwapSurfaceFormat(swapChainSupport.formats);
            PresentModeKhr   presentMode   = ChooseSwapPresentMode(swapChainSupport.presentModes);
            Extent2D         extent        = ChooseSwapExtent(swapChainSupport.capabilities);

            uint imageCount = swapChainSupport.capabilities.MinImageCount + 1;

            if (swapChainSupport.capabilities.MaxImageCount > 0)
            {
                imageCount = Math.Min(imageCount, swapChainSupport.capabilities.MaxImageCount);
            }

            var createInfo = new SwapchainCreateInfoKhr()
            {
                MinImageCount    = imageCount,
                ImageFormat      = surfaceFormat.Format,
                ImageColorSpace  = surfaceFormat.ColorSpace,
                ImageExtent      = extent,
                ImageArrayLayers = 1,
                ImageUsage       = ImageUsageFlags.ColorAttachment,
                PreTransform     = swapChainSupport.capabilities.CurrentTransform,
                CompositeAlpha   = CompositeAlphaFlagsKhr.Opaque,
                PresentMode      = presentMode,
                Surface          = vkSurface,
            };

            var indices = new QueueFamilyIndices(vkPhysicalDevice, vkSurface);

            if (indices.GraphicsFamily != indices.PresentFamily)
            {
                createInfo.ImageSharingMode   = SharingMode.Concurrent;
                createInfo.QueueFamilyIndices = new[]
                {
                    (uint)indices.GraphicsFamily,
                    (uint)indices.PresentFamily,
                };
            }
            else
            {
                createInfo.ImageSharingMode = SharingMode.Exclusive;
            }

            vkSwapChain            = vkDevice.CreateSwapchainKHR(createInfo);
            vkSwapChainImages      = vkDevice.GetSwapchainImagesKHR(vkSwapChain);
            vkSwapChainImageFormat = surfaceFormat.Format;
            vkSwapChainExtent      = extent;
        }
 public SampleGrid(Extent2D extents, double cellSize)
 {
     XS = new List <double>();
     YS = new List <double>();
     for (double x = extents.min.x; x < extents.max.x; x += cellSize)
     {
         XS.Add(x);
     }
     for (double y = extents.min.y; y < extents.max.y; y += cellSize)
     {
         YS.Add(y);
     }
     Extents = new Extent2D(extents.min, new Point2D(XS.Last(), YS.Last()));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DisplaySurfaceCreateInfoKhr"/> structure.
 /// </summary>
 /// <param name="displayMode">The mode to use when displaying this surface.</param>
 /// <param name="planeIndex">The plane on which this surface appears.</param>
 /// <param name="planeStackIndex">The z-order of the plane.</param>
 /// <param name="transform">
 /// The transform to apply to the images as part of the scanout operation.
 /// </param>
 /// <param name="globalAlpha">
 /// The global alpha value. This value is ignored if <see cref="AlphaMode"/> is not <see cref="DisplayPlaneAlphasKhr.Global"/>.
 /// </param>
 /// <param name="alphaMode">The type of alpha blending to use.</param>
 /// <param name="imageExtent">Size of the images to use with this surface.</param>
 public DisplaySurfaceCreateInfoKhr(DisplayModeKhr displayMode, int planeIndex, int planeStackIndex,
                                    SurfaceTransformsKhr transform, float globalAlpha, DisplayPlaneAlphasKhr alphaMode, Extent2D imageExtent)
 {
     Type            = StructureType.DisplaySurfaceCreateInfoKhr;
     Next            = IntPtr.Zero;
     Flags           = 0;
     DisplayMode     = displayMode;
     PlaneIndex      = planeIndex;
     PlaneStackIndex = planeStackIndex;
     Transform       = transform;
     GlobalAlpha     = globalAlpha;
     AlphaMode       = alphaMode;
     ImageExtent     = imageExtent;
 }
Ejemplo n.º 31
0
        public bool CreateFrameBuffer()
        {
            ImageView       [] chainImageViews = mDevices.GetChainImageViews();

            mChainBuffers = new Framebuffer[chainImageViews.Length];

            Extent2D chainExtent = mDevices.GetChainExtent();

            for (int i = 0; i < chainImageViews.Length; i++)
            {
                mChainBuffers[i] = mRenderPass.CreateFramebuffer(new FramebufferCreateInfo(
                                                                     new[] { chainImageViews[i] }, chainExtent.Width, chainExtent.Height, 1));
            }
            return(true);
        }
Ejemplo n.º 32
0
        private void CentrePolygon(ref Windows.UI.Xaml.Shapes.Polygon poly)
        {
            var CurrentExtent = new Extent2D(double.MaxValue, double.MinValue, double.MaxValue, double.MinValue);

            foreach (Point p in poly.Points)
            {
                CurrentExtent.Update(p);
            }
            Point cntr = CurrentExtent.Centre;

            for (var i = 0; i < poly.Points.Count(); i++)
            {
                poly.Points[i] = new Point(poly.Points[i].X - cntr.X,
                                           poly.Points[i].Y - cntr.Y);
            }
        }
Ejemplo n.º 33
0
        private void CreateSwapChain()
        {
            SwapChainSupportDetails swapChainSupport = this.QuerySwapChainSupport(this.physicalDevice);

            uint imageCount = swapChainSupport.Capabilities.MinImageCount + 1;

            if (swapChainSupport.Capabilities.MaxImageCount > 0 && imageCount > swapChainSupport.Capabilities.MaxImageCount)
            {
                imageCount = swapChainSupport.Capabilities.MaxImageCount;
            }

            SurfaceFormat surfaceFormat = this.ChooseSwapSurfaceFormat(swapChainSupport.Formats);

            QueueFamilyIndices queueFamilies = this.FindQueueFamilies(this.physicalDevice);

            var indices = queueFamilies.Indices.ToArray();

            Extent2D extent = this.ChooseSwapExtent(swapChainSupport.Capabilities);

            this.swapChain = device.CreateSwapchain(new SwapchainCreateInfo
            {
                Surface          = surface,
                Flags            = SwapchainCreateFlags.None,
                PresentMode      = this.ChooseSwapPresentMode(swapChainSupport.PresentModes),
                MinImageCount    = imageCount,
                ImageExtent      = extent,
                ImageUsage       = ImageUsageFlags.ColorAttachment,
                PreTransform     = swapChainSupport.Capabilities.CurrentTransform,
                ImageArrayLayers = 1,
                ImageSharingMode = indices.Length == 1
                                    ? SharingMode.Exclusive
                                    : SharingMode.Concurrent,
                QueueFamilyIndices = indices,
                ImageFormat        = surfaceFormat.Format,
                ImageColorSpace    = surfaceFormat.ColorSpace,
                Clipped            = true,
                CompositeAlpha     = CompositeAlphaFlags.Opaque,
                OldSwapchain       = this.swapChain
            });

            this.swapChainFormat = surfaceFormat.Format;
            this.swapChainExtent = extent;

            this.swapChainImages = this.swapChain.GetImages();

            this.swapChainImageViews = swapChainImages.Select(image => this.CreateImageView(image, this.swapChainFormat, ImageAspectFlags.Color)).ToArray();
        }
Ejemplo n.º 34
0
        protected void CreateSwapChain()
        {
            format = ChooseFormat(data.formats);
            var presentMode = ChoosePresentMode(data.presentModes);

            extent = ChooseSwapExtent();

            var imageCount = data.surfaceCapabilities.MinImageCount + 1;

            if (data.surfaceCapabilities.MaxImageCount > 0 && imageCount > data.surfaceCapabilities.MaxImageCount)
            {
                imageCount = data.surfaceCapabilities.MaxImageCount;
            }

            var swapChainInfo = new SwapchainCreateInfoKhr
            {
                Surface          = data.surface,
                MinImageCount    = imageCount,
                ImageFormat      = format.Format,
                ImageColorSpace  = format.ColorSpace,
                ImageExtent      = extent,
                ImageArrayLayers = 1,
                ImageUsage       = ImageUsageFlags.ColorAttachment,
                PreTransform     = data.surfaceCapabilities.CurrentTransform,
                CompositeAlpha   = CompositeAlphaFlagsKhr.Opaque,
                PresentMode      = presentMode,
                Clipped          = true
            };
            var indices            = data.queueFamilyIndices;
            var queueFamilyIndices = new uint[] { (uint)indices.GraphicsFamily, (uint)indices.PresentFamily };

            if (indices.PresentFamily != indices.GraphicsFamily)
            {
                swapChainInfo.ImageSharingMode      = SharingMode.Concurrent;
                swapChainInfo.QueueFamilyIndexCount = (uint)queueFamilyIndices.Length;
                swapChainInfo.QueueFamilyIndices    = queueFamilyIndices;
            }
            else
            {
                swapChainInfo.ImageSharingMode = SharingMode.Exclusive;
            }

            swapchain = device.CreateSwapchainKHR(swapChainInfo);

            images     = device.GetSwapchainImagesKHR(swapchain);
            bufferSize = imageCount;
        }
Ejemplo n.º 35
0
        public static Extent2D Circumcircle(DelaunayPoint v1, DelaunayPoint v2, DelaunayPoint v3, double cx, double cy)
        {
            const double ERROR_BOUND = 0.005;

            //http://mathworld.wolfram.com/Circumcircle.html
            double x1 = v1.X;
            double x2 = v2.X;
            double x3 = v3.X;
            double y1 = v1.Y;
            double y2 = v2.Y;
            double y3 = v3.Y;

            double x1Sq = x1 * x1;
            double x2Sq = x2 * x2;
            double x3Sq = x3 * x3;
            double y1Sq = y1 * y1;
            double y2Sq = y2 * y2;
            double y3Sq = y3 * y3;

            double a = (x1 - x2) * (y2 - y3) - (y1 - y2) * (x2 - x3);
            double bx = -((x1Sq + y1Sq - x2Sq - y2Sq) * (y2 - y3) - (x2Sq + y2Sq - x3Sq - y3Sq) * (y1 - y2));
            double by = ((x1Sq + y1Sq - x2Sq - y2Sq) * (x2 - x3) - (x2Sq + y2Sq - x3Sq - y3Sq) * (x1 - x2));
            double c = -((x1Sq + y1Sq) * (x2 * y3 - x3 * y2) - (x2Sq + y2Sq) * (x1 * y3 - x3 * y1) + (x3Sq + y3Sq) * (x1 * y2 - x2 * y1));

            Extent2D extent = null;

            if (a == 0.0f)
            {
                extent = new Extent2D(cx - ERROR_BOUND, cx + ERROR_BOUND, cy - ERROR_BOUND, cy + ERROR_BOUND);
            }
            else
            {
                double x0 = -bx / (2.0f * a);
                double y0 = -by / (2.0f * a);
                double numerator = bx * bx + by * by - 4.0f * a * c;

                double rad = 0;
                if (numerator >= 0)
                    rad = Math.Sqrt(numerator) / (2.0f * Math.Abs(a));

                extent = new Extent2D(x0 - rad - ERROR_BOUND, x0 + rad + ERROR_BOUND, y0 - rad - ERROR_BOUND, y0 + rad + ERROR_BOUND);
            }
            return extent;
        }
Ejemplo n.º 36
0
        bool IsContainedBy(Extent2D extent)
        {
            if (extent.Contains(m_v[0].X, m_v[0].Y) && extent.Contains(m_v[1].X, m_v[1].Y) && extent.Contains(m_v[2].X, m_v[2].Y))
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 37
0
 public Rect2D(Offset2D offset, Extent2D extent)
 {
     Offset = offset;
     Extent = extent;
 }
Ejemplo n.º 38
0
 public Rect2D(int x, int y, uint width, uint height)
 {
     Offset = new Offset2D(x, y);
     Extent = new Extent2D(width, height);
 }
Ejemplo n.º 39
0
        bool Overlaps(Extent2D extent)
        {
            // Check simplist case - triangle inside extent.
            if (extent.Contains(m_extent))
                return true;

            // Use right-hand rule for each triangle segment against all points of extent rectangle.
            DelaunayPoint p1 = new DelaunayPoint(extent.MinX, extent.MinY, 0.0f, 0);
            DelaunayPoint p2 = new DelaunayPoint(extent.MaxX, extent.MinY, 0.0f, 0);
            DelaunayPoint p3 = new DelaunayPoint(extent.MaxX, extent.MaxY, 0.0f, 0);
            DelaunayPoint p4 = new DelaunayPoint(extent.MinX, extent.MaxY, 0.0f, 0);

            int ar = 0;
            if (DelaunayGeometry.CrossProduct(m_v[0], p1, m_v[1]) >= 0.0f)
                ++ar;
            if (DelaunayGeometry.CrossProduct(m_v[0], p2, m_v[1]) >= 0.0f)
                ++ar;
            if (DelaunayGeometry.CrossProduct(m_v[0], p3, m_v[1]) >= 0.0f)
                ++ar;
            if (DelaunayGeometry.CrossProduct(m_v[0], p4, m_v[1]) >= 0.0f)
                ++ar;

            int br = 0;
            if (DelaunayGeometry.CrossProduct(m_v[1], p1, m_v[2]) >= 0.0f)
                ++br;
            if (DelaunayGeometry.CrossProduct(m_v[1], p2, m_v[2]) >= 0.0f)
                ++br;
            if (DelaunayGeometry.CrossProduct(m_v[1], p3, m_v[2]) >= 0.0f)
                ++br;
            if (DelaunayGeometry.CrossProduct(m_v[1], p4, m_v[2]) >= 0.0f)
                ++br;

            int cr = 0;
            if (DelaunayGeometry.CrossProduct(m_v[2], p1, m_v[0]) >= 0.0f)
                ++cr;
            if (DelaunayGeometry.CrossProduct(m_v[2], p2, m_v[0]) >= 0.0f)
                ++cr;
            if (DelaunayGeometry.CrossProduct(m_v[2], p3, m_v[0]) >= 0.0f)
                ++cr;
            if (DelaunayGeometry.CrossProduct(m_v[2], p4, m_v[0]) >= 0.0f)
                ++cr;

            // There will be some sort intersection of triangle with rectangle if at least one point of
            // the rectangle is on, or to the right (not zero) of every segment of the triangle.
            if (ar != 0 && br != 0 && cr != 0)
            {
                return true;
            }

            return false;
        }