12#ifndef GAMP_GLARRAYDATA_HPP_
13#define GAMP_GLARRAYDATA_HPP_
44 class GLArrayData :
public std::enable_shared_from_this<GLArrayData> {
92 constexpr const std::string&
name() const noexcept {
return m_name; }
102 void setName(
const std::string& newName)
noexcept {
146 glBindAttribLocation(program, loc,
m_name.c_str());
279 virtual std::string_view
className() const noexcept {
return "GLArrayData"; }
285 virtual const
void*
data() const noexcept = 0;
336 std::string r(
"GLArrayData");
337 r.append(
"[").append(
m_name)
338 .append(
", location ").append(std::to_string(
m_location))
339 .append(
", isVertexAttribute ").append(std::to_string(
m_isVertexAttr))
342 .append(
", stride ").append(std::to_string(
m_strideB)).append(
"b ").append(std::to_string(
m_strideL)).append(
"c")
343 .append(
", vboEnabled ").append(std::to_string(
m_vboEnabled))
344 .append(
", vboName ").append(std::to_string(
m_vboName))
347 .append(
", vboOffset ").append(std::to_string(
m_vboOffset))
348 .append(
", alive ").append(std::to_string(
m_alive)).append(
"]");
389 template <
typename ChildT>
391 return std::static_pointer_cast<ChildT>(shared_from_this());
401 if( GL_ELEMENT_ARRAY_BUFFER ==
vboTarget ) {
421 if( 0 >= componentsPerElement ) {
427 throw RenderException(
"stride (" + std::to_string(
stride) +
") lower than component bytes, " + std::to_string(componentsPerElement)
455 case GL_DYNAMIC_DRAW:
463 case GL_ARRAY_BUFFER:
464 case GL_ELEMENT_ARRAY_BUFFER:
Interface for a generic data buffer to be used for OpenGL arrays.
constexpr bool sealed() const noexcept
Returns true if data has been sealed (flipped to read), otherwise false (writing mode).
virtual void validate(const GL &gl) const
Validates this instance's parameter.
void setVBOTarget(GLenum vboTarget) noexcept
virtual std::string toString() const noexcept
GLint setLocation(const GL &, GLuint program) noexcept
Retrieves the location of the shader attribute from the linked shader program.
virtual GLsizei elemCount() const noexcept=0
Returns the element position (written elements) if not sealed() or the element limit (available to re...
virtual const void * data() const noexcept=0
The data pointer, may be null if using a memory-mapped GPU buffer.
void glBufferData(const GL &, glmemsize_t size) const noexcept
Sends (creates, updates) the data to the bound vboName buffer, see glBindBuffer().
constexpr uintptr_t vboOffset() const noexcept
The VBO buffer offset if isVBO()
void bindLocation(const GL &, GLuint program, GLint location) noexcept
Binds the location of the shader attribute to the given location for the unlinked shader program.
jau::type_info m_compTypeSignature
constexpr const std::string & name() const noexcept
The name of the reflecting shader array attribute.
void setVBOName(GLuint vboName) noexcept
Set the VBO buffer name, if valid (!= 0) enable use of VBO, otherwise (==0) disable VBO usage.
virtual void associate(ShaderState &, bool)
Implementation and type dependent object association.
virtual std::string elemStatsToString() const noexcept
Returns a string with detailed buffer element stats, i.e.
constexpr GLsizei compsPerElem() const noexcept
The number of components per element.
virtual glmemsize_t byteCapacity() const noexcept=0
Return the capacity in bytes.
constexpr const jau::type_info & compTypeSignature() const noexcept
The component's static compile-time-type-info (CTTI) jau::type_info, e.g.
virtual void setVBOEnabled(bool vboEnabled)
Enable or disable use of VBO.
void glBindBuffer(const GL &, bool on) const noexcept
Binds the vboName() buffer to its vboTarget() on the GPU, i.e.
void glVertexAttribPointer(const GL &) const noexcept
Associates the vboName() buffer as an vertex attribute on the GPU, or sends the data if !...
void setName(const std::string &newName) noexcept
Set a new name for this array.
constexpr GLuint vboName() const noexcept
The VBO name or 0 if not a VBO.
virtual ~GLArrayData() noexcept=default
virtual void destroy(GL &)
constexpr bool isVertexAttribute() const noexcept
Returns true if this data set is intended for a GLSL vertex shader attribute, otherwise false,...
GLsizei m_strideB
stride in bytes; strideB >= compsPerElement * bytesPerComp
constexpr GLenum vboUsage() const noexcept
The VBO usage or 0 if not a VBO.
GLArrayData(Private, const std::string &name, GLsizei componentsPerElement, GLenum componentType, jau::type_info compTypeSignature, bool normalized, GLsizei stride, GLsizei mappedElementCount, bool isVertexAttribute, GLuint vboName, uintptr_t vboOffset, GLenum vboUsage, GLenum vboTarget)
Private ctor for shared_ptr.
std::string toStringImpl() const noexcept
GLsizei stride() const noexcept
constexpr GLsizei bytesPerComp() const noexcept
The component's size in bytes.
constexpr bool normalized() const noexcept
True, if GL shall normalize fixed point data while converting them into float.
GLsizei m_strideL
stride in logical components
constexpr bool isVBO() const noexcept
Determines whether the data is server side (VBO) and enabled, or a client side array (false).
constexpr GLint location() const noexcept
Returns the shader attribute location for this name, -1 if not yet determined.
std::shared_ptr< ChildT > shared_from_base()
constexpr GLenum vboTarget() const noexcept
The VBO target or 0 if not a VBO.
void setVBOUsage(GLenum vboUsage) noexcept
GLsizei m_mappedElemCount
virtual glmemsize_t byteCount() const noexcept=0
Returns the byte position (written elements) if not sealed() or the byte limit (available to read) af...
virtual const jau::type_info & classSignature() const noexcept=0
Returns type signature of implementing class.
void setLocation(GLint loc) noexcept
Sets the given location of the shader attribute.
constexpr GLenum compType() const noexcept
The component's GL data type, e.g.
GLint retrieveLocation(const GL &, GLuint program) noexcept
Retrieves the location of the shader attribute from the linked shader program.
virtual std::string_view className() const noexcept
Returns class name of implementing class.
GLint setLocation(const GL &, GLuint program, GLint loc) noexcept
Binds the location of the shader attribute to the given location for the unlinked shader program.
const GLArrayDataRef shared()
GLsizei m_compsPerElement
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
Generic type information using either Runtime type information (RTTI) or Compile time type informatio...
std::ostream & operator<<(std::ostream &os, const T v)
static constexpr GLsizei sizeOfGLType(GLenum glType)
GLsizeiptr glmemsize_t
Compatible with ssize_t.
std::shared_ptr< GLArrayData > GLArrayDataRef
static constexpr bool isGLTypeFixedPoint(GLenum glType)
std::string to_hexstring(value_type const &v, const bool skipLeading0x=false) noexcept
Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given pointer.