7#include <QOpenGLFunctions>
30 , m_buffer(other.m_buffer)
31 , m_context(other.m_context)
45 throw GraphicsException(
_t(
"OpenGL Buffer Error"),
_td(
"opengl_buffer_memory_cannot_map",
"Memory [label] Could not be mapped.").replace(
"label",
m_label));
60 m_context->glDeleteBuffers(1, &m_buffer);
73 m_temp_buffer.
setSize(old_size);
83 m_buffer = createBuffer(alloc_size, alloc_size,
type().total_size, GL_STATIC_DRAW, m_temp_buffer.
begin());
84 m_temp_buffer.
clear();
93 switch (
type().byte_size)
96 if (
type().is_unsigned)
return GL_UNSIGNED_BYTE;
99 if (
type().is_float)
return GL_SHORT;
100 if (
type().is_unsigned)
return GL_UNSIGNED_SHORT;
101 else return GL_SHORT;
103 if (
type().is_float)
return GL_FLOAT;
104 if (
type().is_unsigned)
return GL_UNSIGNED_INT;
108 if (
type().is_float)
return GL_DOUBLE;
112 if (
type().is_float)
return GL_FLOAT;
118 else if (
type().is_color)
120 return GL_UNSIGNED_INT;
122 lib_assert(
false,
"unknown vulkanbuffer format");
129 switch (
type().byte_size)
137 lib_assert(
false,
"unknown vulkanbuffer format");
146 if (
type().byte_size == 16)
161 m_temp_buffer.
setSize(buffer_size *
type().total_size);
169 if (reference_data.type() ==
type())
181 if (set_type &&
m_type != reference_data.type())
184 setType(reference_data.type());
186 setSize(reference_data.size());
204 GLint idx = m_context->glGetUniformBlockIndex(shader.
id(), location);
205 m_context->glUniformBlockBinding(shader.
id(), idx, 0);
220 m_context->glEnableVertexAttribArray(attribute);
227 m_context->glVertexAttribPointer(attribute, vector_size, format, GL_FALSE, stride, (
void*)offset);
230 m_context->glVertexAttribIPointer(attribute, vector_size, format, stride, (
void*)offset);
234 m_context->glVertexAttribDivisor(attribute, 1);
241 case Type::INDEX:
return GL_ELEMENT_ARRAY_BUFFER;
break;
244 #ifdef GL_UNIFORM_BUFFER
247 default:
lib_assert(
false,
"unknown type");
break;
249 return GL_ARRAY_BUFFER;
256 GLuint createBuffer(
uint04& allocation_size,
uint04 buffer_size,
uint04 object_size, GLuint usage,
const void* data)
258 lib_assert(buffer_size > 0,
"Bad buffer size");
261 m_context->glGenBuffers(1, &buffer);
262 lib_assert(buffer != 0,
"Bad buffer allocation");
264 allocation_size = buffer_size;
265 m_context->glBufferData(
bindLocation(), buffer_size * object_size, data, usage);
269 DynamicPointer<GLESGraphicsDevice> m_context;
270 Buffer<uint01> m_temp_buffer;
#define UNUSED(expr)
Definition BaseValues.hpp:409
#define lib_assert(expression, message)
Definition LibAssert.h:61
#define _t(english_string)
Definition Translator.h:90
#define _td(def, english_string)
Definition Translator.h:94
void setSize(t_index_type new_size)
Definition Buffer.hpp:803
void ensureCapacity(t_index_type new_capacity, bool ensure_not_greater=false, bool ensure_not_less=true)
Definition Buffer.hpp:519
decltype(auto) begin()
Definition Buffer.hpp:402
void clear()
Definition Buffer.hpp:422
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
A Shader for rendering default OpenGL logic to the graphics card.
Definition GLESShader.h:16
A Special abstract TableColumn responsible for interfacing a Buffer of data with the video card....
Definition GraphicsBuffer.h:45
@ VERTEX
Definition GraphicsBuffer.h:49
@ INDEX
Definition GraphicsBuffer.h:51
@ UNIFORM
Definition GraphicsBuffer.h:50
@ INSTANCE
Definition GraphicsBuffer.h:52
void setType(const TypeInfo &type)
GraphicsBuffer(const String &label)
uint04 m_size
Definition GraphicsBuffer.h:509
uint04 size() const final override
Definition GraphicsBuffer.h:382
bool m_is_memory_owner
Definition GraphicsBuffer.h:514
Type m_internal_type
Definition GraphicsBuffer.h:511
uint04 m_allocated_size
Definition GraphicsBuffer.h:510
bool m_is_accessable
Definition GraphicsBuffer.h:512
A common exeption thrown when an issue occurs within the NDEVR Graphics Engine.
Definition GraphicsException.h:44
Buffer for storing data in the OpenGL engine, usually for rendering.
Definition GLBuffer.h:14
void release()
Definition GLBuffer.h:251
uint04 typeStride() const
Definition GLBuffer.h:125
void sendToVideoCard(bool) final override
Definition GLBuffer.h:78
OpenGLBuffer(const String &label, const DynamicPointer< GLESGraphicsDevice > &device)
Definition GLBuffer.h:16
GLuint bufferID() const
Definition GLBuffer.h:190
void setSize(uint04 buffer_size) final override
Definition GLBuffer.h:158
OpenGLBuffer(const TableColumn &reference_data, const DynamicPointer< GLESGraphicsDevice > &device)
Definition GLBuffer.h:22
void bind()
Definition GLBuffer.h:195
void getFromVideoCard(bool) final override
Definition GLBuffer.h:66
void setRawAttribute(GLint attribute, uint04 vector_size, GLuint format, GLsizei stride, size_t offset)
Definition GLBuffer.h:216
~OpenGLBuffer()
Definition GLBuffer.h:35
OpenGLBuffer(OpenGLBuffer &&other) noexcept
Definition GLBuffer.h:28
void updateRegion(const TableColumn &reference_data, uint04 offset, uint04 size) final override
Definition GLBuffer.h:165
GLuint getFormat(uint01) const
Definition GLBuffer.h:89
void * mapMemory(size_t offset, size_t size) const final override
Definition GLBuffer.h:40
void setAttribute(GLint attribute, uint04 offset=0, uint04 stride=Constant< uint04 >::Invalid)
Definition GLBuffer.h:208
GLuint bindLocation() const
Definition GLBuffer.h:237
void copyData(const TableColumn &reference_data, bool set_type) final override
Definition GLBuffer.h:178
void cleanup() final override
Definition GLBuffer.h:56
void insertRows(uint04, uint04) final override
Definition GLBuffer.h:154
void setUniformAttribute(const GLESShader &shader, const char *location)
Definition GLBuffer.h:200
void unmapMemory() const final override
Definition GLBuffer.h:50
GLuint getFormat() const
Definition GLBuffer.h:150
GLint vectorSize() const
Definition GLBuffer.h:142
The core String class for the NDEVR API.
Definition String.h:69
A virtual storage type that is used with Table class to store data where the actual mechanism for sto...
Definition TableColumn.h:76
String m_label
Definition TableColumn.h:616
TypeInfo m_type
Definition TableColumn.h:617
Time m_modified_time
Definition TableColumn.h:615
const String & label() const
virtual TypeInfo type() const
Definition TableColumn.h:86
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
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 > ...
Definition BaseFunctions.hpp:94
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
static const t_type Invalid
Definition BaseValues.hpp:234