AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Vao.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 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 {
   21class API_AUI_VIEWS Vao {
   22public:
   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    [[nodiscard]]
   43    const AVector<Buffer>& getBuffers() const noexcept {
   44        return mBuffers;
   45    }
   46
   47    void bind() const noexcept;
   48    static void unbind() noexcept;
   49
   56    template <typename T>
   57    void insert(GLuint index, AArrayView<T> data, const char* key) {
   58        if constexpr (std::is_same_v<T, GLuint>) {
   59            insertInteger(index, (const char*) data.data(), data.sizeInBytes(), 1, GL_UNSIGNED_INT);
   60        } else {
   61            insert(index, (const char*) data.data(), data.sizeInBytes(), sizeof(T) / sizeof(float), GL_FLOAT, key);
   62        }
   63    }
   64
   71    template <typename T>
   72    void insertIfKeyMismatches(GLuint index, AArrayView<T> data, const char* key) {
   73        insertIfKeyMismatches(
   74            index, (const char*) data.data(), data.sizeInBytes(), sizeof(T) / sizeof(float), GL_FLOAT, key);
   75    }
   76
   82
   88
   89    void drawArrays(GLenum type, GLsizei count);
   90
   95    void drawElements(GLenum type = GL_TRIANGLES);
   96
   97private:
   98    GLuint mHandle;
   99    AVector<Buffer> mBuffers;
  100    GLuint mIndicesBuffer = 0;
  101    GLsizei mIndicesCount = 0;
  102    GLuint mIndicesType = 0;
  103
  113    void
  114    insert(GLuint index, const char* data, GLsizeiptr dataSize, GLuint vertexSize, GLenum dataType, const char* key);
  115
  125    void insertIfKeyMismatches(
  126        GLuint index, const char* data, GLsizeiptr dataSize, GLuint vertexSize, GLenum dataType, const char* key);
  127
  136    void insertInteger(GLuint index, const char* data, GLsizeiptr dataSize, GLuint vertexSize, GLenum dataType);
  137};
  138}   // namespace gl
Definition AArrayView.h:32
A std::vector with AUI extensions.
Definition AVector.h:39
void insertIfKeyMismatches(GLuint index, AArrayView< T > data, const char *key)
Creates VBO or modifies existing one, if the key pointer mismatches.
Definition Vao.h:72
void indices(AArrayView< uint16_t > data)
Uploads VBO indices.
void insert(GLuint index, AArrayView< T > data, const char *key)
Creates VBO or modifies existing one.
Definition Vao.h:57
void indices(AArrayView< uint32_t > data)
Uploads VBO indices.
void drawElements(GLenum type=GL_TRIANGLES)
Draws buffer. Don't forget to upload indices with indices function/.
Definition Vao.h:23
const char * lastModifierKey
String key of the last object who has modified the buffer.
Definition Vao.h:35