AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Renderbuffer.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 <AUI/GL/GLEnums.h>
   16#include <glm/glm.hpp>
   17
   18namespace gl {
   19    template<Multisampling multisampling = Multisampling::DISABLED>
   20    class Renderbuffer {
   21    public:
   22        Renderbuffer() {
   23            glGenRenderbuffers(1, &mHandle);
   24        }
   25        Renderbuffer(const Renderbuffer&) = delete;
   26        ~Renderbuffer() {
   27            glDeleteRenderbuffers(1, &mHandle);
   28        }
   29
   30        [[nodiscard]]
   31        GLuint handle() const noexcept {
   32            return mHandle;
   33        }
   34
   35        void bind() {
   36            glBindRenderbuffer(GL_RENDERBUFFER, mHandle);
   37        }
   38        void storage(glm::u32vec2 size, InternalFormat internalFormat) {
   39            bind();
   40            if constexpr (multisampling == Multisampling::ENABLED) {
   41                glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, (int)internalFormat, size.x, size.y);
   42            } else {
   43                glRenderbufferStorage(GL_RENDERBUFFER, (int)internalFormat, size.x, size.y);
   44            }
   45        }
   46
   47    private:
   48        GLuint mHandle;
   49    };
   50}