Exemplo n.º 1
0
        private void ReadButton_Click(object sender, EventArgs e)
        {
            if (!m_Connected)
            {
                return;
            }

            String DeviceName = DeviceAddr.Text;
            int    DeviceSize;

            if (!int.TryParse(DeviceNum.Text, out DeviceSize))
            {
                DeviceSize     = 1;
                DeviceNum.Text = DeviceSize.ToString();
            }

            try
            {
                String        data = CommUtil.GetStringFromDevice(DeviceName, DeviceSize * 2, m_PLCCom);
                StringBuilder msg  = new StringBuilder();
                foreach (Char c in data)
                {
                    msg.Append((short)(c));
                    msg.Append(" ");
                }
                DeviceData.Text = msg.ToString();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
        }
        private void CreateIndexBuffer()
        {
            DeviceSize bufferSize = sizeof(short) * (uint)indices.Length;

            CreateBuffer(
                bufferSize,
                BufferUsageFlags.TransferSrc,
                MemoryPropertyFlags.HostVisible | MemoryPropertyFlags.HostCoherent,
                out Vulkan.Buffer stagingIndexBuffer,
                out DeviceMemory stagingIndexBufferMemory);

            IntPtr bufferPointer = vkDevice.MapMemory(stagingIndexBufferMemory, 0, bufferSize);

            Marshal.Copy(indices, 0, bufferPointer, indices.Length);
            vkDevice.UnmapMemory(stagingIndexBufferMemory);

            CreateBuffer(
                bufferSize,
                BufferUsageFlags.IndexBuffer | BufferUsageFlags.TransferDst,
                MemoryPropertyFlags.DeviceLocal,
                out vkIndexBuffer,
                out vkIndexBufferMemory);

            CopyBuffer(stagingIndexBuffer, vkIndexBuffer, bufferSize);

            vkDevice.DestroyBuffer(stagingIndexBuffer);
            vkDevice.FreeMemory(stagingIndexBufferMemory);
        }
Exemplo n.º 3
0
 /// <param name="Format">Optionally specifies format of elements</param>
 /// <param name="Offset">Specified in bytes</param>
 /// <param name="Range">View size specified in bytes</param>
 public BufferViewCreateInfo(Buffer Buffer, Format Format, DeviceSize Offset, DeviceSize Range) : this()
 {
     this.Buffer = Buffer;
     this.Format = Format;
     this.Offset = Offset;
     this.Range  = Range;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="extendedHandle">
 /// The CommandBuffer handle to extend.
 /// </param>
 public static unsafe void BeginConditionalRendering(this SharpVk.CommandBuffer extendedHandle, SharpVk.Buffer buffer, DeviceSize offset, SharpVk.Multivendor.ConditionalRenderingFlags?flags = default(SharpVk.Multivendor.ConditionalRenderingFlags?))
 {
     try
     {
         CommandCache commandCache = default(CommandCache);
         SharpVk.Interop.Multivendor.ConditionalRenderingBeginInfo *marshalledConditionalRenderingBegin = default(SharpVk.Interop.Multivendor.ConditionalRenderingBeginInfo *);
         void *nextPointer = default(void *);
         commandCache = extendedHandle.commandCache;
         marshalledConditionalRenderingBegin         = (SharpVk.Interop.Multivendor.ConditionalRenderingBeginInfo *)(Interop.HeapUtil.Allocate <SharpVk.Interop.Multivendor.ConditionalRenderingBeginInfo>());
         marshalledConditionalRenderingBegin->SType  = StructureType.ConditionalRenderingBeginInfo;
         marshalledConditionalRenderingBegin->Next   = nextPointer;
         marshalledConditionalRenderingBegin->Buffer = buffer?.handle ?? default(SharpVk.Interop.Buffer);
         marshalledConditionalRenderingBegin->Offset = offset;
         if (flags != null)
         {
             marshalledConditionalRenderingBegin->Flags = flags.Value;
         }
         else
         {
             marshalledConditionalRenderingBegin->Flags = default(SharpVk.Multivendor.ConditionalRenderingFlags);
         }
         SharpVk.Interop.Multivendor.VkCommandBufferBeginConditionalRenderingDelegate commandDelegate = commandCache.Cache.vkCmdBeginConditionalRenderingEXT;
         commandDelegate(extendedHandle.handle, marshalledConditionalRenderingBegin);
     }
     finally
     {
         Interop.HeapUtil.FreeAll();
     }
 }
        private void CopyBuffer(Vulkan.Buffer srcBuffer, Vulkan.Buffer dstBuffer, DeviceSize size)
        {
            var allocInfo = new CommandBufferAllocateInfo()
            {
                CommandPool        = vkCommandPool,
                CommandBufferCount = 1,
                Level = CommandBufferLevel.Primary,
            };

            var commmandBuffer = vkDevice.AllocateCommandBuffers(allocInfo)[0];

            commmandBuffer.Begin(new CommandBufferBeginInfo()
            {
                Flags = CommandBufferUsageFlags.OneTimeSubmit
            });
            commmandBuffer.CmdCopyBuffer(srcBuffer, dstBuffer, new BufferCopy[] { new BufferCopy()
                                                                                  {
                                                                                      Size = size
                                                                                  } });
            commmandBuffer.End();

            vkGraphicsQueue.Submit(new SubmitInfo()
            {
                CommandBuffers = new CommandBuffer[] { commmandBuffer }
            });
            vkGraphicsQueue.WaitIdle();

            vkDevice.FreeCommandBuffer(vkCommandPool, commmandBuffer);
        }
Exemplo n.º 6
0
        void CopyArrayToBuffer(DeviceMemory bufferMem, DeviceSize size, byte[] data)
        {
            var map = device.MapMemory(bufferMem, 0, size);

            Marshal.Copy(data, 0, map, (int)((ulong)size));
            device.UnmapMemory(bufferMem);
        }
Exemplo n.º 7
0
 public void CmdBindIndexBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer buffer,
     DeviceSize offset,
     VkIndexType indexType)
 {
 }
Exemplo n.º 8
0
        internal void Init(DeviceSize deviceSize, IconSize iconSize)
        {
            SuspendLayout();
            Controls.Clear();

            for (byte i = 0; i < deviceSize.Width; i++)
            {
                for (byte j = 0; j < deviceSize.Height; j++)
                {
                    PictureBox box = new PictureBox();
                    box.Size       = new Size(iconSize.Width, iconSize.Height);
                    box.Tag        = new Location(i, j);
                    box.MouseDown += BoxOnMouseDown;
                    box.MouseUp   += BoxOnMouseUp;

                    Controls.Add(box);
                    box.Parent = this;
                    box.Left   = i * iconSize.Width;
                    box.Top    = j * iconSize.Height;
                }
            }

            Size = new Size(deviceSize.Width * iconSize.Width, deviceSize.Height * iconSize.Height);
            ResumeLayout();
        }
Exemplo n.º 9
0
        public static DeviceSize GetDeviceSize(double width)
        {
            DeviceSize device = DeviceSize.Medium;

            if (width <= 544)
            {
                device = DeviceSize.ExtraSmall;
            }
            else if (width > 544 && width <= 768)
            {
                device = DeviceSize.Small;
            }
            else if (width > 768 && width <= 992)
            {
                device = DeviceSize.Medium;
            }
            else if (width > 992 && width <= 1200)
            {
                device = DeviceSize.Large;
            }
            else if (width > 1200)
            {
                device = DeviceSize.ExtraLarge;
            }

            return(device);
        }
Exemplo n.º 10
0
 /// <param name="Size">Specified in bytes</param>
 /// <param name="Usage">Buffer usage flags</param>
 public BufferCreateInfo(DeviceSize Size, BufferUsageFlags Usage, SharingMode SharingMode, UInt32[] QueueFamilyIndices) : this()
 {
     this.Size               = Size;
     this.Usage              = Usage;
     this.SharingMode        = SharingMode;
     this.QueueFamilyIndices = QueueFamilyIndices;
 }
Exemplo n.º 11
0
 /// <param name="SrcQueueFamilyIndex">Queue family to transition ownership from</param>
 /// <param name="DstQueueFamilyIndex">Queue family to transition ownership to</param>
 /// <param name="Buffer">Buffer to sync</param>
 /// <param name="Offset">Offset within the buffer to sync</param>
 /// <param name="Size">Amount of bytes to sync</param>
 public BufferMemoryBarrier(UInt32 SrcQueueFamilyIndex, UInt32 DstQueueFamilyIndex, Buffer Buffer, DeviceSize Offset, DeviceSize Size) : this()
 {
     this.SrcQueueFamilyIndex = SrcQueueFamilyIndex;
     this.DstQueueFamilyIndex = DstQueueFamilyIndex;
     this.Buffer = Buffer;
     this.Offset = Offset;
     this.Size   = Size;
 }
Exemplo n.º 12
0
 public void CmdFillBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer dstBuffer,
     DeviceSize dstOffset,
     DeviceSize size,
     int data)
 {
 }
