示例#1
0
        void recordDraw(CommandBuffer cmd, Framebuffer fb)
        {
            texture.SetLayout(cmd, VkImageAspectFlags.Color, VkImageLayout.Undefined, VkImageLayout.ShaderReadOnlyOptimal,
                              VkPipelineStageFlags.BottomOfPipe, VkPipelineStageFlags.FragmentShader);

            pipeline.RenderPass.Begin(cmd, fb);

            cmd.SetViewport(fb.Width, fb.Height);
            cmd.SetScissor(fb.Width, fb.Height);
            cmd.BindDescriptorSet(pipeline.Layout, descriptorSet);

            pipeline.Bind(cmd);

            cmd.BindVertexBuffer(vbo, 0);
            cmd.BindIndexBuffer(ibo, VkIndexType.Uint16);
            cmd.DrawIndexed((uint)indices.Length);

            pipeline.RenderPass.End(cmd);
        }
示例#2
0
        void RenderTexturedQuad(CommandBuffer cmdBuffer, VertexData vertexData, ImageData imageData, PipelineLayout pipelineLayout, DescriptorSet descriptorSet, RenderPass renderPass, Pipeline pipeline, Framebuffer framebuffer, uint width, uint height)
        {
            var viewport = new Viewport(0, 0, width, height, 0, 1);

            cmdBuffer.SetViewport(0, new[] { viewport });

            var renderArea      = new Rect2D(new Offset2D(0, 0), new Extent2D(width, height));
            var renderPassBegin = new RenderPassBeginInfo(renderPass, framebuffer, renderArea, null);

            cmdBuffer.BeginRenderPass(renderPassBegin, SubpassContents.Inline);
            renderPassBegin.Dispose();

            cmdBuffer.BindDescriptorSets(PipelineBindPoint.Graphics, pipelineLayout, 0, new[] { descriptorSet }, null);

            cmdBuffer.BindPipeline(PipelineBindPoint.Graphics, pipeline);

            cmdBuffer.BindVertexBuffers(0, new[] { vertexData.Buffer }, new DeviceSize[] { 0 });
            cmdBuffer.BindIndexBuffer(vertexData.IndexBuffer, 0, IndexType.Uint32);
            cmdBuffer.DrawIndexed((uint)vertexData.Indicies.Length, 1, 0, 0, 1);

            cmdBuffer.EndRenderPass();
        }
示例#3
0
 /// <summary>
 /// Bind this vertex buffer.
 /// </summary>
 public void Bind(CommandBuffer commands, int offset)
 {
     commands.BindIndexBuffer(IndexBuffer, offset, IndexType.Uint32);
 }
