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_ref r = std::make_shared<GLArrayDataClient>(Private(),
78 name, compsPerElement,
100 client_ref r = std::make_shared<GLArrayDataClient>(Private(),
101 name, compsPerElement,
109 std::string_view
className() const noexcept
override {
return "GLArrayDataClient"; }
315 template<
typename T, std::enable_if_t<std::is_
integral_v<T> || std::is_
floating_po
int_v<T>,
bool> = true>
320 return static_cast<T
>(
m_buffer.get() );
323 template<
typename... Targs,
356 return putN(x, y, z);
359 return putN(x, y, z, w);
372 std::string
toString(
bool withData)
const noexcept override {
373 std::string r(
"GLArrayDataWrapper[");
377 .append(
", usesShaderState ").append(std::to_string(
nullptr!=
m_shaderState))
410 const GLsizei required_elems =
compsToElemCount(has_comps + spareComponents);
412 return reserve( std::max(grown_elems, required_elems) );
435 if( nsize <= osize ) {
440 jau::PLAIN_PRINT(
true,
"*** Size: Reserve: comps: %zd, %zd / %zd -> %zd / %zd; %s",
494 name, componentsPerElement,
512 name, componentsPerElement,
515 m_buffer(nullptr, initialElementCount),
526 const std::string&
name, GLsizei componentsPerElement,
531 name, componentsPerElement,
544 if( !m_isValidated ) {
545 m_isValidated =
true;
560 bool m_isValidated =
false;
561 static constexpr bool DEBUG_MODE =
false;
569 template<
typename Value_type>
577 m_ad->glBindBuffer(
gl,
true);
578 if( !
m_ad->isVBOWritten() ) {
579 if(
m_ad->usesClientMem() ) {
582 m_ad->setVBOWritten(
true);
585 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
GLArrayDataClient(Private, const std::string &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.
const GLArrayDataClientRef< value_type > shared()
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)
static client_ref createGLSL(const std::string &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 float growthFactor() const noexcept
Returns this buffer's growth factor.
impl::GLArrayHandlerPtr< value_type > m_glArrayHandler
constexpr_cxx20 client_t & putf(const float v)
GLArrayDataClient(Private, const std::string &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
void rewind()
Rewinds this buffer.
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.
std::shared_ptr< client_t > client_ref
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, const std::string &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/ 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
constexpr_cxx20 client_t & putu32(const uint32_t v)
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::string toString(bool withData) const noexcept override
void checkSeal(bool test)
static client_ref createGLSL(const std::string &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...
std::string elemStatsToString() const noexcept override
GLArrayDataProxy(Private, const std::string &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.
std::unique_ptr< buffer_t > buffer_ref
constexpr bool usesClientMem() const noexcept
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
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...
GLArrayDataClientRef< Value_type > m_ad
Used for 1:1 GLSL arrays, i.e.
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...
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 > > GLArrayDataClientRef
GLArrayDataClientRef< float > GLFloatArrayDataClientRef
GLArrayDataClient< float > GLFloatArrayDataClient
std::unique_ptr< GLArrayHandler< Value_type > > GLArrayHandlerPtr
constexpr GLenum glType() noexcept
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.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
void PLAIN_PRINT(const bool printPrefix, const char *format,...) noexcept
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.