SimpleGL  1.1.0
A framework for platform independent rendering
batching_vk.cpp
Go to the documentation of this file.
1 
9 
10 #include <glm/glm.hpp>
11 
14 
15 using namespace std;
16 using namespace glm;
17 
18 namespace sgl {
19 
20  std::vector<uint8_t> BatchVK::vertexCode = {
21  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, 0x00, 0x39, 0x00, 0x00, 0x00,
22  0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00,
23  0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
24  0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
25  0x0f, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
26  0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
27  0x11, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00,
28  0x02, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x00, 0x04, 0x00, 0x09, 0x00, 0x47, 0x4c, 0x5f, 0x41,
29  0x52, 0x42, 0x5f, 0x73, 0x65, 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x64,
30  0x65, 0x72, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00,
31  0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00,
32  0x09, 0x00, 0x00, 0x00, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00,
33  0x05, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00,
34  0x05, 0x00, 0x06, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43,
35  0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x11, 0x00, 0x00, 0x00,
36  0x74, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00,
37  0x15, 0x00, 0x00, 0x00, 0x6d, 0x76, 0x70, 0x00, 0x05, 0x00, 0x06, 0x00, 0x16, 0x00, 0x00, 0x00,
38  0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00,
39  0x06, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x6f, 0x64, 0x65,
40  0x6c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
41  0x76, 0x69, 0x65, 0x77, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x16, 0x00, 0x00, 0x00,
42  0x02, 0x00, 0x00, 0x00, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00,
43  0x06, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x63, 0x6c, 0x69, 0x70,
44  0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x18, 0x00, 0x00, 0x00, 0x74, 0x72, 0x61, 0x6e,
45  0x73, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00,
46  0x2a, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x50, 0x65, 0x72, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78,
47  0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48  0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x05, 0x00, 0x03, 0x00,
49  0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x30, 0x00, 0x00, 0x00,
50  0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
51  0x09, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
52  0x0b, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
53  0x0f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
54  0x11, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00,
55  0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00,
56  0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57  0x48, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
58  0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
59  0x05, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
60  0x23, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00,
61  0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00,
62  0x16, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00,
63  0x16, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
64  0x48, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
65  0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
66  0x05, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
67  0x23, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00,
68  0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00,
69  0x16, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00,
70  0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00,
71  0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x2a, 0x00, 0x00, 0x00,
72  0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00,
73  0x2a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x30, 0x00, 0x00, 0x00,
74  0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
75  0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00,
76  0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00,
77  0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
78  0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
79  0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00,
80  0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00,
81  0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00,
82  0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00,
83  0x03, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00,
84  0x0f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00,
85  0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00,
86  0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00,
87  0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00,
88  0x07, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x06, 0x00, 0x16, 0x00, 0x00, 0x00,
89  0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
90  0x20, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,
91  0x3b, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
92  0x15, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
93  0x2b, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
94  0x20, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
95  0x2b, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
96  0x2b, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
97  0x2b, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98  0x1e, 0x00, 0x03, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
99  0x2b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
100  0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00,
101  0x2e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
102  0x2f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
103  0x2f, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00,
104  0x06, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x36, 0x00, 0x05, 0x00,
105  0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
106  0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00,
107  0x15, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00,
108  0x0c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00,
109  0x0c, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
110  0x11, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
111  0x41, 0x00, 0x05, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
112  0x1a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00,
113  0x1c, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
114  0x18, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00,
115  0x20, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x92, 0x00, 0x05, 0x00, 0x13, 0x00, 0x00, 0x00,
116  0x21, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00,
117  0x1b, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00,
118  0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00,
119  0x92, 0x00, 0x05, 0x00, 0x13, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
120  0x24, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
121  0x18, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00,
122  0x28, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x92, 0x00, 0x05, 0x00, 0x13, 0x00, 0x00, 0x00,
123  0x29, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00,
124  0x15, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00,
125  0x2d, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x2e, 0x00, 0x00, 0x00,
126  0x31, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00,
127  0x33, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00,
128  0x06, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
129  0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00,
130  0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00,
131  0x33, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00,
132  0x91, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00,
133  0x36, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
134  0x2c, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x38, 0x00, 0x00, 0x00,
135  0x37, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00
136  };
137 
138  std::vector<uint8_t> BatchVK::fragmentCode = {
139  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, 0x00, 0x1b, 0x00, 0x00, 0x00,
140  0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00,
141  0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
142  0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
143  0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
144  0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
145  0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00,
146  0x02, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x00, 0x04, 0x00, 0x09, 0x00, 0x47, 0x4c, 0x5f, 0x41,
147  0x52, 0x42, 0x5f, 0x73, 0x65, 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x64,
148  0x65, 0x72, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00,
149  0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00,
150  0x09, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x6f, 0x6c, 0x6f, 0x72,
151  0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x49,
152  0x6d, 0x61, 0x67, 0x65, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x11, 0x00, 0x00, 0x00,
153  0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00,
154  0x05, 0x00, 0x05, 0x00, 0x15, 0x00, 0x00, 0x00, 0x66, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f,
155  0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x17, 0x00, 0x00, 0x00, 0x76, 0x65, 0x72, 0x74,
156  0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x47, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00,
157  0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00,
158  0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00,
159  0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x15, 0x00, 0x00, 0x00,
160  0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00,
161  0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
162  0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00,
163  0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00,
164  0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
165  0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x00, 0x00,
166  0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00,
168  0x0b, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
169  0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
170  0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00,
171  0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00,
172  0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00,
173  0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00,
174  0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00,
175  0x15, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00,
176  0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00,
177  0x17, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00,
178  0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00,
179  0x05, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
180  0x07, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
181  0x0d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
182  0x11, 0x00, 0x00, 0x00, 0x57, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
183  0x0e, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00,
184  0x13, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
185  0x17, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00,
186  0x09, 0x00, 0x00, 0x00, 0x85, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00,
187  0x18, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x15, 0x00, 0x00, 0x00,
188  0x1a, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00
189  };
190 
191  TextureImage* BatchVK::defaultTexture;
192 
193  BatchVK::BatchVK(int capacity) : Batch() {
194  /* Create the vertex and fragment shader module */
195  ShaderModule vertShader(BatchVK::vertexCode, ShaderStageBit::VERTEX_BIT);
196  ShaderModule fragShader(BatchVK::fragmentCode, ShaderStageBit::FRAGMENT_BIT);
197  vector<ShaderModule*> shaderModules = {&vertShader, &fragShader};
198 
199  /* Create the render pass and graphics pipeline */
200  renderPass = new RenderPass();
201  graphicsPipeline = new GraphicsPipeline(renderPass, shaderModules);
202 
203  /* Generate pools and framebuffers */
207 
208  /* Create vertex buffers */
209  positionBuffer = new VertexBuffer(capacity * sizeof (vec3));
210  colorBuffer = new VertexBuffer(capacity * sizeof (vec4));
211  texCoordBuffer = new VertexBuffer(capacity * sizeof (vec2));
212  normalBuffer = new VertexBuffer(capacity * sizeof (vec3));
213 
214  /* Create uniform buffer */
215  transformationBuffer = new UniformBuffer(sizeof (Transformation));
216 
217  /* Create descriptor set */
218  descriptorSet = new DescriptorSet(graphicsPipeline);
219 
220  /* Allocate command buffer */
221  commandBuffer = new CommandBuffer();
222 
223  /* Create semaphores and acquire the first image */
226 
227  /* Vulkan clip space has inverted Y and half Z */
228  transformation.clip = glm::mat4(1.0f, 0.0f, 0.0f, 0.0f,
229  0.0f, -1.0f, 0.0f, 0.0f,
230  0.0f, 0.0f, 0.5f, 0.0f,
231  0.0f, 0.0f, 0.5f, 1.0f);
232 
233  /* Apply transformation */
235  transformationBuffer->upload(transformData);
236  descriptorSet->update(transformationBuffer, transformData);
237 
238  /* Generate default texture, this texture contains 1 white pixel */
239  /* This texture will work like some kind of a bitmask */
240  vector<uint8_t> data = {0xFF, 0xFF, 0xFF, 0xFF};
241  BatchVK::defaultTexture = new TextureImage(1, 1);
242  BatchVK::defaultTexture->upload(data);
243  TextureImage::setCurrent(BatchVK::defaultTexture);
244  }
245 
247  /* Delete uniform buffers */
248  delete transformationBuffer;
249 
250  /* Delete vertex buffers */
251  delete normalBuffer;
252  delete texCoordBuffer;
253  delete colorBuffer;
254  delete positionBuffer;
255 
256  /* Delete graphics pipeline */
257  delete graphicsPipeline;
258 
259  /* Delete render pass */
260  delete renderPass;
261  }
262 
263  void BatchVK::flush() {
264  /* Only flush if there is at least one vertex */
265  if (numVertices > 0) {
266  /* Fill colors */
267  if (colors.size() == 0) {
268  /* No color: Fill with white */
269  while (colors.size() < vertices.size()) {
270  color(vec4(1.0f));
271  }
272  } else if (colors.size() < vertices.size()) {
273  /* Less colors than vertices: Fill with last color */
274  vec4 lastColor = colors.back();
275  while (colors.size() < vertices.size()) {
276  color(lastColor);
277  }
278  }
279 
280  /* Fill texCoords */
281  if (texCoords.size() == 0) {
282  /* No texture coordinates, bind mask texture */
283  TextureImage::setCurrent(BatchVK::defaultTexture);
284  }
285  while (texCoords.size() < vertices.size()) {
286  texCoord(vec2(1.0f));
287  }
288 
289  /* Fill normals */
290  while (normals.size() < vertices.size()) {
291  normal(vec3(0.0f));
292  }
293 
294  /* Begin recording and render pass */
295  commandBuffer->begin();
296  commandBuffer->beginRenderPass(renderPass);
297 
298  /* Bind graphics pipeline */
299  commandBuffer->bindPipeline(graphicsPipeline);
300 
301  /* Upload vertex data */
302  positionBuffer->upload(vertices);
303  colorBuffer->upload(colors);
304  texCoordBuffer->upload(texCoords);
305  normalBuffer->upload(normals);
306 
307  /* Bind vertex buffers */
308  commandBuffer->bindVertexBuffer(positionBuffer, 0);
309  commandBuffer->bindVertexBuffer(colorBuffer, 1);
310  commandBuffer->bindVertexBuffer(texCoordBuffer, 2);
311  commandBuffer->bindVertexBuffer(normalBuffer, 3);
312 
313  /* Bind descriptor sets */
314  descriptorSet->update(TextureImage::getCurrent());
315  commandBuffer->bindDescriptorSet(descriptorSet, graphicsPipeline, 0);
316 
317  /* Draw batch */
318  commandBuffer->draw(numVertices);
319 
320  /* End render pass and recording */
321  commandBuffer->endRenderPass();
322  commandBuffer->end();
323 
324  /* Submit command buffer */
325  commandBuffer->submit();
326 
327  /* Clear lists */
328  vertices.clear();
329  colors.clear();
330  texCoords.clear();
331  normals.clear();
332  numVertices = 0;
333  }
334  }
335 }
void bindVertexBuffer(VertexBuffer *vertexBuffer, uint32_t binding)
Binds a vertex buffer to the command buffer.
void draw(uint32_t vertexCount)
Draws primitives.
Indicates to use VK_SHADER_STAGE_VERTEX_BIT.
void end()
Ends recording of the command buffer.
void color(float r, float g, float b)
Defines a new color with specified components.
Definition: batching.cpp:64
Swapchain * getSwapchain()
Returns the swapchain of this context.
static VulkanContext * getCurrent()
Returns the current Vulkan context.
void createCommandPool()
Creates the command pool for this context.
glm::mat4 projection
The projection matrix.
Definition: transform.hpp:49
void endRenderPass()
Ends the current render pass.
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18
glm::mat4 view
The view matrix.
Definition: transform.hpp:46
void begin()
Begins recording of the command buffer.
This struct contains information to calculate the Model-View-Projection-Matrix.
Definition: transform.hpp:40
std::vector< glm::vec3 > vertices
The storage for vertices.
Definition: batching.hpp:39
This class wraps a Vulkan command buffer.
void createFramebuffers(RenderPass *renderPass)
Creates the swapchain framebuffers for this context.
Indicates to use VK_SHADER_STAGE_FRAGMENT_BIT.
void texCoord(float s, float t)
Defines a new texture coordinate with specified values.
Definition: batching.cpp:80
static TextureImage * getCurrent()
Returns the currently used texture image.
void beginRenderPass(RenderPass *renderPass)
Begins a render pass.
This class wraps a Vulkan texture image.
void submit()
Submits the command buffer.
void upload(std::vector< glm::mat2 > data)
Uploads data to the uniform buffer.
void normal(float nx, float ny, float nz)
Defines a new normal with specified values.
Definition: batching.cpp:88
void flush() override
Flushes the batch, could be used if the batch would overflow.
This class wraps a Vulkan descriptor set.
int numVertices
The counter for the number of vertices.
Definition: batching.hpp:36
void bindPipeline(GraphicsPipeline *pipeline)
Binds a graphics pipeline to the command buffer.
std::vector< glm::vec2 > texCoords
The storage for texture coordinates.
Definition: batching.hpp:45
This class wraps a Vulkan vertex buffer.
void upload(std::vector< float > data)
Uploads data to the vertex buffer.
This class defines methods for batch rendering.
Definition: batching.hpp:26
Transformation transformation
The transformation for the batch.
Definition: batching.hpp:30
void createDescriptorPool()
Create the descriptor pool for this context.
This class wraps a Vulkan shader module.
This class wraps a Vulkan graphics pipeline.
std::vector< glm::vec4 > colors
The storage for colors.
Definition: batching.hpp:42
This class wraps a Vulkan uniform buffer.
void update(UniformBuffer *uniformBuffer, std::vector< glm::mat2 > data)
Updates the descriptor set.
This class wraps a Vulkan render pass.
Definition: render_pass.hpp:22
~BatchVK(void)
Destroys a batch.
void bindDescriptorSet(DescriptorSet *descriptorSet, GraphicsPipeline *graphicsPipeline, uint32_t binding)
Binds a descriptor set to the command buffer.
glm::mat4 clip
The clip matrix.
Definition: transform.hpp:52
void acquireNextImage()
Updates the index for the swapchain images.
Definition: swapchain.cpp:163
static void setCurrent(TextureImage *current)
Sets the currently used texture image.
glm::mat4 model
The model matrix.
Definition: transform.hpp:43
std::vector< glm::vec3 > normals
The storage for normals.
Definition: batching.hpp:48
void createRenderFence()
Creates the render fence.