3#include "ResourceBase.h"
6#include "Foundation/Memory/MemoryBuffer.h"
7#include "Foundation/Reflection/Name.h"
10#include <glm/vec4.hpp>
12#include <OsoMemoryProfiler/CogsMemoryProfile.h>
56 void set(
size_t offset,
size_t size,
const uint8_t * data);
59 void invalidate(
size_t offset,
size_t size);
62 size_t size()
const {
return bytes.size(); }
65 bool empty()
const {
return size() == 0; }
68 void resize(
size_t size);
74 void *
data() {
return bytes.data(); }
77 const void *
data()
const {
return bytes.data(); }
80 void * map(uint32_t flags);
98 bool isVertexBuffer()
const {
return bindFlags & BufferBindFlags::VertexBuffer; }
101 bool isIndexBuffer()
const {
return bindFlags & BufferBindFlags::IndexBuffer; }
106 uint16_t bufferFlags = BufferFlags::None;
107 uint16_t bindFlags = BufferBindFlags::None;
139 const T *
data()
const {
return reinterpret_cast<const T *
>(
resolve()->
data()); }
159 assert(index *
sizeof(T) <
resolve()->
size() &&
"Index out of range.");
160 return *(
data() + index);
166 assert(index *
sizeof(T) <
resolve()->
size() &&
"Index out of range.");
167 return *(
data() + index);
173 using ResourceBufferHandle::operator->;
178#if __cplusplus < 199711L
194#if defined( __linux__ )
Base allocator implementation.
Provides a weakly referenced view over the contents of a string.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
void setChanged(Cogs::Core::Context *context, Cogs::ComponentModel::Component *component, Reflection::FieldId fieldId)
Must be Called after changing a Component field. Mark field changed. Request engine update.
EBufferBindFlags
Buffer bind flags enumeration.
@ None
Buffer may not be bound as GPU resource.
@ VertexBuffer
Buffer can be bound as vertex buffer.
@ IndexBuffer
Buffer can be bound as index buffer.
EBufferFlags
Buffer state flags enumeration.
@ Mapped
Buffer data is mapped by client code.
@ Dirty
Buffer contents are dirty.
void unmap()
Unmap the buffer, signaling writes to mapped buffer memory are done.
bool empty() const
If the buffer is empty. Note that an empty buffer may still have reserved storage.
const void * data() const
Get a pointer to the buffer data.
void * map(uint32_t flags)
Map the buffer data backing storage, returning a writable pointer.
void setBindFlags(uint16_t flags)
Set the bind flags for the buffer determining how the buffer data may be uploaded to GPU.
void resize(size_t size)
Resize the buffer to accomodate the given number of bytes.
bool isVertexBuffer() const
Gets if the buffer data is usable as a vertex data.
size_t size() const
Size of the buffer in bytes.
uint16_t getBufferFlags() const
Get the buffer flags.
void clear()
Clear the buffer contents. Note that the buffer may retain reserved storage after clearing.
void * data()
Get a pointer to the buffer data.
bool isIndexBuffer() const
Gets if the buffer data is usable as index buffer data.
BufferResource()
Construct an empty buffer resource.
uint16_t getBindFlags() const
Get the bind flags.
BufferView provides a typed, reference-counted, span of an underlying buffer resource.
BufferView(const ResourceBufferHandle &other)
Construct a buffer view from the given untyped handle.
uint8_t getGeneration() const
Get the generation counter.
T * end()
Get an iterator pointing to one past the final element of type T in the buffer.
BufferView()=default
Default constructor. A default view has no underlying resource.
void unmap()
Unmap the buffer storage.
T & operator[](size_t index)
Access the element of type T at index.
BufferView(BufferResource *b)
Construct a buffer view to the given buffer resource b.
void resize(size_t size)
Resize the buffer to accomodate size number of elements of type T.
T * map()
Map the buffer contents, providing write access until unmapped.
bool empty() const
Gets if the buffer is empty.
T * begin()
Get an iterator to the first element of type T in the buffer.
T * data()
Get a pointer to the underlying data. Returns nullptr if no storage is allocated.
size_t size() const
Gets the size of the buffer in number of elements of type T.
const T & operator[](size_t index) const
Access the element of type T at index.
Base class for engine resources.
ResourceHandle_t & operator=(const ResourceHandle_t &other)
Copy assign the handle from the given other handle.
BufferResource * resolve() const
Resolve the handle, returning a pointer to the actual resource.