mesh.pipeline.hpp

1
2
3
4
5
6
7
8
9
#pragma once


#include <planet/affine/point3d.hpp>
#include <planet/vk/engine/app.hpp>
#include <planet/vk/engine/render_parameters.hpp>


namespace planet::vk::engine::pipeline {

2D triangle mesh with per-vertex colour

13
14
15
16
17
18
19
20
21
22
23
24
25
    class mesh final {
      public:
        mesh(engine::renderer &,
             std::string_view vertex_spirv,
             blend_mode = blend_mode::multiply);

        vk::graphics_pipeline pipeline;


        struct vertex {
            planet::affine::point3d p;
            colour c;
        };

Mesh data to be drawn

29
30
31
32
33
34
35
36
37
38
39
40
41
42
        class data {
            friend class mesh;
            std::vector<vertex> vertices;
            std::vector<std::uint32_t> indices;


          public:
            void clear() {
                vertices.clear();
                indices.clear();
            }
            [[nodiscard]] bool empty() const noexcept {
                return vertices.empty();
            }

2D Z layer height

46
            float z_layer = 0.75f;

Draw a triangle mesh

50
51
52
53
54
55
56
57
58
59
60
            void draw(std::span<vertex const>, std::span<std::uint32_t const>);
            void
                    draw(std::span<vertex const>,
                         std::span<std::uint32_t const>,
                         planet::affine::point3d const &);
            void
                    draw(std::span<vertex const>,
                         std::span<std::uint32_t const>,
                         planet::affine::point3d const &,
                         colour const &);
        };

This frame's draw data and commands

64
        data this_frame;

Draw already captured data

66
        void draw(data const &);

Add draw commands to command buffer

70
71
72
73
74
75
76
77
78
79
80
        void render(render_parameters);


      private:
        std::array<buffer<vertex>, max_frames_in_flight> vertex_buffers;

        std::array<buffer<std::uint32_t>, max_frames_in_flight> index_buffers;
    };


}