forked from maplibre/maplibre-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniform_buffer_gl.hpp
74 lines (57 loc) · 2.44 KB
/
uniform_buffer_gl.hpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include <mbgl/gfx/uniform_buffer.hpp>
#include <mbgl/gl/types.hpp>
#include <mbgl/gl/buffer_allocator.hpp>
namespace mbgl {
namespace gl {
class UniformBufferGL final : public gfx::UniformBuffer {
UniformBufferGL(const UniformBufferGL&);
public:
UniformBufferGL(const void* data, std::size_t size_, IBufferAllocator& allocator);
~UniformBufferGL() override;
UniformBufferGL(UniformBufferGL&& rhs) noexcept;
UniformBufferGL& operator=(const UniformBufferGL& rhs) = delete;
BufferID getID() const;
gl::RelocatableBuffer<UniformBufferGL>& getManagedBuffer() noexcept { return managedBuffer; }
const gl::RelocatableBuffer<UniformBufferGL>& getManagedBuffer() const noexcept { return managedBuffer; }
UniformBufferGL clone() const { return {*this}; }
// gfx::UniformBuffer
void update(const void* data, std::size_t dataSize) override;
private:
// unique id used for debugging and profiling purposes
// localID should not be used as unique id because a const buffer pool is managed using IBufferAllocator
// Currently unique IDs for constant buffers are only used when Tracy profiling is enabled
#ifdef MLN_TRACY_ENABLE
int64_t uniqueDebugId = -1;
#endif
// If the requested UBO size is too large for the allocator, the UBO will manage its own allocation
bool isManagedAllocation = false;
BufferID localID;
gl::RelocatableBuffer<UniformBufferGL> managedBuffer;
friend class UniformBufferArrayGL;
};
/// Stores a collection of uniform buffers by name
class UniformBufferArrayGL final : public gfx::UniformBufferArray {
public:
UniformBufferArrayGL() = default;
UniformBufferArrayGL(UniformBufferArrayGL&& other)
: UniformBufferArray(std::move(other)) {}
UniformBufferArrayGL(const UniformBufferArrayGL&) = delete;
UniformBufferArrayGL& operator=(UniformBufferArrayGL&& other) {
UniformBufferArray::operator=(std::move(other));
return *this;
}
UniformBufferArrayGL& operator=(const UniformBufferArrayGL& other) {
UniformBufferArray::operator=(other);
return *this;
}
void bind() const;
void unbind() const;
void bind(gfx::RenderPass&) override { bind(); }
private:
std::unique_ptr<gfx::UniformBuffer> copy(const gfx::UniformBuffer& uniformBuffers) override {
return std::make_unique<UniformBufferGL>(static_cast<const UniformBufferGL&>(uniformBuffers).clone());
}
};
} // namespace gl
} // namespace mbgl