Exemplo n.º 13
0
 public void CmdUpdateBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer dstBuffer,
     DeviceSize dstOffset,
     DeviceSize dataSize,
     IntPtr pData)
 {
 }
Exemplo n.º 14
0
 public void CmdDrawIndexedIndirect(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer buffer,
     DeviceSize offset,
     int drawCount,
     int stride)
 {
 }
Exemplo n.º 15
0
        private static DevicePower PromptForPoweredBy(DeviceSize size, string prompt)
        {
            bool        validEntry = false;
            string      entry      = "";
            DevicePower poweredBy  = DevicePower.Solar;

            do
            {
                Console.Write(prompt.ToString());
                entry = Console.ReadLine();

                try
                {
                    switch (Int32.Parse(entry))
                    {
                    case 1:
                        if (size.Equals(DeviceSize.Medium))
                        {
                            poweredBy = DevicePower.Battery;

                            validEntry = true;
                        }
                        else
                        {
                            poweredBy = DevicePower.Generator;

                            validEntry = true;
                        }
                        break;

                    case 2:
                        if (size.Equals(DeviceSize.Medium))
                        {
                            poweredBy = DevicePower.Solar;

                            validEntry = true;
                        }
                        else
                        {
                            poweredBy = DevicePower.Solar;

                            validEntry = true;
                        }
                        break;

                    default:
                        Console.WriteLine("\n**Please enter a valid value.");
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("\n**Please enter a valid value.");
                }
            } while (!validEntry);

            return(poweredBy);
        }
Exemplo n.º 16
0
 public Widget(DeviceFinish finish, DeviceSize size, int serialNumber)
 {
     SerialNumber = serialNumber;
     Name         = "Widget";
     Price        = 0.00m;
     Finish       = finish;
     Size         = size;
     AddComponents();
 }
Exemplo n.º 17
0
 public VulkanImage(VulkanBufferManager manager, Image image, DeviceMemory memory, DeviceSize offset, DeviceSize size, Format format)
 {
     this.manager = manager;
     this.image   = image;
     this.memory  = memory;
     this.offset  = offset;
     this.size    = size;
     this.format  = format;
 }
Exemplo n.º 18
0
        VertexData CreateVertexData()
        {
            var data = new VertexData();

            var quadVertices = new[, ]
            {
                { 1.0f, 1.0f, 0.0f, /* UV: */ 1.0f, 1.0f, /* Normal: */ 0.0f, 0.0f, 1.0f },
                { -1.0f, 1.0f, 0.0f, /* UV: */ 0.0f, 1.0f, /* Normal: */ 0.0f, 0.0f, 1.0f },
                { -1.0f, -1.0f, 0.0f, /* UV: */ 0.0f, 0.0f, /* Normal: */ 0.0f, 0.0f, 1.0f },
                { 1.0f, -1.0f, 0.0f, /* UV: */ 1.0f, 0.0f, /* Normal: */ 0.0f, 0.0f, 1.0f },
            };

            DeviceSize memorySize = (ulong)(sizeof(float) * quadVertices.Length);

            data.Buffer = CreateBuffer(memorySize, BufferUsageFlags.VertexBuffer);

            var memoryRequirements = device.GetBufferMemoryRequirements(data.Buffer);
            var memoryIndex        = FindMemoryIndex(MemoryPropertyFlags.HostVisible);
            var allocateInfo       = new MemoryAllocateInfo(memoryRequirements.Size, memoryIndex);

            data.DeviceMemory = BindBuffer(data.Buffer, allocateInfo);

            var vertexPtr = device.MapMemory(data.DeviceMemory, 0, memorySize);

            VulkanUtils.Copy2DArray(quadVertices, vertexPtr, memorySize, memorySize);
            device.UnmapMemory(data.DeviceMemory);

            data.Indicies = new[] { 0, 1, 2, 2, 3, 0 };

            memorySize       = (ulong)(sizeof(uint) * data.Indicies.Length);
            data.IndexBuffer = CreateBuffer(memorySize, BufferUsageFlags.IndexBuffer);

            memoryRequirements     = device.GetBufferMemoryRequirements(data.IndexBuffer);
            memoryIndex            = FindMemoryIndex(MemoryPropertyFlags.HostVisible);
            allocateInfo           = new MemoryAllocateInfo(memoryRequirements.Size, memoryIndex);
            data.IndexDeviceMemory = BindBuffer(data.IndexBuffer, allocateInfo);

            var bytes = data.Indicies.SelectMany(BitConverter.GetBytes).ToArray(); // oh man, dat Linq tho

            CopyArrayToBuffer(data.IndexDeviceMemory, memorySize, bytes);

            data.BindingDescriptions = new[]
            {
                new VertexInputBindingDescription(0, (uint)(sizeof(float) * quadVertices.GetLength(1)), VertexInputRate.Vertex)
            };

            data.AttributeDescriptions = new[]
            {
                new VertexInputAttributeDescription(0, 0, Format.R32g32b32Sfloat, 0),                 // Vertex: X, Y, Z
                new VertexInputAttributeDescription(1, 0, Format.R32g32Sfloat, sizeof(float) * 3),    // UV: U, V
                new VertexInputAttributeDescription(2, 0, Format.R32g32b32Sfloat, sizeof(float) * 5), // Normal: X, Y, Z
            };

            return(data);
        }
Exemplo n.º 19
0
 public Gadget(DeviceFinish finish, DeviceSize size, int serialNumber)
 {
     SerialNumber = serialNumber;
     Name         = "Gadget";
     Price        = 0.00m;
     FixedComponentsTotalPrice = 0.00m;
     Finish     = finish;
     Size       = size;
     Components = new List <Widget>();
     AddFixedComponents();
 }
Exemplo n.º 20
0
        private void CreateUniformBuffer()
        {
            DeviceSize bufferSize = Marshal.SizeOf <UniformBufferObject>();

            CreateBuffer(
                bufferSize,
                BufferUsageFlags.UniformBuffer,
                MemoryPropertyFlags.HostVisible | MemoryPropertyFlags.HostCoherent,
                out vkUniformBuffer,
                out vkUniformBufferMemory);
        }
Exemplo n.º 21
0
        public virtual BufferWithMemory CreateBuffer(BufferUsageFlags usageFlags, DeviceSize size, float[] data)
        {
            BufferWithMemory bufferWithMemory;

            fixed(void *p = &data[0])
            {
                bufferWithMemory = VContext.Instance.CreateBuffer(usageFlags, size, p);
            }

            return(bufferWithMemory);
        }
Exemplo n.º 22
0
        public LayoutContext(IDevice device, GlobalContext globalContext, Action <ILayout> setLayoutAction, Action setPreviousLayoutAction, Func <IDisposable> pauseDrawingFunc, Func <IEnumerable <ILayout> > activeLayoutsFunc)
        {
            _device            = device;
            IconSize           = device.IconSize;
            ButtonCount        = device.ButtonCount;
            _globalContext     = globalContext;
            _pauseDrawingFunc  = pauseDrawingFunc;
            _activeLayoutsFunc = activeLayoutsFunc;

            _setLayoutAction         = setLayoutAction;
            _setPreviousLayoutAction = setPreviousLayoutAction;
        }
 public bool IsEmpty()
 {
     return((SelectorRegions == null || SelectorRegions.Length == 0) &&
            Status == RenderStatus.None &&
            RenderId == null &&
            ImageLocation == null &&
            Error == null &&
            OS == null &&
            UserAgent == null &&
            DeviceSize.IsEmpty() &&
            SelectorRegions == null);
 }
Exemplo n.º 24
0
        public static SizeRequest ProcessFormInlineSizeRequest(this Layout <View> element, double widthConstraint, double heightConstraint)
        {
            DeviceSize device = Common.GetCurrentDeviceSize();

            if (element.WidthRequest > 0)
            {
                widthConstraint = Math.Min(element.WidthRequest, widthConstraint);
            }
            if (element.HeightRequest > 0)
            {
                heightConstraint = Math.Min(element.HeightRequest, heightConstraint);
            }

            double internalHeight = double.IsPositiveInfinity(heightConstraint) ? double.PositiveInfinity : Math.Max(0, heightConstraint);
            double internalWidth  = double.IsPositiveInfinity(widthConstraint) ? double.PositiveInfinity : Math.Max(0, widthConstraint);

            // Measure children height
            double height          = 0d;
            double lastChildHeight = 0d;
            double totalWidth      = 0;
            double totalHeight     = 0d;
            int    totalRow        = 1;

            foreach (var child in element.Children)
            {
                var size = child.Measure(internalWidth, internalHeight);
                lastChildHeight = Math.Max(size.Request.Height + child.Margin.VerticalThickness, lastChildHeight);
                totalWidth     += size.Request.Width + child.Margin.HorizontalThickness;
                if (device == DeviceSize.ExtraSmall || device == DeviceSize.Small)
                {
                    totalHeight += size.Request.Height + child.Margin.VerticalThickness;
                }
                else
                {
                    totalHeight = lastChildHeight;
                    if (totalWidth > internalWidth)
                    {
                        totalRow  += 1;
                        totalWidth = 0;
                    }
                }
            }

            height = element.Padding.VerticalThickness + totalHeight;
            if (totalRow > 1)
            {
                height = element.Padding.VerticalThickness + (totalHeight * totalRow);
            }

            return(new SizeRequest(new Size(internalWidth, height), new Size(0, 0)));
        }
Exemplo n.º 25
0
 public void SetIosDeviceSize(DeviceSize size)
 {
     if (size != null && IosDeviceInfo != null)
     {
         if (IosDeviceInfo.ScreenOrientation == ScreenOrientation.Portrait)
         {
             IosDeviceInfo.Size = size.Portrait;
         }
         else
         {
             IosDeviceInfo.Size = size.Landscape;
         }
     }
 }
Exemplo n.º 26
0
 public void SetEmulationDeviceSize(DeviceSize size)
 {
     if (size != null && EmulationInfo != null)
     {
         if (EmulationInfo.ScreenOrientation == ScreenOrientation.Portrait)
         {
             EmulationInfo.Size = size.Portrait;
         }
         else
         {
             EmulationInfo.Size = size.Landscape;
         }
     }
 }
Exemplo n.º 27
0
        public BufferView CreateBufferview(Buffer buffer, Format format, DeviceSize size)
        {
            BufferView bufferView = VContext.Instance.device.CreateBufferView
                                    (
                new BufferViewCreateInfo()
            {
                Buffer = buffer,
                Format = format,
                Offset = 0,
                Range  = size
            }
                                    );

            return(bufferView);
        }
Exemplo n.º 28
0
        public static void ProcessFormBasicClass(this Layout <View> element, double x, double y, double width, double height)
        {
            DeviceSize device = Common.GetCurrentDeviceSize();
            double     yPos   = y;

            foreach (var child in element.Children)
            {
                var request     = child.Measure(width, height);
                var childWidth  = width - child.Margin.HorizontalThickness;
                var childHeight = request.Request.Height;

                var region = new Rectangle(x + child.Margin.Left, yPos + child.Margin.Top, childWidth, childHeight);
                child.Layout(region);

                yPos += childHeight + child.Margin.VerticalThickness;
            }
        }
Exemplo n.º 29
0
        public static void ProcessFormBasicClass(this Layout <View> element, double x, double y, double width, double height)
        {
            DeviceSize device = Common.GetCurrentDeviceSize();
            double     yPos   = y;

            foreach (var child in element.Children)
            {
                var request     = child.Measure(width, height);
                var childWidth  = width;
                var childHeight = request.Request.Height;

                var region = new Rectangle(x, yPos, childWidth, childHeight);
                child.Layout(region);

                yPos += childHeight;
            }
        }
Exemplo n.º 30
0
        private static int GetColumnOffsetSizeByDeviceSize(View element, DeviceSize deviceSize)
        {
            var property = element.GetValue(ResponsiveProperty.ClassProperty);
            int value    = -1;

            if (property != null)
            {
                List <string> classes           = property.ToString().Split(" ".ToCharArray()).ToList();
                string        columnStartString = $"col-{deviceSize.Tag()}-offset-";

                if (classes.Any(o => o.StartsWith(columnStartString)))
                {
                    value = Convert.ToInt16(classes.Where(o => o.StartsWith(columnStartString)).First().TrimStart(columnStartString.ToCharArray()));
                }
            }

            return(value);
        }
Exemplo n.º 31
0
 public void CmdDrawIndexedIndirect(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer buffer,
     DeviceSize offset,
     int drawCount,
     int stride)
 { }
Exemplo n.º 32
0
 public void CmdDispatchIndirect(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer buffer,
     DeviceSize offset)
 { }
Exemplo n.º 33
0
 public void CmdBindIndexBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer buffer,
     DeviceSize offset,
     VkIndexType indexType)
 { }
Exemplo n.º 34
0
 public void CmdFillBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer dstBuffer,
     DeviceSize dstOffset,
     DeviceSize size,
     int data)
 { }
Exemplo n.º 35
0
 public void CmdUpdateBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer dstBuffer,
     DeviceSize dstOffset,
     DeviceSize dataSize,
     IntPtr pData)
 { }