VertexLayout.cpp 1.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Created by Charlotte on 28.05.2021.
//

#include "vkcv/VertexLayout.hpp"

namespace vkcv {
    uint32_t static getFormatSize(VertexFormat format) {
        switch (format) {
            case VertexFormat::FLOAT:
                return 4;
            case VertexFormat::FLOAT2:
                return 8;
            case VertexFormat::FLOAT3:
                return 12;
            case VertexFormat::FLOAT4:
                return 16;
            case VertexFormat::INT:
                return 4;
            case VertexFormat::INT2:
                return 8;
            case VertexFormat::INT3:
                return 12;
            case VertexFormat::INT4:
                return 16;
            default:
                break;
        }
        std::cout << "VertexLayout: No format given" << std::endl;
        return 0;
    }

    VertexInputAttachment::VertexInputAttachment(uint32_t location, uint32_t binding, VertexFormat format, uint32_t offset) noexcept:
            location{location},
            binding{binding},
            format{format},
            offset{offset}
            {}

    VertexLayout::VertexLayout() noexcept :
    stride{0},
    attachmentMap()
    {}

    VertexLayout::VertexLayout(const std::vector<VertexInputAttachment> &inputs) noexcept {
        stride = 0;
        for (const auto &input : inputs) {
            attachmentMap.insert(std::make_pair(input.location, input));
            stride += getFormatSize(input.format);
        }
    }

}