AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
TextureRenderTarget.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
   15#include <AUI/Util/kAUI.h>
   16#include <AUI/GL/Framebuffer.h>
   17#include <AUI/GL/GLEnums.h>
   18
   19namespace gl {
   20
   21    template<InternalFormat internalFormat /* = GL_DEPTH_COMPONENT24 */,
   22             Type type                     /* = GL_FLOAT */,
   23             Format format                    = Format::DEPTH_COMPONENT>
   24    class TextureRenderTarget final: public Framebuffer::IRenderTarget {
   25    public:
   26        TextureRenderTarget() {
   27        }
   28
   29        void bindAsTexture(int index) {
   30            mTexture.bind(index);
   31        }
   32
   33        void attach(Framebuffer& to, GLenum attachmentType) override {
   34            to.bind();
   35            glGetError();
   36            onFramebufferResize(to.size());
   37            glFramebufferTexture2D(GL_FRAMEBUFFER, attachmentType, GL_TEXTURE_2D, mTexture.getHandle(), 0);
   38            if (glGetError() != GL_NO_ERROR) {
   39                throw AException("unable to create texture target");
   40            }
   41        }
   42
   43        [[nodiscard]]
   44        Texture2D& texture() noexcept {
   45            return mTexture;
   46        }
   47
   48        void onFramebufferResize(glm::u32vec2 size) override {
   49            mTexture.framebufferTex2D(size, type);
   50        }
   51
   52    private:
   53        Texture2D mTexture;
   54    };
   55}
Abstract AUI exception.
Definition AException.h:28
Definition Framebuffer.h:35
Definition Texture2D.h:20