AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
Vao.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include "AUI/GL/gl.h"
15#include <glm/glm.hpp>
16#include "AUI/Common/AVector.h"
17#include "AUI/Util/AArrayView.h"
18#include "AUI/Views.h"
19
20namespace gl {
21 class API_AUI_VIEWS Vao {
22 public:
23 struct Buffer {
24 GLuint handle = 0;
25 uint32_t signature = 0; // signature used for optimization
26
35 const char* lastModifierKey = nullptr;
36 };
37
38 Vao();
39 ~Vao();
40 Vao(const Vao&) = delete;
41
42
43 [[nodiscard]]
44 const AVector<Buffer>& getBuffers() const noexcept {
45 return mBuffers;
46 }
47
48 void bind() const noexcept;
49 static void unbind() noexcept;
50
57 template<typename T>
58 void insert(GLuint index, AArrayView<T> data, const char* key) {
59 if constexpr (std::is_same_v<T, GLuint>) {
60 insertInteger(index, (const char*)data.data(), data.sizeInBytes(), 1, GL_UNSIGNED_INT);
61 } else {
62 insert(index, (const char*)data.data(), data.sizeInBytes(), sizeof(T) / sizeof(float), GL_FLOAT, key);
63 }
64 }
65
72 template<typename T>
73 void insertIfKeyMismatches(GLuint index, AArrayView<T> data, const char* key) {
74 insertIfKeyMismatches(index, (const char*)data.data(), data.sizeInBytes(), sizeof(T) / sizeof(float), GL_FLOAT, key);
75 }
76
81 void indices(AArrayView<GLuint> data);
82
83 void drawArrays(GLenum type, GLsizei count);
84
89 void drawElements(GLenum type = GL_TRIANGLES);
90
91 private:
92 GLuint mHandle;
93 AVector<Buffer> mBuffers;
94 GLuint mIndicesBuffer = 0;
95 GLsizei mIndicesCount = 0;
96
97
106 void insert(GLuint index, const char* data, GLsizeiptr dataSize, GLuint vertexSize, GLenum dataType, const char* key);
107
116 void insertIfKeyMismatches(GLuint index, const char* data, GLsizeiptr dataSize, GLuint vertexSize, GLenum dataType, const char* key);
117
118
126 void insertInteger(GLuint index, const char* data, GLsizeiptr dataSize, GLuint vertexSize, GLenum dataType);
127 };
128}
Definition: AArrayView.h:25
A std::vector with AUI extensions.
Definition: AVector.h:38
Definition: Vao.h:21
void insertIfKeyMismatches(GLuint index, AArrayView< T > data, const char *key)
Creates VBO or modifies existing one, if the key pointer mismatches.
Definition: Vao.h:73
Definition: Type.h:16
Definition: Vao.h:23