private void RenderMeshInstances(CommandBuffer cmd, MeshRenderer mesh, DeviceBuffer instanceBuffer, uint instanceAmount, uint instanceIndex, RenderContext context)
        {
            int matIndex = 0;

            foreach (var subMesh in mesh.mesh.subMeshes)
            {
                var material =
                    mesh.materials.Length == 0
                                        ? defaultMaterial
                                        :(matIndex < mesh.materials.Length ? mesh.materials[matIndex] : mesh.materials[0]);

                var pipeline = material.GetPipeline();

                cmd.UsePipeline(pipeline);

                if (pipeline.instanced)
                {
                    cmd.BindVertexBuffer(instanceBuffer, Pipeline.VERTEX_INSTANCE_BUFFER_BIND_ID);
                    cmd.DrawIndexed(subMesh, instanceAmount, instanceIndex - instanceAmount);
                }
                else
                {
                    //TODO: Non-instanced rendering
                }
            }
        }
Esempio n. 2
0
        private void RenderMeshInstances(CommandBuffer cmd, Mesh mesh, Material material, DeviceBuffer instanceBuffer, uint instanceAmount, uint instanceIndex, RenderContext context)
        {
            foreach (var subMesh in mesh.subMeshes)
            {
                var pipeline = material.GetPipeline();

                cmd.UsePipeline(pipeline);

                if (pipeline.instanced)
                {
                    cmd.BindVertexBuffer(instanceBuffer, Pipeline.VERTEX_INSTANCE_BUFFER_BIND_ID);
                    cmd.DrawIndexed(subMesh, instanceAmount, instanceIndex - instanceAmount);
                }
            }
        }
Esempio n. 3
0
        void recordDraw(CommandBuffer cmd, Framebuffer fb)
        {
            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.Draw(36);

            pipeline.RenderPass.End(cmd);
        }
Esempio n. 4
0
        public void Draw(CommandBuffer cmd, PipelineLayout pipelineLayout, Buffer instanceBuf, bool shadowPass = false, params InstancedCmd[] instances)
        {
            cmd.BindVertexBuffer(instanceBuf, 1);
            uint firstInstance = 0;

            for (int i = 0; i < instances.Length; i++)
            {
                foreach (Primitive p in Meshes[instances[i].meshIdx].Primitives)
                {
                    if (!shadowPass)
                    {
                        cmd.PushConstant(pipelineLayout, VkShaderStageFlags.Fragment, (int)p.material, (uint)Marshal.SizeOf <Matrix4x4>());
                    }
                    cmd.DrawIndexed(p.indexCount, instances[i].count, p.indexBase, p.vertexBase, firstInstance);
                }
                firstInstance += instances[i].count;
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 /// <summary> bind vertex and index buffers </summary>
 public virtual void Bind(CommandBuffer cmd)
 {
     cmd.BindVertexBuffer(vbo);
     cmd.BindIndexBuffer(ibo, IndexBufferType);
 }