AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Framebuffer.h
1
2/*
3 * AUI Framework - Declarative UI toolkit for modern C++20
4 * Copyright (C) 2020-2024 Alex2772 and Contributors
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 */
12
13#pragma once
14
15#include "AUI/Traits/values.h"
16#include "glm/fwd.hpp"
17#include <AUI/Common/AString.h>
18#include <cstdint>
19#include <glm/glm.hpp>
20#include <AUI/Common/AMap.h>
21#include <AUI/Common/AVector.h>
22#include <AUI/Views.h>
23#include <AUI/GL/gl.h>
24
25namespace gl {
26 class API_AUI_VIEWS Framebuffer: public aui::noncopyable {
27 public:
28
29#if AUI_PLATFORM_IOS
30 static constexpr auto DEFAULT_FB = 1;
31#else
32 static constexpr auto DEFAULT_FB = 0;
33#endif
34
36 friend class Framebuffer;
37 public:
38 virtual ~IRenderTarget() = default;
39
40 protected:
41 virtual void onFramebufferResize(glm::u32vec2 size) = 0;
42 virtual void attach(Framebuffer& to, GLenum attachmentType) = 0;
43 };
44
45 Framebuffer();
46 Framebuffer(Framebuffer&& rhs) noexcept: mHandle(rhs.mHandle),
47 mSize(rhs.mSize),
48 mAttachedTargets(std::move(rhs.mAttachedTargets)),
49 mSupersamplingRatio(rhs.mSupersamplingRatio) {
50 rhs.mHandle = 0;
51 }
52 virtual ~Framebuffer();
53
54 void bind();
55 void bindForRead();
56 void bindForWrite();
57 static void unbind();
58 void resize(glm::u32vec2 newSize);
59
60 [[nodiscard]]
61 std::uint32_t supersamlingRatio() const noexcept {
62 return mSupersamplingRatio;
63 }
64
65 void setSupersamplingRatio(std::uint32_t ratio) noexcept {
66 mSupersamplingRatio = ratio;
67 }
68
69 [[nodiscard]]
70 glm::u32vec2 supersampledSize() const noexcept {
71 return mSize * mSupersamplingRatio;
72 }
73
74 [[nodiscard]]
75 glm::u32vec2 size() const noexcept {
76 return mSize;
77 }
78
79 operator bool() const {
80 return mHandle;
81 }
82 uint32_t getHandle() const {
83 return mHandle;
84 }
85
86 void attach(_<IRenderTarget> renderTarget, GLenum attachmentType /* = GL_COLOR_ATTACHEMNT0 */) {
87 renderTarget->attach(*this, attachmentType);
88 unbind();
89 mAttachedTargets << std::move(renderTarget);
90 }
91
92 Framebuffer& operator=(Framebuffer&& rhs) noexcept {
93 if (mHandle == rhs.mHandle) {
94 return *this;
95 }
96 std::swap(mHandle, rhs.mHandle);
97 mSize = rhs.mSize;
98 mSupersamplingRatio = rhs.mSupersamplingRatio;
99 mAttachedTargets = std::move(rhs.mAttachedTargets);
100 return *this;
101 }
102
103 static gl::Framebuffer* current();
104
105 void bindViewport();
106
107 private:
108 uint32_t mHandle = 0;
109 std::uint32_t mSupersamplingRatio = 1;
110 glm::u32vec2 mSize{0, 0};
111 AVector<_<IRenderTarget>> mAttachedTargets;
112 };
113}
Definition Framebuffer.h:35
Definition Framebuffer.h:26
Forbids copy of your class.
Definition values.h:40