Example #1
0
 /// <summary>
 /// Runs when component is enabled in the scene
 /// </summary>
 public override Task OnEnable()
 => Task.Run(() =>
 {
     var module    = Engine.Instance.GetModule <GraphicsModule>();
     var LIGHT_KEY = "_LIGHT";
     _framebuffer  = new API.Framebuffer(
         module.RenderPasses[LIGHT_KEY],
         1024, 1024
         );
     if (_pipeline == null)
     {
         _pipeline = new API.GraphicsPipeline(
             module.GraphicsService.PrimaryDevice,
             module.RenderPasses[LIGHT_KEY],
             new List <API.DescriptorLayout>
         {
             module.DescriptorLayouts["_PROJECTION"],
             module.DescriptorLayouts["_VIEW"],
             module.DescriptorLayouts["_MODEL"]
         },
             new List <API.ShaderModule>()
         {
             new API.ShaderModule(
                 module.GraphicsService.PrimaryDevice,
                 "Assets/Shaders/Default/Light.vert"
                 ),
             new API.ShaderModule(
                 module.GraphicsService.PrimaryDevice,
                 "Assets/Shaders/Default/Light.frag"
                 )
         },
             new PipelineInputBuilder()
             );
     }
 });
Example #2
0
        public unsafe void BeginRenderPass(
            Framebuffer framebuffer,
            VkSubpassContents subpassContents
            )
        {
            var renderPass  = framebuffer.RenderPass;
            var clearValues = new NativeList <VkClearValue>();

            foreach (var attachment in renderPass.Attachments)
            {
                if (attachment.Format == RenderPassAttachment.Default.Format)
                {
                    clearValues.Add(new VkClearValue()
                    {
                        color = new VkClearColorValue(
                            0.0f,
                            0.0f,
                            0.0f,
                            0.0f
                            )
                    });
                }
                else if (attachment.Format == RenderPassAttachment.DefaultDepth.Format)
                {
                    clearValues.Add(new VkClearValue()
                    {
                        depthStencil = new VkClearDepthStencilValue(
                            1.0f,
                            0
                            )
                    });
                }
            }

            var renderPassBeginInfo = new VkRenderPassBeginInfo
            {
                sType           = VkStructureType.RenderPassBeginInfo,
                clearValueCount = clearValues.Count,
                pClearValues    = (VkClearValue *)clearValues.Data.ToPointer(),
                framebuffer     = framebuffer.Handle,
                renderPass      = renderPass.Handle,
                renderArea      = new VkRect2D
                {
                    offset = new VkOffset2D
                    {
                        x = 0,
                        y = 0
                    },
                    extent = new VkExtent2D
                    {
                        width  = framebuffer.Width,
                        height = framebuffer.Height
                    }
                }
            };

            VulkanNative.vkCmdBeginRenderPass(
                _handle,
                &renderPassBeginInfo,
                subpassContents
                );
            // update the layout for images
            for (int i = 0; i < framebuffer.Images.Count; i++)
            {
                Array.Fill(framebuffer.Images[i].Layout, framebuffer.RenderPass.Attachments[i].FinalLayout);
            }
        }