Debian Codegraph @

Sources/nCine/Graphics/RHI/Software/SwBuffer.cpp

raw
1 #include "SwBuffer.h"
2 #include "SwDevice.h"
3
4 #include <cstring>
5
6 namespace nCine::RHI::Software
7 {
8 std::uint32_t SwBuffer::_nextHandle = 1;
9
10 SwBuffer::SwBuffer(BufferTarget target)
11 : _handle(_nextHandle++), _target(target)
12 {
13 }
14
15 bool SwBuffer::Bind() const
16 {
17 // The software backend does not consult a bound-buffer cache; the effects read from the ranges
18 // forwarded by BindBufferRange(), so this only reports that a bind "was issued"
19 return true;
20 }
21
22 bool SwBuffer::Unbind() const
23 {
24 return true;
25 }
26
27 void SwBuffer::BufferData(std::size_t size, const void* data, BufferUsage usage)
28 {
29 static_cast<void>(usage);
30 _storage.assign(size, std::uint8_t(0));
31 if (data != nullptr && size > 0) {
32 std::memcpy(_storage.data(), data, size);
33 }
34 }
35
36 void SwBuffer::BufferSubData(std::size_t offset, std::size_t size, const void* data)
37 {
38 if (data == nullptr || size == 0 || offset + size > _storage.size()) {
39 return;
40 }
41 std::memcpy(_storage.data() + offset, data, size);
42 }
43
44 void SwBuffer::BufferStorage(std::size_t size, const void* data, MapFlags flags)
45 {
46 // The software backend keeps everything in a resizable host store, so "immutable storage" is just
47 // a plain (re)allocation; the storage/mapping flags do not apply
48 static_cast<void>(flags);
49 _storage.assign(size, std::uint8_t(0));
50 if (data != nullptr && size > 0) {
51 std::memcpy(_storage.data(), data, size);
52 }
53 }
54
55 void SwBuffer::BindBufferBase(std::uint32_t index)
56 {
57 BindBufferRange(index, 0, _storage.size());
58 }
59
60 void SwBuffer::BindBufferRange(std::uint32_t index, std::size_t offset, std::size_t size)
61 {
62 if (offset > _storage.size()) {
63 return;
64 }
65 if (offset + size > _storage.size()) {
66 size = _storage.size() - offset;
67 }
68 SwDevice::BindUniformRange(index, _storage.data() + offset, std::uint32_t(size));
69 }
70
71 void* SwBuffer::MapBufferRange(std::size_t offset, std::size_t length, MapFlags access)
72 {
73 static_cast<void>(length);
74 static_cast<void>(access);
75 if (offset > _storage.size()) {
76 return nullptr;
77 }
78 return _storage.data() + offset;
79 }
80
81 void SwBuffer::FlushMappedBufferRange(std::size_t offset, std::size_t length)
82 {
83 static_cast<void>(offset);
84 static_cast<void>(length);
85 }
86
87 bool SwBuffer::Unmap()
88 {
89 return true;
90 }
91
92 void SwBuffer::SetObjectLabel(StringView label)
93 {
94 static_cast<void>(label);
95 }
96 }