fix mem runaway
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
#include "CvMatRender.hpp"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
using namespace pixelarium::imaging;
|
||||
|
||||
pixelarium::render::CvMatRender::CvMatRender(const Image& img)
|
||||
pixelarium::render::CvMatRender::CvMatRender(const std::shared_ptr<Image>& 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;
|
||||
}
|
||||
|
||||
@@ -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 <memory>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <GL/GL.h>
|
||||
@@ -10,20 +14,21 @@
|
||||
#include <GLFW/glfw3.h> // 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<pixelarium::imaging::Image>& img);
|
||||
GLuint* Render();
|
||||
|
||||
private:
|
||||
cv::Mat _img;
|
||||
std::shared_ptr<pixelarium::imaging::Image> _base;
|
||||
GLuint _texture;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user