示例#4
0
        public override void Bind(Device device, RenderPass renderPass, CommandBuffer commandBuffer, Extent2D targetExtent)
        {
            this.aspectRatio = (float)targetExtent.Width / (float)targetExtent.Height;

            this.pipeline = device.CreateGraphicsPipelines(null, new[]
            {
                new GraphicsPipelineCreateInfo
                {
                    Layout           = this.pipelineLayout,
                    RenderPass       = renderPass,
                    Subpass          = 0,
                    VertexInputState = new PipelineVertexInputStateCreateInfo()
                    {
                        VertexBindingDescriptions   = new [] { Vertex.GetBindingDescription() },
                        VertexAttributeDescriptions = Vertex.GetAttributeDescriptions()
                    },
                    InputAssemblyState = new PipelineInputAssemblyStateCreateInfo
                    {
                        PrimitiveRestartEnable = false,
                        Topology = PrimitiveTopology.TriangleList
                    },
                    ViewportState = new PipelineViewportStateCreateInfo
                    {
                        Viewports = new[]
                        {
                            new Viewport
                            {
                                X        = 0f,
                                Y        = 0f,
                                Width    = targetExtent.Width,
                                Height   = targetExtent.Height,
                                MaxDepth = 1,
                                MinDepth = 0
                            }
                        },
                        Scissors = new[]
                        {
                            new Rect2D
                            {
                                Offset = new Offset2D(),
                                Extent = targetExtent
                            }
                        }
                    },
                    RasterizationState = new PipelineRasterizationStateCreateInfo
                    {
                        DepthClampEnable        = false,
                        RasterizerDiscardEnable = false,
                        PolygonMode             = PolygonMode.Fill,
                        LineWidth       = 1,
                        CullMode        = CullModeFlags.Back,
                        FrontFace       = FrontFace.CounterClockwise,
                        DepthBiasEnable = false
                    },
                    MultisampleState = new PipelineMultisampleStateCreateInfo
                    {
                        SampleShadingEnable  = false,
                        RasterizationSamples = SampleCountFlags.SampleCount1,
                        MinSampleShading     = 1
                    },
                    ColorBlendState = new PipelineColorBlendStateCreateInfo
                    {
                        Attachments = new[]
                        {
                            new PipelineColorBlendAttachmentState
                            {
                                ColorWriteMask = ColorComponentFlags.R
                                                 | ColorComponentFlags.G
                                                 | ColorComponentFlags.B
                                                 | ColorComponentFlags.A,
                                BlendEnable                 = false,
                                SourceColorBlendFactor      = BlendFactor.One,
                                DestinationColorBlendFactor = BlendFactor.Zero,
                                ColorBlendOp                = BlendOp.Add,
                                SourceAlphaBlendFactor      = BlendFactor.One,
                                DestinationAlphaBlendFactor = BlendFactor.Zero,
                                AlphaBlendOp                = BlendOp.Add
                            }
                        },
                        LogicOpEnable  = false,
                        LogicOp        = LogicOp.Copy,
                        BlendConstants = new float[] { 0, 0, 0, 0 }
                    },
                    DepthStencilState = new PipelineDepthStencilStateCreateInfo
                    {
                        DepthTestEnable       = true,
                        DepthWriteEnable      = true,
                        DepthCompareOp        = CompareOp.Less,
                        DepthBoundsTestEnable = false,
                        MinDepthBounds        = 0,
                        MaxDepthBounds        = 1,
                        StencilTestEnable     = false
                    },
                    Stages = new[]
                    {
                        new PipelineShaderStageCreateInfo
                        {
                            Stage  = ShaderStageFlags.Vertex,
                            Module = this.vertexShader,
                            Name   = "main"
                        },
                        new PipelineShaderStageCreateInfo
                        {
                            Stage  = ShaderStageFlags.Fragment,
                            Module = this.fragmentShader,
                            Name   = "main"
                        }
                    }
                }
            }).Single();

            commandBuffer.BindPipeline(PipelineBindPoint.Graphics, this.pipeline);

            commandBuffer.BindVertexBuffers(0, this.vertexBuffer.Buffer, (DeviceSize)0);

            commandBuffer.BindIndexBuffer(this.indexBuffer.Buffer, 0, IndexType.UInt32);

            commandBuffer.BindDescriptorSets(PipelineBindPoint.Graphics, pipelineLayout, 0, descriptorSet, null);

            commandBuffer.DrawIndexed((uint)indexCount, 1, 0, 0, 0);
        }
示例#5
0
 /// <summary> bind vertex and index buffers </summary>
 public virtual void Bind(CommandBuffer cmd)
 {
     cmd.BindVertexBuffer(vbo);
     cmd.BindIndexBuffer(ibo, IndexBufferType);
 }
