2#include "../Headers/GLESGraphicsDevice.h"
3#include <NDEVR/GraphicsBuffer.h>
4#include <NDEVR/GraphicsException.h>
5#include <NDEVR/Translator.h>
6#include <QOpenGLFunctions>
39 , m_buffer(other.m_buffer)
40 , m_context(other.m_context)
42 other.m_buffer = Constant<uint04>::Invalid;
58 lib_assert(
size > 0,
"Bad size map");
61 throw GraphicsException(_t(
"OpenGL Buffer Error"), _td(
"opengl_buffer_memory_cannot_map",
"Memory [label] Could not be mapped.").replace(
"label",
m_label));
63 lib_assert(offset +
size <=
m_size *
type().total_size,
"Bad size update");
78 m_context->glDeleteBuffers(1, &m_buffer);
79 m_buffer = Constant<uint04>::Invalid;
99 createBuffer(GL_STATIC_DRAW, m_temp_buffer.begin());
101 setBuffer(GL_STATIC_DRAW, m_temp_buffer.begin());
102 m_temp_buffer.clear();
104 m_temp_buffer.ensureCapacity(0,
true,
true);
112 if (
type().is_number)
114 switch (
type().byte_size)
117 if (
type().is_unsigned)
return GL_UNSIGNED_BYTE;
120 if (
type().is_float)
return GL_SHORT;
121 if (
type().is_unsigned)
return GL_UNSIGNED_SHORT;
122 else return GL_SHORT;
124 if (
type().is_float)
return GL_FLOAT;
125 if (
type().is_unsigned)
return GL_UNSIGNED_INT;
129 if (
type().is_float)
return GL_DOUBLE;
133 if (
type().is_float)
return GL_FLOAT;
139 else if (
type().is_color)
141 return GL_UNSIGNED_BYTE;
143 lib_assert(
false,
"unknown vulkanbuffer format");
152 switch (
type().byte_size)
160 lib_assert(
false,
"unknown vulkanbuffer format");
169 if (
type().byte_size == 16)
182 lib_assert(
false,
"Not yet implemented");
188 if (
m_size == buffer_size)
191 m_temp_buffer.setSize(buffer_size *
type().total_size);
204 if (reference_data.type() ==
type())
210 lib_assert(
false,
"Not yet implimented");
224 if (set_type &&
m_type != reference_data.type())
227 setType(reference_data.type());
229 setSize(reference_data.size());
237 lib_assert(
IsValid(m_buffer),
"Bad buffer");
265 bind(buffer_start, buffer_size);
290 m_context->glEnableVertexAttribArray(attribute);
297 m_context->glVertexAttribPointer(attribute, vector_size, format, GL_FALSE, stride, (
void*)offset);
309 m_context->glVertexAttribPointer(attribute, vector_size, format, GL_TRUE, stride, (
void*)offset);
311 m_context->glVertexAttribPointer(attribute, vector_size, format, GL_FALSE, stride, (
void*)offset);
313 m_context->glVertexAttribIPointer(attribute, vector_size, format, stride, (
void*)offset);
317 m_context->glVertexAttribDivisor(attribute, 1);
326 case Type::INDEX:
return GL_ELEMENT_ARRAY_BUFFER;
break;
329 #ifdef GL_UNIFORM_BUFFER
332 default: lib_assert(
false,
"unknown type");
break;
334 return GL_ARRAY_BUFFER;
345 void createBuffer(GLuint usage,
const void* data)
347 lib_assert(
size() > 0,
"Bad buffer size");
348 lib_assert(
IsInvalid(m_buffer),
"Bad buffer generation");
350 m_context->glGenBuffers(1, &m_buffer);
351 setBuffer(usage, data);
356 void setBuffer(GLuint usage,
const void* data)
358 lib_assert(m_buffer != 0,
"Bad buffer allocation");
368 lib_assert(m_buffer != 0,
"Bad buffer allocation");
372 GLuint m_buffer = Constant<uint04>::Invalid;
373 DynamicPointer<GLESGraphicsDevice> m_context;
374 Buffer<uint01> m_temp_buffer;
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
uint08 m_size
Current number of elements in the buffer.
GraphicsBuffer(const StringView &label)
Constructs a graphics buffer with the given label.
uint08 m_allocated_size
Allocated capacity in elements.
Type m_internal_type
Video card usage type.
bool m_is_memory_owner
Whether this buffer owns the underlying memory.
virtual TypeInfo type() const override
Returns the type information for this buffer.
bool m_is_accessable
Whether the buffer is CPU-accessible.
uint04 size() const final override
Returns the number of rows in this column.
@ INDEX
Index data for indexed drawing.
@ VERTEX
Vertex attribute data.
@ INSTANCE
Per-instance attribute data.
@ UNIFORM
Uniform (constant) data.
void setType(const TypeInfo &type)
Sets the element type for this buffer.
TypeInfo m_type
Element type information.
A common exeption thrown when an issue occurs within the NDEVR Graphics Engine.
void setAttribute(GLint attribute, uint04 offset=0, uint04 stride=Constant< uint04 >::Invalid)
Sets a vertex attribute pointer for the entire buffer.
void bind()
Binds the entire buffer to its target binding point.
void * mapMemory(size_t offset, size_t size) const final override
Maps a region of the buffer into CPU-accessible memory.
void insertRows(uint04, uint04) final override
Inserts rows into the buffer.
~OpenGLBuffer()
Destructor.
virtual void setDefaultValueFrom(const TableColumn &) override
No-op for OpenGL buffers.
GLint vectorSize() const
Returns the number of components per vertex attribute.
void getFromVideoCard(bool) final override
Prepares the buffer for CPU read-back by allocating a temp buffer.
void setAttributeRange(GLint attribute, uint04 buffer_start, uint04 buffer_size, uint04 offset=0, uint04 stride=Constant< uint04 >::Invalid)
Sets a vertex attribute pointer for a sub-range of the buffer.
GLuint getFormat() const
Returns the OpenGL data type enum for the buffer.
void setRawAttribute(GLint attribute, uint04 vector_size, GLuint format, GLsizei stride, size_t offset)
Sets a raw vertex attribute pointer with explicit format parameters.
void sendToVideoCard(bool) final override
Uploads the temp buffer data to the GPU.
OpenGLBuffer(const TableColumn &reference_data, const DynamicPointer< GLESGraphicsDevice > &device)
Constructs an OpenGLBuffer and copies data from a TableColumn.
GLuint bufferID() const
Returns the OpenGL buffer object ID.
OpenGLBuffer(OpenGLBuffer &&other) noexcept
Move constructor.
uint04 typeStride() const
Returns the byte stride per element component.
void release()
Unbinds this buffer from its target binding point.
void cleanup() final override
Deletes the GPU buffer and resets internal state.
OpenGLBuffer(const StringView &label, const DynamicPointer< GLESGraphicsDevice > &device)
Constructs an empty OpenGLBuffer with the given label.
GLuint bindLocation() const
Returns the OpenGL binding target for this buffer type.
void setSize(uint04 buffer_size) final override
Resizes the buffer to hold the specified number of elements.
void copyData(const TableColumn &reference_data, bool set_type) final override
Copies all data from a TableColumn into this buffer.
GLuint getFormat(uint01) const
Returns the OpenGL data type enum for the buffer's element type.
void bind(uint04 offset, uint04 size)
Binds a sub-range of the buffer to its target binding point.
void unmapMemory(size_t, size_t) const final override
Unmaps previously mapped buffer memory.
void updateRegion(const TableColumn &reference_data, uint04 offset, uint04 size) final override
Updates a sub-region of the buffer from a TableColumn.
The core String View class for the NDEVR API.
A virtual storage type that is used with Table class to store data where the actual mechanism for sto...
virtual uint04 size() const =0
Returns the number of rows in this column.
String m_label
The display name or identifier for this column.
const String & label() const
Returns the label (name) of this column.
Time m_modified_time
The timestamp of the most recent modification to this column.
The primary namespace for the NDEVR SDK.
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.