Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
Buffer.hpp
1
#pragma once
2
3
#include <stdint.h>
4
5
#include <Common/Containers/Bitset.hpp>
6
7
#include "Formats.hpp"
8
9
namespace
Grindstone::GraphicsAPI {
10
enum class
BufferUsage : uint8_t {
11
Vertex = 1,
12
Index = 1 << 1,
13
Uniform = 1 << 2,
14
Storage = 1 << 3,
15
Indirect = 1 << 4,
16
TransferSrc = 1 << 5,
17
TransferDst = 1 << 6
18
};
19
}
20
21
template
<>
22
struct
EnumFlagsTraits
<Grindstone::GraphicsAPI::BufferUsage> {
23
static
constexpr
const
char
* names[] = {
24
"Vertex"
,
25
"Index"
,
26
"Uniform"
,
27
"Storage"
,
28
"Indirect"
,
29
"TransferSrc"
,
30
"TransferDst"
31
};
32
static
constexpr
size_t
size = 7;
33
};
34
35
inline
Grindstone::GraphicsAPI::BufferUsage operator|(Grindstone::GraphicsAPI::BufferUsage a,
const
Grindstone::GraphicsAPI::BufferUsage b) {
36
using
Underlying = uint8_t;
37
return
static_cast<
Grindstone::GraphicsAPI::BufferUsage
>
(
static_cast<
Underlying
>
(a) |
static_cast<
Underlying
>
(b));
38
}
39
40
inline
Grindstone::GraphicsAPI::BufferUsage operator&(Grindstone::GraphicsAPI::BufferUsage a,
const
Grindstone::GraphicsAPI::BufferUsage b) {
41
using
Underlying = uint8_t;
42
return
static_cast<
Grindstone::GraphicsAPI::BufferUsage
>
(
static_cast<
Underlying
>
(a) &
static_cast<
Underlying
>
(b));
43
}
44
45
namespace
Grindstone::GraphicsAPI {
49
class
Buffer {
50
public
:
51
struct
CreateInfo
{
52
const
char
* debugName;
53
const
void
* content;
54
size_t
bufferSize;
55
Grindstone::Containers::BitsetFlags<Grindstone::GraphicsAPI::BufferUsage>
bufferUsage;
56
MemoryUsage memoryUsage;
57
};
58
59
Buffer(
const
Grindstone::GraphicsAPI::Buffer::CreateInfo
& createInfo) :
60
debugName(createInfo.debugName),
61
bufferUsage(createInfo.bufferUsage),
62
memoryUsage(createInfo.memoryUsage),
63
bufferSize(createInfo.bufferSize) {};
64
65
virtual
~Buffer
() {}
66
virtual
void
* Map() = 0;
67
virtual
void
Unmap() = 0;
68
virtual
void
UploadData(
const
void
* data,
size_t
size,
size_t
offset = 0) = 0;
69
70
void
UploadData(
const
void
* data) {
71
UploadData(data, bufferSize, 0);
72
}
73
74
BufferUsage GetBufferUsage()
const
{
75
return
bufferUsage.GetValueEnum();
76
}
77
78
MemoryUsage GetMemoryUsage()
const
{
79
return
memoryUsage;
80
}
81
82
size_t
GetSize()
const
{
83
return
bufferSize;
84
}
85
86
protected
:
87
const
char
* debugName;
88
Grindstone::Containers::BitsetFlags<BufferUsage> bufferUsage;
89
MemoryUsage memoryUsage;
90
size_t
bufferSize;
91
void
* mappedMemoryPtr =
nullptr
;
92
};
93
};
Grindstone::Containers::BitsetFlags
Definition
Bitset.hpp:331
Grindstone::GraphicsAPI::Buffer
Definition
Buffer.hpp:49
EnumFlagsTraits
Definition
EnumTraits.hpp:51
Grindstone::GraphicsAPI::Buffer::CreateInfo
Definition
Buffer.hpp:51
sources
code
Common
Graphics
Buffer.hpp
Generated by
1.17.0