12#ifndef GAMP_GLSLARRAYHANDLER_HPP_
13#define GAMP_GLSLARRAYHANDLER_HPP_
21namespace gamp::render::gl::data::impl {
22 using namespace gamp::render::gl;
23 using namespace gamp::render::gl::data;
34 template <
typename Value_type>
35 class GLSLArrayHandler :
public GLArrayHandler<Value_type> {
40 GLSLArrayHandler() noexcept = default;
42 void setSubArrayVBOName(GLuint)
override {
43 throw jau::UnsupportedOperationException(
"@GLSLArrayHandler",
E_FILE_LINE);
46 void addSubHandler(GLSLSubArrayHandler&&)
override {
47 throw jau::UnsupportedOperationException(
"@GLSLArrayHandler",
E_FILE_LINE);
50 void enableState(
GL& gl,
bool enable, ShaderState* st)
override {
52 enableShaderState(gl, enable, *st);
54 enableSimple(gl, enable);
58 void enableShaderState(
GL& gl,
bool enable, ShaderState& st) {
60 throw jau::IllegalStateError(
"GLArrayDataClient not set",
E_FILE_LINE);
79 if( !m_ad->isVBOWritten() ) {
80 m_ad->glBindBuffer(gl,
true);
81 if( m_ad->usesClientMem() ) {
82 m_ad->glBufferData(gl);
84 m_ad->setVBOWritten(
true);
86 m_ad->glBindBuffer(gl,
false);
91 ::glGetVertexAttribiv(m_ad->location(), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING,
reinterpret_cast<GLint*
>(&tempI));
92 if( m_ad->vboName() != tempI ) {
93 m_ad->glBindBuffer(gl,
true);
95 m_ad->glBindBuffer(gl,
false);
98 }
else if( m_ad->usesClientMem() ) {
108 void enableSimple(
const GL& gl,
bool enable) {
109 GLint location = m_ad->location();
128 if( m_ad->isVBO() ) {
130 if( !m_ad->isVBOWritten() ) {
131 m_ad->glBindBuffer(gl,
true);
132 if( m_ad->usesClientMem() ) {
133 ::glBufferData(m_ad->vboTarget(), m_ad->byteCount(), m_ad->data(), m_ad->vboUsage());
135 m_ad->setVBOWritten(
true);
136 m_ad->glVertexAttribPointer(gl);
137 m_ad->glBindBuffer(gl,
false);
142 glGetVertexAttribiv(location, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING,
reinterpret_cast<GLint*
>(&tempI));
143 if( m_ad->vboName() != tempI ) {
144 m_ad->glBindBuffer(gl,
true);
145 m_ad->glVertexAttribPointer(gl);
146 m_ad->glBindBuffer(gl,
false);
149 }
else if( m_ad->usesClientMem() ) {
150 m_ad->glVertexAttribPointer(gl);
152 ::glEnableVertexAttribArray(location);
154 ::glDisableVertexAttribArray(location);
bool vertexAttribPointer(const GL &gl, const GLArrayDataSRef &data)
Set the GLArrayData vertex attribute data, if it's location is valid, i.e.
bool enableAttribute(const GL &gl, const stringview_t name)
Enables a vertex attribute array.
bool disableAttribute(const GL &gl, const string_t &name)
Disables a vertex attribute array.
GLint resolveLocation(const GL &gl, stringview_t name)
Validates the location of a shader attribute.