12#ifndef GAMP_GLARRAYDATACLIENT_HPP_
13#define GAMP_GLARRAYDATACLIENT_HPP_
29 using namespace gamp::render::gl;
36 template<
typename Value_type>
39 template<
typename Value_type>
50 template<
typename Value_type>
77 client_sref r = std::make_shared<GLArrayDataClient>(Private(),
78 name, compsPerElement,
80 true, std::move(std::make_unique<impl::GLSLArrayHandler<value_type>>()),
100 client_sref r = std::make_shared<GLArrayDataClient>(Private(),
101 name, compsPerElement,
103 true, std::move(std::make_unique<impl::GLSLArrayHandler<value_type>>()),
109 std::string_view
className() const noexcept
override {
return "GLArrayDataClient"; }
316 template<
typename T, std::enable_if_t<std::is_
integral_v<T> || std::is_
floating_po
int_v<T>,
bool> = true>
321 return static_cast<T
>(
m_buffer.get() );
324 template<
typename... Targs,
365 return putN(x, y, z);
368 return putN(x, y, z, w);
381 std::string
toString(
bool withData)
const noexcept override {
382 std::string r(
"GLArrayDataWrapper[");
386 .append(
", usesShaderState ").append(std::to_string(
nullptr!=
m_shaderState))
419 const GLsizei required_elems =
compsToElemCount(has_comps + spareComponents);
421 return reserve( std::max(grown_elems, required_elems) );
444 if( nsize <= osize ) {
449 jau_PLAIN_PRINT(
true,
"*** Size: Reserve: comps: %zd, %zd / %zd -> %zd / %zd; %s",
507 name, componentsPerElement,
529 name, componentsPerElement,
532 m_buffer(nullptr, initialElementCount),
547 std::string_view
name, GLsizei componentsPerElement,
552 name, componentsPerElement,
565 if( !m_isValidated ) {
566 m_isValidated =
true;
581 bool m_isValidated =
false;
582 static constexpr bool DEBUG_MODE =
false;
589namespace gamp::render::gl::data::impl {
590 template<
typename Value_type>
591 bool GLArrayHandler<Value_type>::bindBuffer(
GL&
gl,
bool bind) {
592 if( !m_ad || !m_ad->isVBO() ) {
598 m_ad->glBindBuffer(
gl,
true);
599 if( !m_ad->isVBOWritten() ) {
600 if( m_ad->usesClientMem() ) {
601 m_ad->glBufferData(
gl);
603 m_ad->setVBOWritten(
true);
606 m_ad->glBindBuffer(
gl,
false);
Client data buffer for non VBO GLArrayData usage of given template-type Value_type.
std::string_view className() const noexcept override
Returns class name of implementing class.
GLArrayDataProxy< value_type > proxy_t
constexpr bool enabled() const noexcept
constexpr_cxx20 client_t & put2f(const float x, const float y)
constexpr_cxx20 client_t & put4f(const float x, const float y, const float z, const float w)
constexpr_cxx20 client_t & put2f(const jau::math::Vec2f &v)
constexpr float growthFactor() const noexcept
Returns this buffer's growth factor.
impl::GLArrayHandlerPtr< value_type > m_glArrayHandler
constexpr_cxx20 client_t & putf(const float v)
void rewind()
Rewinds this buffer.
const GLArrayDataClientSRef< value_type > shared()
static client_sref createGLSL(std::string_view name, GLsizei compsPerElement, bool normalized, size_t initialElementCount)
Create a client side buffer object, using a custom GLSL array attribute name and starting with a new ...
constexpr_cxx20 client_t & putN(const Targs &...args)
bool bindBuffer(GL &gl, bool bind)
if bind is true and the data uses VBO, the latter will be bound and data written to the GPU if requir...
void destroy(GL &gl) override
void seal(GL &gl, bool seal_)
Convenience method calling seal(bool) and enableBuffer(GL&, bool).
void enableBuffer(GL &gl, bool enable)
Enables the buffer if enable is true, and transfers the data if required.
void clear()
Clears this buffer and resets states accordingly.
void clear(GL &gl)
Clears this buffer and resets states accordingly.
GLArrayDataClient(Private, std::string_view name, GLsizei componentsPerElement, bool normalized, GLsizei stride, GLsizei initialElementCount, float growthFactor, bool isVertexAttribute, impl::GLArrayHandlerPtr< value_type > &&glArrayHandler, GLuint vboName, uintptr_t vboOffset, GLenum vboUsage, GLenum vboTarget)
Private client-mem ctor w/o passing custom buffer.
constexpr_cxx20 client_t & put(std::initializer_list< value_type > initlist)
void setVBOWritten(bool written) noexcept
Marks the buffer written to the VBO.
void setGrowthFactor(float v) noexcept
Sets a new growth factor for this buffer.
void setEnableAlways(bool always)
Affects the behavior of 'enableBuffer'.
void associate(ShaderState &st, bool enable) override
Implementation and type dependent object association.
constexpr bool isVBOWritten() const noexcept
Is the buffer written to the VBO ?
const jau::type_info & classSignature() const noexcept override
Returns type signature of implementing class.
GLArrayDataClient(Private, std::string_view name, GLsizei componentsPerElement, bool normalized, GLsizei stride, buffer_t &&data, float growthFactor, bool isVertexAttribute, impl::GLArrayHandlerPtr< value_type > &&glArrayHandler, GLuint vboName, uintptr_t vboOffset, GLenum vboUsage, GLenum vboTarget)
Private client-mem ctor w/o passing custom buffer.
GLArrayDataClient< value_type > client_t
ShaderState * m_shaderState
constexpr GLsizei compsToElemCount(GLsizei componentCount) const noexcept
Returning element-count from given componentCount, rounding up to componentsPerElement.
bool growIfNeeded(glmemsize_t spareComponents)
Increase the capacity of the buffer if necessary to add given spareComponents components.
static constexpr float DEFAULT_GROWTH_FACTOR
constexpr_cxx20 client_t & put3f(const jau::math::Vec3f &v)
std::string toString() const noexcept override
constexpr_cxx20 client_t & puti32(const int32_t v)
jau::darray< value_type, glmemsize_t > buffer_t
static client_sref createGLSL(std::string_view name, GLsizei compsPerElement, bool normalized, GLsizei stride, buffer_t &&buffer)
Create a client side buffer object, using a custom GLSL array attribute name and starting with a give...
constexpr_cxx20 client_t & putu32(const uint32_t v)
GLArrayDataClient(Private, std::string_view name, GLsizei componentsPerElement, bool normalized, GLsizei stride, GLsizei mappedElementCount, bool isVertexAttribute, impl::GLArrayHandlerPtr< value_type > &&glArrayHandler, GLuint vboName, uintptr_t vboOffset, GLenum vboUsage, GLenum vboTarget)
using memory mapped elements
constexpr_cxx20 client_t & put3f(const float x, const float y, const float z)
virtual void init_vbo(const GL &gl)
bool reserve(GLsizei elementCount)
Increase the capacity of the buffer to given elementCount element size, i.e.
constexpr_cxx20 client_t & put(const value_type v)
bool m_enableBufferAlways
constexpr_cxx20 client_t & put4f(const jau::math::Vec4f &v)
std::shared_ptr< client_t > client_sref
std::string toString(bool withData) const noexcept override
void checkSeal(bool test)
std::string elemStatsToString() const noexcept override
GLArrayDataProxy(Private, std::string_view name, GLsizei componentsPerElement, bool normalized, GLsizei stride, buffer_t &buffer, bool isVertexAttribute, GLuint vboName, uintptr_t vboOffset, GLenum vboUsage, GLenum vboTarget)
jau::darray< value_type, glmemsize_t > buffer_t
void destroy(GL &gl) override
const void * data() const noexcept override
Returns client-data pointer at current position if usesClientMem(), otherwise nullptr.
constexpr bool usesClientMem() const noexcept
std::unique_ptr< buffer_t > buffer_sref
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.
constexpr uintptr_t vboOffset() const noexcept
The VBO buffer offset if isVBO()
constexpr GLsizei compsPerElem() const noexcept
The number of components per element.
constexpr GLuint vboName() const noexcept
The VBO name or 0 if not a VBO.
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.
GLsizei stride() const noexcept
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
std::shared_ptr< ChildT > shared_from_base()
constexpr GLenum vboTarget() const noexcept
The VBO target or 0 if not a VBO.
GLsizei m_mappedElemCount
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...
#define jau_PLAIN_PRINT(printPrefix, fmt,...)
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
consteval_cxx20 std::string_view name() noexcept
std::tuple_element_t< 0, std::tuple< Ts... > > first_type
#define constexpr_cxx20
constexpr qualifier replacement for C++20 constexpr.
constexpr bool is_all_same_v
const jau::type_info & static_ctti() noexcept
Returns a static global reference of make_ctti<T>(true) w/ identity instance.
GLsizeiptr glmemsize_t
Compatible with ssize_t.
std::shared_ptr< GLArrayDataClient< Value_type > > GLArrayDataClientSRef
GLArrayDataClientSRef< float > GLFloatArrayDataClientSRef
GLArrayDataClient< float > GLFloatArrayDataClient
constexpr GLenum glType() noexcept
std::string toHexString(const void *data, const nsize_t length, const lb_endian_t byteOrder=lb_endian_t::big, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix) noexcept
Produce a hexadecimal string representation of the given lsb-first byte values.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.