Gamp v0.0.8
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
GLSLArrayHandlerInterleaved.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_GLSLARRAYHANDLERINTERLEAVED_HPP_
13#define GAMP_GLSLARRAYHANDLERINTERLEAVED_HPP_
14
15#include <jau/basic_types.hpp>
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 * Interleaved fixed function arrays, i.e. where this buffer data
30 * represents many arrays.
31 */
32 template<typename Value_type>
33 class GLSLArrayHandlerInterleaved : public GLArrayHandler<Value_type> {
34 private:
35 std::vector<GLSLSubArrayHandler> subArrays;
36 using GLArrayHandler<Value_type>::m_ad;
37
38 void syncSubData(const GL& gl, ShaderState* st) {
39 for(auto & subArray : subArrays) {
40 subArray.syncData(gl, st);
41 }
42 }
43
44 public:
45 typedef GLArrayHandler<Value_type> glarray_t;
46
47 GLSLArrayHandlerInterleaved() noexcept = default;
48
49 void setSubArrayVBOName(GLuint vboName) override {
50 for(auto & subArray : subArrays) {
51 subArray.data()->setVBOName(vboName);
52 }
53 }
54
55 void addSubHandler(GLSLSubArrayHandler&& handler) override {
56 subArrays.push_back(std::move(handler));
57 }
58
59 void enableState(GL& gl, bool enable, ShaderState* st) override {
60 if(enable) {
61 if(!m_ad->isVBO()) {
62 throw jau::InternalError("Interleaved handle is not VBO: "+m_ad->toString(), E_FILE_LINE);
63 }
64 glarray_t::bindBuffer(gl, true);
65 // sub data will decide whether to update the vertex attrib pointer
66 syncSubData(gl, st);
67 glarray_t::bindBuffer(gl, false);
68 }
69 for(auto & subArray : subArrays) {
70 subArray.enableState(gl, enable, st);
71 }
72 }
73 };
74
75 /**@}*/
76}
77
78#endif /* GAMP_GLSLARRAYHANDLERINTERLEAVED_HPP_ */
#define E_FILE_LINE
uint8_t Value_type