7#include <QOpenGLFunctions>
27 , m_buffer(other.m_buffer)
28 , m_context(other.m_context)
42 throw GraphicsException(
_t(
"OpenGL Buffer Error"),
_td(
"opengl_buffer_memory_cannot_map",
"Memory [label] Could not be mapped.").replace(
"label",
m_label));
57 m_context->glDeleteBuffers(1, &m_buffer);
70 m_temp_buffer.
setSize(old_size);
80 m_buffer = createBuffer(alloc_size, alloc_size,
type().total_size, GL_STATIC_DRAW, m_temp_buffer.
begin());
81 m_temp_buffer.
clear();
90 switch (
type().byte_size)
93 if (
type().is_unsigned)
return GL_UNSIGNED_BYTE;
96 if (
type().is_float)
return GL_SHORT;
97 if (
type().is_unsigned)
return GL_UNSIGNED_SHORT;
100 if (
type().is_float)
return GL_FLOAT;
101 if (
type().is_unsigned)
return GL_UNSIGNED_INT;
105 if (
type().is_float)
return GL_DOUBLE;
109 if (
type().is_float)
return GL_FLOAT;
115 else if (
type().is_color)
117 return GL_UNSIGNED_INT;
119 lib_assert(
false,
"unknown vulkanbuffer format");
126 switch (
type().byte_size)
134 lib_assert(
false,
"unknown vulkanbuffer format");
143 if (
type().byte_size == 16)
158 m_temp_buffer.
setSize(buffer_size *
type().total_size);
166 if (reference_data.type() ==
type())
178 if (set_type &&
m_type != reference_data.type())
181 setType(reference_data.type());
183 setSize(reference_data.size());
201 GLint idx = m_context->glGetUniformBlockIndex(shader.
id(), location);
202 m_context->glUniformBlockBinding(shader.
id(), idx, 0);
217 m_context->glEnableVertexAttribArray(attribute);
224 m_context->glVertexAttribPointer(attribute, vector_size, format, GL_FALSE, stride, (
void*)offset);
227 m_context->glVertexAttribIPointer(attribute, vector_size, format, stride, (
void*)offset);
231 m_context->glVertexAttribDivisor(attribute, 1);
238 case Type::INDEX:
return GL_ELEMENT_ARRAY_BUFFER;
break;
241 #ifdef GL_UNIFORM_BUFFER
244 default:
lib_assert(
false,
"unknown type");
break;
246 return GL_ARRAY_BUFFER;
253 GLuint createBuffer(
uint04& allocation_size,
uint04 buffer_size,
uint04 object_size, GLuint usage,
const void* data)
255 lib_assert(buffer_size > 0,
"Bad buffer size");
258 m_context->glGenBuffers(1, &buffer);
259 lib_assert(buffer != 0,
"Bad buffer allocation");
261 allocation_size = buffer_size;
262 m_context->glBufferData(
bindLocation(), buffer_size * object_size, data, usage);
266 DynamicPointer<GLESGraphicsDevice> m_context;
267 Buffer<uint01> m_temp_buffer;
#define UNUSED(expr)
Definition BaseValues.hpp:433
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
#define _t(english_string)
Definition Translator.h:87
#define _td(def, english_string)
Definition Translator.h:91
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
void ensureCapacity(t_index_type new_capacity, bool ensure_not_greater=false, bool ensure_not_less=true)
Definition Buffer.hpp:803
decltype(auto) begin()
Definition Buffer.hpp:504
void clear()
Definition Buffer.hpp:572
Definition Pointer.hpp:303
Definition GLESShader.h:13
uint04 id() const
Definition GLESShader.h:167
Definition GraphicsBuffer.h:39
@ VERTEX
Definition GraphicsBuffer.h:43
@ INDEX
Definition GraphicsBuffer.h:45
@ UNIFORM
Definition GraphicsBuffer.h:44
@ INSTANCE
Definition GraphicsBuffer.h:46
NDEVR_GRAPHICS_API void setType(const TypeInfo &type)
Definition GraphicsBuffer.cpp:80
NDEVR_GRAPHICS_API GraphicsBuffer(const String &label)
Definition GraphicsBuffer.cpp:5
uint04 m_size
Definition GraphicsBuffer.h:501
uint04 size() const final override
Definition GraphicsBuffer.h:376
bool m_is_memory_owner
Definition GraphicsBuffer.h:506
Type m_internal_type
Definition GraphicsBuffer.h:503
uint04 m_allocated_size
Definition GraphicsBuffer.h:502
bool m_is_accessable
Definition GraphicsBuffer.h:504
Definition GraphicsException.h:40
void release()
Definition GLBuffer.h:248
uint04 typeStride() const
Definition GLBuffer.h:122
void sendToVideoCard(bool) final override
Definition GLBuffer.h:75
OpenGLBuffer(const String &label, const DynamicPointer< GLESGraphicsDevice > &device)
Definition GLBuffer.h:13
GLuint bufferID() const
Definition GLBuffer.h:187
void setSize(uint04 buffer_size) final override
Definition GLBuffer.h:155
OpenGLBuffer(const TableColumn &reference_data, const DynamicPointer< GLESGraphicsDevice > &device)
Definition GLBuffer.h:19
void bind()
Definition GLBuffer.h:192
void getFromVideoCard(bool) final override
Definition GLBuffer.h:63
void setRawAttribute(GLint attribute, uint04 vector_size, GLuint format, GLsizei stride, size_t offset)
Definition GLBuffer.h:213
~OpenGLBuffer()
Definition GLBuffer.h:32
OpenGLBuffer(OpenGLBuffer &&other) noexcept
Definition GLBuffer.h:25
void updateRegion(const TableColumn &reference_data, uint04 offset, uint04 size) final override
Definition GLBuffer.h:162
GLuint getFormat(uint01) const
Definition GLBuffer.h:86
void setAttribute(GLint attribute, uint04 offset=0, uint04 stride=Constant< uint04 >::NaN)
Definition GLBuffer.h:205
void * mapMemory(size_t offset, size_t size) const final override
Definition GLBuffer.h:37
GLuint bindLocation() const
Definition GLBuffer.h:234
void copyData(const TableColumn &reference_data, bool set_type) final override
Definition GLBuffer.h:175
void cleanup() final override
Definition GLBuffer.h:53
void insertRows(uint04, uint04) final override
Definition GLBuffer.h:151
void setUniformAttribute(const GLESShader &shader, const char *location)
Definition GLBuffer.h:197
void unmapMemory() const final override
Definition GLBuffer.h:47
GLuint getFormat() const
Definition GLBuffer.h:147
GLint vectorSize() const
Definition GLBuffer.h:139
Definition TableColumn.h:68
String m_label
Definition TableColumn.h:608
TypeInfo m_type
Definition TableColumn.h:609
Time m_modified_time
Definition TableColumn.h:607
const String & label() const
Definition TableColumn.cpp:303
virtual TypeInfo type() const
Definition TableColumn.h:78
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator.
Definition BaseFunctions.hpp:116
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
Definition BaseValues.hpp:272
static const t_type NaN
Definition BaseValues.hpp:274