Resources (#1)

* start some resource fiddling

* start some resource fiddling

* initiate a real resource manager

* fix color flicker in rendering

* delete unintended constructors

and add a convenience function to reset the render-image (from the
original image, aka. clone again)

* [OpenGL deprecation warning]

The compiler said that these functions are "deprecated". They seem to
be useless anyway...

* various improvements

* add resource enumerator and documentation

* fix constness stuff

* use existing iterator for insertion

* init unit tests

* rm bogus file

---------

Co-authored-by: m-aXimilian <keuffnermax@gmail.com>
This commit is contained in:
m-aXimilian
2025-06-13 22:23:20 +00:00
committed by GitHub
parent a175b79c96
commit a8489292b6
21 changed files with 574 additions and 169 deletions
+28 -24
View File
@@ -1,8 +1,9 @@
#include "AppGLFW.hpp"
#include <format>
#include <memory>
#include "imaging/Image.hpp"
#include "imaging/PixelariumImage.hpp"
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
@@ -22,7 +23,8 @@ using namespace pixelarium::imaging;
return false;
}
/*static*/ ImVec2 pixelarium::ui::ascpet_const_dimensions(const pixelarium::imaging::Image& img, const ImVec2& curr_dim)
/*static*/ ImVec2 pixelarium::ui::aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img,
const ImVec2& curr_dim)
{
const auto w_fact = (static_cast<float>(curr_dim.x) / img.GetImage().cols);
const auto h_fact = (static_cast<float>(curr_dim.y) / img.GetImage().rows);
@@ -133,27 +135,33 @@ int pixelarium::ui::AppGLFW::Run()
this->MenuBar();
if (this->_imagep)
if (this->imagep_)
{
// auto render = render::CvMatRender(this->_img);
ImGui::Begin("An image", &this->_imagep, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar);
this->_curr_dim = ImGui::GetContentRegionAvail();
ImGui::Begin("An image", &this->imagep_, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar);
this->curr_dim_ = ImGui::GetContentRegionAvail();
auto new_dim = ImGui::GetContentRegionAvail();
auto texture = dim_changed_p(this->_curr_dim, new_dim)
? this->_render.Render(static_cast<size_t>(this->_curr_dim.x),
static_cast<size_t>(this->_curr_dim.y))
: this->_render.Render();
auto texture = dim_changed_p(this->curr_dim_, new_dim)
? this->render_.Render(static_cast<size_t>(this->curr_dim_.x),
static_cast<size_t>(this->curr_dim_.y))
: this->render_.Render();
this->_curr_dim = new_dim;
this->curr_dim_ = new_dim;
// random aspect ratio
// ImGui::Image(reinterpret_cast<Textured>(
// reinterpret_cast<void*>(*texture)),
// this->_curr_dim);
ImVec2 dim(this->_img->GetImage().cols, this->_img->GetImage().rows);
ImVec2 dim(this->img_->GetImage().cols, this->img_->GetImage().rows);
// aspect ratio constant render
ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(*texture)),
ascpet_const_dimensions(*this->_img, new_dim));
ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(texture)),
aspect_const_dimensions(*this->img_, new_dim));
// ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(texture)),
// ImVec2(img_->GetImage().cols, img_->GetImage().rows));
// We can do everything else from within the image buffer that ImGui offers
// ImGui::Separator();
// ImGui::Text("This is a text within the image frame");
ImGui::End();
}
@@ -162,8 +170,6 @@ int pixelarium::ui::AppGLFW::Run()
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(this->window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
@@ -217,15 +223,13 @@ void pixelarium::ui::AppGLFW::LoadImageProt()
auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()};
for (auto& p : res)
{
// lg::Logger::Debug("Adding image from " + std::string(p),
// __FUNCTION__);
if (this->_logger)
if (this->logger_)
{
this->_logger->Warn(std::format("Creating image {}", p));
this->logger_->Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
}
// this->_img = Image(p);
this->_img = std::make_shared<Image>(p);
this->_render = pixelarium::render::CvMatRender(this->_img);
this->_imagep = true;
this->img_ = std::make_shared<PixelariumImage>(p);
this->render_ = pixelarium::render::CvMatRender(this->img_);
this->imagep_ = true;
}
}
}