Cogs.Core
BuffersCommon.cpp
1#include "Foundation/Logging/Logger.h"
2#include "BuffersCommon.h"
3#include "ContextCommon.h"
4
5namespace {
6 using namespace Cogs;
7
8 Logging::Log logger = Logging::getLogger("BuffersCommon");
9
10 BuffersCommon::BufferType getType(BindFlags::EBindFlags bindFlags)
11 {
12 if (bindFlags & BindFlags::VertexBuffer) {
13 return BuffersCommon::BufferType::Vertex;
14 }
15 else if (bindFlags & BindFlags::IndexBuffer) {
16 return BuffersCommon::BufferType::Index;
17 }
18 else if (bindFlags & BindFlags::ConstantBuffer) {
19 return BuffersCommon::BufferType::Constant;
20 }
21 else {
22 return BuffersCommon::BufferType::Unclassified;
23 }
24 }
25
26}
27
28Cogs::VertexFormatHandle Cogs::BuffersCommon::createVertexFormat(const VertexElement * elements, size_t count)
29{
30 return VertexFormats::createVertexFormat(elements, count);
31}
32
33const Cogs::VertexFormat *Cogs::BuffersCommon::getVertexFormat(VertexFormatHandle handle)
34{
35 return VertexFormats::getVertexFormat(handle);
36}
37
39 const VertexBufferHandle*, const size_t,
40 const VertexFormat* const*, const uint32_t*, const uint32_t*,
41 const IndexBufferHandle, uint32_t)
42{
43 LOG_ERROR_ONCE(logger, "loadVertexArrayObject: Rendering context does not support vertex array objects.");
45}
46
48{
49 LOG_ERROR_ONCE(logger, "releaseVertexArrayObject: Rendering context does not support vertex array objects.");
50}
51
53{
54 assert(HandleIsValid(handle) && "recordBufferCreate requires a valid buffer handle.");
55 auto& t = bufferStats[static_cast<size_t>(getType(bindFlags))];
56 t.count.fetch_add(1);
57 t.bytes.fetch_add(bytes);
58}
59
61{
62 assert(HandleIsValid(handle) && "recordBufferRelease requires a valid buffer handle.");
63 auto& t = bufferStats[static_cast<size_t>(getType(bindFlags))];
64 t.count.fetch_sub(1);
65 t.bytes.fetch_sub(bytes);
66}
67
69{
70 stats.vertexBufferBytes = bufferStats[static_cast<size_t>(BufferType::Vertex)].bytes.load();
71 stats.indexBufferBytes = bufferStats[static_cast<size_t>(BufferType::Index)].bytes.load();
72 stats.constantBufferBytes = bufferStats[static_cast<size_t>(BufferType::Constant)].bytes.load();
73 stats.unclassifiedBufferBytes = bufferStats[static_cast<size_t>(BufferType::Unclassified)].bytes.load();
74 stats.vertexBufferCount = bufferStats[static_cast<size_t>(BufferType::Vertex)].count.load();
75 stats.indexBufferCount = bufferStats[static_cast<size_t>(BufferType::Index)].count.load();
76 stats.constantBufferCount = bufferStats[static_cast<size_t>(BufferType::Constant)].count.load();
77 stats.unclassifiedBufferCount = bufferStats[static_cast<size_t>(BufferType::Unclassified)].count.load();
78}
Log implementation class.
Definition: LogManager.h:140
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:181
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
EBindFlags
Bind flags enumeration.
Definition: Flags.h:64
@ ConstantBuffer
The buffer can be bound as input to effects as a constant buffer.
Definition: Flags.h:72
@ VertexBuffer
The buffer can be bound as input to the vertex shader stage as a vertex buffer.
Definition: Flags.h:68
@ IndexBuffer
The buffer can be bound as input to the vertex shader stage as an index buffer.
Definition: Flags.h:70
virtual VertexArrayObjectHandle loadVertexArrayObject(const EffectHandle effectHandle, const VertexBufferHandle *vertexBufferHandles, const size_t vertexBufferCount, const VertexFormat *const *vertexFormats=nullptr, const uint32_t *vertexBufferStrides=nullptr, const uint32_t *vertexBufferOffsets=nullptr, const IndexBufferHandle indexBufferHandle=IndexBufferHandle::NoHandle, uint32_t indexBufferStride=0) override
void recordBufferRelease(BufferHandle handle, BindFlags::EBindFlags bindFlags, size_t bytes)
void recordBufferCreate(BufferHandle handle, BindFlags::EBindFlags bindFlags, size_t bytes)
void updateResourceStatistics(ResourceStatistics &stats) const
virtual void releaseVertexArrayObject(VertexArrayObjectHandle) override
static const Handle_t InvalidHandle
Represents an invalid handle.
Definition: Common.h:81
Vertex element structure used to describe a single data element in a vertex for the input assembler.
Definition: VertexFormat.h:38
Vertex format structure used to describe a single vertex for the input assembler.
Definition: VertexFormat.h:60