示例#6
0
        public override void Bind(Device device, RenderPass renderPass, CommandBuffer commandBuffer, Extent2D targetExtent)
        {
            this.aspectRatio = (float)targetExtent.Width / (float)targetExtent.Height;

            this.projectionMatrix = mat4.Translate(0, -1, 0) * mat4.Scale(256f / targetExtent.Width, 256f / targetExtent.Height, 1);

            this.renderStateBuffer.Update(new RenderState {
                Projection = mat4.Identity, View = mat4.Identity
            });

            this.pipeline = device.CreateGraphicsPipeline(null,
                                                          new[]
            {
                new PipelineShaderStageCreateInfo
                {
                    Stage  = ShaderStageFlags.Vertex,
                    Module = this.vertexShader,
                    Name   = "main"
                },
                new PipelineShaderStageCreateInfo
                {
                    Stage  = ShaderStageFlags.Fragment,
                    Module = this.fragmentShader,
                    Name   = "main"
                }
            },
                                                          new PipelineVertexInputStateCreateInfo()
            {
                VertexBindingDescriptions   = new[] { Vertex.GetBindingDescription(), SpriteData.GetBindingDescription() },
                VertexAttributeDescriptions = Vertex.GetAttributeDescriptions().Concat(SpriteData.GetAttributeDescriptions()).ToArray()
            },
                                                          new PipelineInputAssemblyStateCreateInfo
            {
                Topology = PrimitiveTopology.TriangleList
            },
                                                          new PipelineRasterizationStateCreateInfo
            {
                PolygonMode = PolygonMode.Fill,
                LineWidth   = 1,
                CullMode    = CullModeFlags.Back,
                FrontFace   = FrontFace.CounterClockwise
            },
                                                          this.pipelineLayout,
                                                          renderPass,
                                                          0,
                                                          null,
                                                          0,
                                                          viewportState: new PipelineViewportStateCreateInfo
            {
                Viewports = new[]
                {
                    new Viewport
                    {
                        X        = 0f,
                        Y        = 0f,
                        Width    = targetExtent.Width,
                        Height   = targetExtent.Height,
                        MaxDepth = 1,
                        MinDepth = 0
                    }
                },
                Scissors = new[]
                {
                    new Rect2D(targetExtent)
                }
            },
                                                          multisampleState: new PipelineMultisampleStateCreateInfo
            {
                SampleShadingEnable  = false,
                RasterizationSamples = SampleCountFlags.SampleCount1,
                MinSampleShading     = 1
            },
                                                          depthStencilState: new PipelineDepthStencilStateCreateInfo
            {
                DepthTestEnable  = false,
                DepthWriteEnable = true,
                DepthCompareOp   = CompareOp.Less,
                MinDepthBounds   = 0,
                MaxDepthBounds   = 1
            },
                                                          colorBlendState: new PipelineColorBlendStateCreateInfo
            {
                Attachments = new[]
                {
                    new PipelineColorBlendAttachmentState
                    {
                        ColorWriteMask = ColorComponentFlags.R
                                         | ColorComponentFlags.G
                                         | ColorComponentFlags.B
                                         | ColorComponentFlags.A,
                        BlendEnable                 = true,
                        SourceColorBlendFactor      = BlendFactor.SourceAlpha,
                        DestinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha,
                        ColorBlendOp                = BlendOp.Add,
                        SourceAlphaBlendFactor      = BlendFactor.One,
                        DestinationAlphaBlendFactor = BlendFactor.One,
                        AlphaBlendOp                = BlendOp.Max
                    }
                },
                BlendConstants = new float[] { 0, 0, 0, 0 }
            });

            commandBuffer.BindPipeline(PipelineBindPoint.Graphics, this.pipeline);

            commandBuffer.BindVertexBuffers(0, new[] { this.vertexBuffer.Buffer, this.spriteDataBuffer.Buffer }, new DeviceSize[] { 0, 0 });

            commandBuffer.BindIndexBuffer(this.indexBuffer.Buffer, 0, IndexType.Uint32);

            commandBuffer.BindDescriptorSets(PipelineBindPoint.Graphics, pipelineLayout, 0, this.descriptorSet, null);

            commandBuffer.DrawIndexedIndirect(this.indirectCommandBuffer.Buffer, 0, 1, 0);
        }