1#include "RenderBuffer.h"
4#include "Rendering/IBuffers.h"
6#include "Foundation/Logging/Logger.h"
13void Cogs::Core::RenderBuffer::update(Renderer * renderer)
15 const size_t desiredSize = elementCount.getValue() ? elementCount.getValue() * elementSize.getValue() : bufferSize.getValue();
17 if (desiredSize == size && currentCount == bufferCount)
return;
22 currentCount = bufferCount;
24 void * data =
nullptr;
25 std::vector<uint32_t> fill;
30 for (
auto & p : parameters) {
31 if (p.key ==
"flags") {
32 if (p.value ==
"Raw") {
34 }
else if (p.value ==
"Structured") {
36 }
else if (p.value ==
"StructuredWithCounter") {
39 }
else if (p.key ==
"fill") {
40 if (p.type == ParsedDataType::UInt) {
41 fill.resize(size, p.uintValue);
44 else if (p.type == ParsedDataType::Int) {
45 char *dat = (
char*)&p.intValue;
47 memcpy(fill.data(), dat,
sizeof(int32_t));
50 else if (p.type == ParsedDataType::Float) {
51 char *dat = (
char*)&p.floatValue;
53 memcpy(fill.data(), dat,
sizeof(
float));
56 }
else if (p.key ==
"accessMode") {
57 if (p.value ==
"Read") {
59 }
else if (p.value ==
"Write") {
61 }
else if (p.value ==
"ReadWrite") {
64 }
else if (p.key ==
"usage") {
65 if (p.value ==
"Default") {
67 }
else if (p.value ==
"Dynamic") {
69 }
else if (p.value ==
"Staging") {
75 auto device = renderer->getDevice();
76 auto buffers = device->getBuffers();
77 frames.resize(currentCount);
78 if (currentCount == 1) {
79 buffer = buffers->loadBuffer(data, size, usage, accessMode, bindFlags,
static_cast<uint32_t
>(elementSize));
80 buffers->annotate(buffer,
"RenderBuffer");
83 LOG_ERROR(logger,
"Could not create buffer with size=%zd.", size);
86 this->buffers.resize(currentCount);
87 for (
size_t i = 0; i < currentCount; ++i) {
88 this->buffers[i] = buffers->loadBuffer(data, size, usage, accessMode, bindFlags,
static_cast<uint32_t
>(elementSize));
89 buffers->annotate(this->buffers[i],
"RenderBuffer");
92 LOG_ERROR(logger,
"Could not create buffer with size=%zd.", size);
98 buffers->annotate(buffer, getName());
102void Cogs::Core::RenderBuffer::release(Renderer * renderer)
104 auto device = renderer->getDevice();
105 auto buffers = device->getBuffers();
108 buffers->releaseBuffer(buffer);
110 for (
size_t i = 0; i < this->buffers.size(); ++i) {
111 buffers->releaseBuffer(this->buffers[i]);
Log implementation class.
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
EAccessMode
Access mode enumeration.
@ Read
The buffer can be mapped and read from by the CPU after creation.
@ Write
The buffer can be mapped and written to by the CPU after creation.
@ None
The buffer can not be either read from or written to by the CPU after creation.
EBindFlags
Bind flags enumeration.
@ StructuredBufferWithCounter
The buffer can be bound as a structured buffer and read or written from shaders, with an additional a...
@ RawBuffer
The buffer can be bound as a byte address buffer and read or written from shaders.
@ None
The buffer will not be bound to the graphics pipeline. Suitable for staging resources.
@ StructuredBuffer
The buffer can be bound as a structured buffer and read or written from shaders.
@ Dynamic
Buffer will be loaded and modified with some frequency.