mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 03:21:49 +00:00
add gui.create_frame
This commit is contained in:
parent
3014329280
commit
463098aa1e
8 changed files with 84 additions and 24 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include "graphics/core/Framebuffer.hpp"
|
||||
#include "graphics/core/DrawContext.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "frontend/UiDocument.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "../GUI.hpp"
|
||||
|
||||
|
|
@ -12,25 +13,23 @@ using namespace gui;
|
|||
|
||||
static inline constexpr int MAX_TEXTURE_SIZE = 2048;
|
||||
|
||||
gui::Frame::Frame(GUI& gui) : Container(gui, {}), fbo(nullptr) {}
|
||||
gui::Frame::Frame(GUI& gui, std::string outputTexture)
|
||||
: Container(gui, {}),
|
||||
fbo(nullptr),
|
||||
outputTexture(std::move(outputTexture)) {
|
||||
}
|
||||
|
||||
gui::Frame::~Frame() = default;
|
||||
|
||||
void gui::Frame::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
if (fbo == nullptr) {
|
||||
return;
|
||||
}
|
||||
glm::ivec2 size = getSize();
|
||||
if (size.x <= 0 || size.y <= 0 ||
|
||||
size.x > MAX_TEXTURE_SIZE || size.y > MAX_TEXTURE_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto& nonConstASsets = const_cast<Assets&>(assets);
|
||||
if (fbo && (fbo->getWidth() != size.x || fbo->getHeight() != size.y)) {
|
||||
fbo->resize(size.x, size.y);
|
||||
nonConstASsets.store(fbo->getSharedTexture(), texture);
|
||||
} else if (fbo == nullptr) {
|
||||
fbo = std::make_unique<Framebuffer>(size.x, size.y, true);
|
||||
nonConstASsets.store(fbo->getSharedTexture(), texture);
|
||||
}
|
||||
|
||||
// ui uses flipped camera with matrix based on main viewport
|
||||
setPos({0, pctx.getViewport().y - size.y});
|
||||
|
||||
|
|
@ -40,3 +39,17 @@ void gui::Frame::draw(const DrawContext& pctx, const Assets& assets) {
|
|||
Container::draw(ctx, assets);
|
||||
ctx.getBatch2D()->flush();
|
||||
}
|
||||
|
||||
void gui::Frame::updateOutput(Assets& assets) {
|
||||
if (fbo && (fbo->getWidth() != size.x || fbo->getHeight() != size.y)) {
|
||||
fbo->resize(size.x, size.y);
|
||||
assets.store(fbo->getSharedTexture(), outputTexture);
|
||||
} else if (fbo == nullptr) {
|
||||
fbo = std::make_unique<Framebuffer>(size.x, size.y, true);
|
||||
assets.store(fbo->getSharedTexture(), outputTexture);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& gui::Frame::getOutputTexture() const {
|
||||
return outputTexture;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue