AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
IRenderViewToTexture.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 <glm/glm.hpp>
   15#include <AUI/Common/AStaticVector.h>
   16#include <AUI/Geometry2D/ARect.h>
   17#include <AUI/Render/ARenderContext.h>
   18
   19class IRenderer;
   20class AView;
   21
   27public:
   28
   32    struct InvalidArea {
   36        struct Empty {};
   37
   41        struct Full {};
   42
   46        using Rectangles = AStaticVector<ARect<int>, ARenderContext::Rectangles::capacity() - 1>;
   47
   48        using Underlying = std::variant<Empty, Rectangles, Full>;
   49
   50        template<aui::convertible_to<Underlying> F>
   51        InvalidArea(F&& u) noexcept: mUnderlying(std::forward<F>(u)) {}
   52        InvalidArea() noexcept: mUnderlying(Empty{}) {}
   53
   54
   55        [[nodiscard]]
   56        bool empty() const noexcept {
   57            return std::holds_alternative<Empty>(mUnderlying);
   58        }
   59
   60        [[nodiscard]]
   61        bool full() const noexcept {
   62            return std::holds_alternative<Full>(mUnderlying);
   63        }
   64
   68        void addRectangle(ARect<int> rhs);
   69
   70        Rectangles* rectangles() noexcept {
   71            return std::get_if<Rectangles>(&mUnderlying);
   72        }
   73
   74        const Rectangles* rectangles() const noexcept {
   75            return std::get_if<Rectangles>(&mUnderlying);
   76        }
   77
   78    private:
   79        Underlying mUnderlying;
   80    };
   81
   82
   83
   84
   99    virtual bool begin(IRenderer& renderer, glm::ivec2 surfaceSize, IRenderViewToTexture::InvalidArea& invalidArea) = 0;
  100
  108    virtual void end(IRenderer& renderer) = 0;
  109
  115    virtual void draw(IRenderer& renderer) = 0;
  116
  117    virtual ~IRenderViewToTexture() = default;
  118
  119    static void enableForView(IRenderer& renderer, AView& view);
  120    static void disableForView(AView& view);
  121
  122    [[nodiscard]]
  123    static bool isEnabledForView(AView& view);
  124};
Vector-like container up to maxSize elements inplace.
Definition AStaticVector.h:33
Base class of all UI objects.
Definition AView.h:78
Rendering view to texture storage interface.
Definition IRenderViewToTexture.h:26
virtual void end(IRenderer &renderer)=0
Finishes drawing operation started with begin method.
virtual bool begin(IRenderer &renderer, glm::ivec2 surfaceSize, IRenderViewToTexture::InvalidArea &invalidArea)=0
Instructs the renderer to begin drawing to the surface (framebuffer) stored in IRenderViewToTexture.
virtual void draw(IRenderer &renderer)=0
Draws contents of the surface.
Base class for rendering.
Definition IRenderer.h:149
Axis aligned 2D rectangle.
Definition ARect.h:24
No redraw.
Definition IRenderViewToTexture.h:36
Full redraw.
Definition IRenderViewToTexture.h:41
Defines areas to invalidate (redraw).
Definition IRenderViewToTexture.h:32
AStaticVector< ARect< int >, ARenderContext::Rectangles::capacity() - 1 > Rectangles
Specific areas redraw.
Definition IRenderViewToTexture.h:46
void addRectangle(ARect< int > rhs)
Adds rectangle as an invalid area. If needed, switches to full redraw.