]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/structurebuilder.cpp
Fixes for handling extended alignment in GLSL
[libs/gl.git] / source / backends / vulkan / structurebuilder.cpp
1 #include "error.h"
2 #include "structurebuilder.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GL {
8
9 StructureBuilder::StructureBuilder(vector<char> &s, unsigned max_parts):
10         storage(s)
11 {
12         storage.clear();
13         parts.reserve(max_parts);
14 }
15
16 void *&StructureBuilder::add(std::size_t size, std::size_t align)
17 {
18         if(parts.size()>=parts.capacity())
19                 throw invalid_operation("StructureBuilder::add");
20
21         parts.emplace_back();
22         Part &part = parts.back();
23         part.offset = storage.size()+align-1;
24         part.offset -= part.offset%align;
25
26         storage.resize(part.offset+size);
27         for(Part &p: parts)
28                 p.pointer = storage.data()+p.offset;
29
30         return parts.back().pointer;
31 }
32
33 } // namespace GL
34 } // namespace Msp