Gamp v0.0.8
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
GLSLSubArrayHandler.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright Gothel Software e.K.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11
12#ifndef GAMP_GLSLARRAYHANDLERFLAT_HPP_
13#define GAMP_GLSLARRAYHANDLERFLAT_HPP_
14
18
19namespace gamp::render::gl::data::impl {
20 using namespace gamp::render::gl;
21 using namespace gamp::render::gl::data;
22
23 /** \addtogroup Gamp_GLImpl
24 *
25 * @{
26 */
27
28 /**
29 * Used for interleaved GLSL arrays, i.e. where the buffer data itself is handled
30 * separately and interleaves many arrays.
31 */
32 class GLSLSubArrayHandler : public GLSubArrayHandler {
33 private:
34 GLArrayDataSRef m_ad;
35
36 public:
37 GLSLSubArrayHandler(GLArrayDataSRef & ad)
38 : m_ad(ad) { }
39
40 void syncData(const GL& gl, ShaderState* st) override {
41 if( st ) {
42 st->vertexAttribPointer(gl, m_ad);
43 } else {
44 if( 0 <= m_ad->location() ) {
45 m_ad->glVertexAttribPointer(gl);
46 }
47 }
48 /**
49 * Due to probable application VBO switching, this might not make any sense ..
50 *
51 if(!written) {
52 st.vertexAttribPointer(glsl, ad);
53 } else if(st.getAttribLocation(glsl, ad) >= 0) {
54 final int[] qi = new int[1];
55 glsl.glGetVertexAttribiv(ad.getLocation(), GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0);
56 if(ad.getVBOName() != qi[0]) {
57 System.err.println("XXX1: "+ad.getName()+", vbo ad "+ad.getVBOName()+", gl "+qi[0]+", "+ad);
58 st.vertexAttribPointer(glsl, ad);
59 } else {
60 System.err.println("XXX0: "+ad.getName()+", vbo ad "+ad.getVBOName()+", gl "+qi[0]+", "+ad);
61 }
62 }*/
63 }
64
65 void enableState(const GL& gl, bool enable, ShaderState* st) override {
66 if( st ) {
67 if( enable ) {
68 st->enableAttribute(gl, m_ad);
69 } else {
70 st->disableAttribute(gl, m_ad);
71 }
72 } else {
73 GLint location = m_ad->location();
74 if( 0 <= location ) {
75 if( enable ) {
76 ::glEnableVertexAttribArray(location);
77 } else {
78 ::glDisableVertexAttribArray(location);
79 }
80 }
81 }
82 }
83
84 const GLArrayDataSRef& data() override { return m_ad; }
85 };
86 /**@}*/
87} // namespace gamp::render::gl::data::impl
88
89#endif /* GAMP_GLSLARRAYHANDLERFLAT_HPP_ */
90
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.
std::shared_ptr< GLArrayData > GLArrayDataSRef