diff --git a/lib/rendering/CvMatRender.cpp b/lib/rendering/CvMatRender.cpp index e678d07..9482ed9 100644 --- a/lib/rendering/CvMatRender.cpp +++ b/lib/rendering/CvMatRender.cpp @@ -1,14 +1,15 @@ #include "CvMatRender.hpp" #include +#include using namespace pixelarium::imaging; -pixelarium::render::CvMatRender::CvMatRender(const Image& img) +pixelarium::render::CvMatRender::CvMatRender(const std::shared_ptr& img) + : _base(img), _texture(0) { - this->_img = img.GetImage(); - this->_texture = 0; - - cv::cvtColor(this->_img, this->_img, cv::COLOR_BGR2RGBA); + this->_img = this->_base->GetImage().clone(); + // // storing a copy of the to-be-rendered image with a "well-behaved" + // cv::cvtColor(this->_img, this->_img, cv::COLOR_BGR2RGBA); } /*static*/ void pixelarium::render::matToTexture(const cv::Mat& image, GLuint* texture) @@ -42,8 +43,11 @@ pixelarium::render::CvMatRender::CvMatRender(const Image& img) } } -GLuint pixelarium::render::CvMatRender::Render() +GLuint* pixelarium::render::CvMatRender::Render() { - matToTexture(this->_img, &this->_texture); - return this->_texture; + // storing a copy of the to-be-rendered image with a "well-behaved" + cv::cvtColor(this->_img, this->_img, cv::COLOR_BGR2RGBA); + if (this->_texture == 0) + matToTexture(this->_img, &this->_texture); + return &this->_texture; } diff --git a/lib/rendering/CvMatRender.hpp b/lib/rendering/CvMatRender.hpp index 2b05b27..2bdd6c3 100644 --- a/lib/rendering/CvMatRender.hpp +++ b/lib/rendering/CvMatRender.hpp @@ -1,4 +1,8 @@ #pragma once +// windows. must come before GL/GL.h here. +// clang format would change this, effectively rendering the build broken. +// clang-format off +#include #ifdef _WIN32 #include #include @@ -10,20 +14,21 @@ #include // Will drag system OpenGL headers #endif #include "imaging/Image.hpp" +// clang-format on namespace pixelarium::render { - static void matToTexture(const cv::Mat& image, - GLuint* texture); +static void matToTexture(const cv::Mat& image, GLuint* texture); class CvMatRender { public: - explicit CvMatRender(const pixelarium::imaging::Image& img); - // void* Render(); - GLuint Render(); + CvMatRender() = default; + explicit CvMatRender(const std::shared_ptr& img); + GLuint* Render(); private: cv::Mat _img; + std::shared_ptr _base; GLuint _texture; }; diff --git a/src/AppGLFW.cpp b/src/AppGLFW.cpp index 4e95b3d..d769fe7 100644 --- a/src/AppGLFW.cpp +++ b/src/AppGLFW.cpp @@ -1,4 +1,6 @@ #include "AppGLFW.hpp" +#include +#include #include "imgui.h" @@ -115,9 +117,9 @@ int pixelarium::ui::AppGLFW::Run() if (this->_imagep) { - auto render = render::CvMatRender(this->_img); + // auto render = render::CvMatRender(this->_img); ImGui::Begin("An image", &this->_imagep, NULL); - ImGui::Image(render.Render(), ImVec2(this->_img.GetImage().cols, this->_img.GetImage().rows)); + ImGui::Image(*this->_render.Render(), ImVec2(this->_img->GetImage().cols, this->_img->GetImage().rows)); ImGui::End(); } @@ -185,7 +187,9 @@ void pixelarium::ui::AppGLFW::LoadImageProt() // lg::Logger::Debug("Adding image from " + std::string(p), // __FUNCTION__); - this->_img = Image(p); + // this->_img = Image(p); + this->_img = std::make_shared(p); + this->_render = pixelarium::render::CvMatRender(this->_img); this->_imagep = true; } } \ No newline at end of file diff --git a/src/AppGLFW.hpp b/src/AppGLFW.hpp index ca69ff6..cc6ab24 100644 --- a/src/AppGLFW.hpp +++ b/src/AppGLFW.hpp @@ -8,6 +8,7 @@ #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" +#include "rendering/CvMatRender.hpp" namespace pixelarium::ui { @@ -33,7 +34,8 @@ class AppGLFW LogLevelSelection log_level_ = static_cast(0); GLFWwindow* window = nullptr; ImGuiWindowFlags window_flags = 0; - pixelarium::imaging::Image _img; + std::shared_ptr _img; + pixelarium::render::CvMatRender _render; bool _imagep { false }; };