-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathindexed_buffer.hpp
More file actions
46 lines (38 loc) · 1.49 KB
/
Copy pathindexed_buffer.hpp
File metadata and controls
46 lines (38 loc) · 1.49 KB
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
#pragma once
#include <limitless/core/context_debug.hpp>
#include <unordered_map>
#include <stdexcept>
#include <string>
#include <memory>
#include <mutex>
#include <map>
#include <optional>
namespace Limitless {
class Buffer;
struct buffer_not_found : public std::runtime_error {
explicit buffer_not_found(const std::string& name) : runtime_error(name) {}
};
class IndexedBuffer final {
public:
enum class Type { UniformBuffer = GL_UNIFORM_BLOCK, ShaderStorage = GL_SHADER_STORAGE_BLOCK };
using Identifier = std::pair<Type, std::string>;
private:
std::map<Identifier, std::shared_ptr<Buffer>> buffers;
std::unordered_map<Type, GLint> current_bind;
std::map<Identifier, GLuint> bound;
public:
GLuint getBindingPoint(Type type, std::string_view name) noexcept;
void add(Type type, const std::string& name, std::shared_ptr<Buffer> buffer) noexcept;
void remove(Type type, const std::string& name);
std::optional<std::shared_ptr<Buffer>> get(Type type, const std::string& name) noexcept;
};
struct IndexedBufferData {
IndexedBuffer::Type target;
std::string name;
GLuint block_index;
GLuint bound_point;
bool index_connected {};
IndexedBufferData(IndexedBuffer::Type _target, std::string _name, GLuint _block_index, GLuint _bound_point)
: target{_target}, name{std::move(_name)}, block_index{_block_index}, bound_point{_bound_point} {}
};
}