Esempio n. 1
0
        public MeshRenderer(Graphics g, Texture2D tex, string vertexShader, string fragmentShader, int maxInstances = 1024, int maxUniqueMeshes = 8)
        {
            MaxInstances    = maxInstances;
            MaxUniqueMeshes = maxUniqueMeshes;
            Graphics        = g;
            Texture         = tex;
            Instances       = new VKBuffer[maxUniqueMeshes];
            Count           = new int[maxUniqueMeshes];
            Meshes          = new Mesh[maxUniqueMeshes];
            for (var i = 0; i < maxUniqueMeshes; i++)
            {
                Instances[i] = VKBuffer.InstanceInfo <MeshRenderInfo>(g, maxInstances);
            }
            TempInstances      = new MeshInfo[maxInstances];
            InstanceCopyBuffer = new MeshRenderInfo[maxInstances];
            UProjection        = VKBuffer.UniformBuffer <ViewProjection>(g, 1);
            UTime = VKBuffer.UniformBuffer <float>(g, 1);

            Pipeline = new PipelineController(Graphics);
            Pipeline.ClearDepthOnBeginPass = true;
            Pipeline.DepthTest             = false;
            Pipeline.DepthWrite            = false;
            Pipeline.BlendMode             = BlendMode.AlphaPremultiplied;
            Pipeline.Instancing            = true;
            Pipeline.InstanceInfoType      = typeof(MeshRenderInfo);
            Pipeline.Shaders         = new[] { vertexShader, fragmentShader };
            Pipeline.DescriptorItems = new[] {
                DescriptorItem.UniformBuffer(DescriptorItem.ShaderType.Vertex, UProjection),
                DescriptorItem.UniformBuffer(DescriptorItem.ShaderType.Vertex, UTime),
                DescriptorItem.CombinedImageSampler(DescriptorItem.ShaderType.Fragment, tex, DescriptorItem.SamplerFilter.Nearest, DescriptorItem.SamplerFilter.Nearest)
            };
        }
Esempio n. 2
0
        internal void RemoveFrameBuffer(PipelineController pipeline)
        {
            Framebuffer fb;

            if (Framebuffer.TryGetValue(pipeline, out fb))
            {
                fb?.Dispose();
                Framebuffer.Remove(pipeline);
            }
        }
        public void BeginPass(PipelineController pipeline)
        {
            var renderPassBeginInfo = new RenderPassBeginInfo(
                Image.GetFrameBuffer(pipeline),
                new Rect2D(0, 0, Image.Size.X, Image.Size.Y),
                new ClearColorValue(),
                new ClearDepthStencilValue(1f, 0)
                );

            CommandBuffer.CmdBeginRenderPass(renderPassBeginInfo);
            CommandBuffer.CmdBindDescriptorSet(PipelineBindPoint.Graphics, pipeline.PipelineLayout, pipeline.DescriptorSet);
            CommandBuffer.CmdBindPipeline(PipelineBindPoint.Graphics, pipeline.Pipeline);
        }
Esempio n. 4
0
        internal Framebuffer GetFrameBuffer(PipelineController pipeline)
        {
            Framebuffer fb;

            if (!Framebuffer.TryGetValue(pipeline, out fb))
            {
                fb = pipeline.RenderPass.CreateFramebuffer(new FramebufferCreateInfo(
                                                               new[] { View, DepthStencil.View },
                                                               Size.X, Size.Y));
                Framebuffer.Add(pipeline, fb);
            }
            return(fb);
        }