AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Vbo.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/Common/AVector.h>
   15#include <AUI/GL/gl.h>
   16#include <glm/glm.hpp>
   17#include "ResourcePool.h"
   18
   19namespace gl {
   20    namespace detail {
   21        template<gl::ResourceKind T>
   22        class API_AUI_VIEWS VboImpl {
   23        protected:
   24            GLuint mHandle;
   25
   26        public:
   27            VboImpl();
   28            VboImpl(const VboImpl&) = delete;
   29
   30            VboImpl(VboImpl&& v): mHandle(v.mHandle) {
   31                v.mHandle = 0;
   32            }
   33
   34            ~VboImpl();
   35
   36        };
   37    }
   38
   39    class API_AUI_VIEWS VertexBuffer: public detail::VboImpl<gl::ResourceKind::VERTEX_BUFFER> {
   40    private:
   41        void insert(const char* data, size_t length);
   42
   43    public:
   44        void bind();
   45
   46
   47        template<typename T>
   48        void set(const T* data, size_t count) {
   49            static_assert(std::is_standard_layout_v<T>, "you may use only standard layout types in gl::VertexBuffer::set");
   50            insert(reinterpret_cast<const char*>(data), count * sizeof(T));
   51        }
   52
   53        template<typename T>
   54        void set(const AVector<T>& data) {
   55            set(data.data(), data.size());
   56        }
   57    };
   58
   59    class API_AUI_VIEWS IndexBuffer: public detail::VboImpl<gl::ResourceKind::INDEX_BUFFER> {
   60    private:
   61        size_t mIndicesCount;
   62    public:
   63        void bind();
   64        void set(const GLuint* indices, GLsizei length);
   65
   66        void set(const AVector<GLuint>& indices) {
   67            set(indices.data(), static_cast<GLsizei>(indices.size() * sizeof(GLuint)));
   68        }
   69
   70        void draw(GLenum primitiveType) {
   71            bind();
   72            drawWithoutBind(primitiveType);
   73        }
   74        void drawWithoutBind(GLenum primitiveType) {
   75            glDrawElements(primitiveType, GLsizei(mIndicesCount), GL_UNSIGNED_INT, nullptr);
   76        }
   77
   78        [[nodiscard]]
   79        size_t count() const {
   80            return mIndicesCount;
   81        }
   82    };
   83}
A std::vector with AUI extensions.
Definition AVector.h:39
Definition Vbo.h:59
Definition Vbo.h:39