unload brush texture from main memory, preload brush on preview to free render thread
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "brush.h"
|
||||
#include "asset.h"
|
||||
|
||||
void BrushMesh::draw(const std::vector<StrokeSample>& samples, const glm::mat4& proj)
|
||||
{
|
||||
@@ -325,6 +326,8 @@ void Stroke::start(const std::shared_ptr<Brush>& brush)
|
||||
|
||||
bool Brush::load_tip(const std::string& path, const std::string& thumb)
|
||||
{
|
||||
if (m_tip_texture)
|
||||
return true;
|
||||
m_tip_texture = std::make_shared<Texture2D>();
|
||||
if (!m_tip_texture->load(path))
|
||||
{
|
||||
@@ -342,6 +345,8 @@ bool Brush::load_tip(const std::string& path, const std::string& thumb)
|
||||
|
||||
bool Brush::load_dual(const std::string& path, const std::string& thumb)
|
||||
{
|
||||
if (m_dual_texture)
|
||||
return true;
|
||||
m_dual_texture = std::make_shared<Texture2D>();
|
||||
if (!m_dual_texture->load(path))
|
||||
{
|
||||
@@ -357,6 +362,8 @@ bool Brush::load_dual(const std::string& path, const std::string& thumb)
|
||||
|
||||
bool Brush::load_pattern(const std::string& path, const std::string& thumb)
|
||||
{
|
||||
if (m_pattern_texture)
|
||||
return true;
|
||||
m_pattern_texture = std::make_shared<Texture2D>();
|
||||
if (!m_pattern_texture->load(path))
|
||||
{
|
||||
@@ -372,10 +379,13 @@ bool Brush::load_pattern(const std::string& path, const std::string& thumb)
|
||||
|
||||
bool Brush::load()
|
||||
{
|
||||
if (!m_brush_path.empty())
|
||||
if (!m_brush_path.empty() && !m_tip_texture)
|
||||
{
|
||||
m_tip_texture = std::make_shared<Texture2D>();
|
||||
if (!m_tip_texture->load(m_brush_path))
|
||||
auto loaded = m_tip_img ?
|
||||
m_tip_texture->create(*m_tip_img) :
|
||||
m_tip_texture->load(m_brush_path);
|
||||
if (!loaded)
|
||||
{
|
||||
LOG("failed to load %s", m_brush_path.c_str());
|
||||
m_tip_texture = nullptr;
|
||||
@@ -384,10 +394,13 @@ bool Brush::load()
|
||||
m_tip_texture->create_mipmaps();
|
||||
m_tip_texture->auto_destroy = true;
|
||||
}
|
||||
if (!m_dual_path.empty())
|
||||
if (!m_dual_path.empty() && !m_dual_texture)
|
||||
{
|
||||
m_dual_texture = std::make_shared<Texture2D>();
|
||||
if (!m_dual_texture->load(m_dual_path))
|
||||
auto loaded = m_dual_img ?
|
||||
m_dual_texture->create(*m_dual_img) :
|
||||
m_dual_texture->load(m_dual_path);
|
||||
if (!loaded)
|
||||
{
|
||||
LOG("failed to load %s", m_dual_path.c_str());
|
||||
m_tip_texture = nullptr;
|
||||
@@ -397,10 +410,13 @@ bool Brush::load()
|
||||
m_dual_texture->create_mipmaps();
|
||||
m_dual_texture->auto_destroy = true;
|
||||
}
|
||||
if (!m_pattern_path.empty())
|
||||
if (!m_pattern_path.empty() && !m_pattern_texture)
|
||||
{
|
||||
m_pattern_texture = std::make_shared<Texture2D>();
|
||||
if (!m_pattern_texture->load(m_pattern_path))
|
||||
auto loaded = m_pattern_img ?
|
||||
m_pattern_texture->create(*m_pattern_img) :
|
||||
m_pattern_texture->load(m_pattern_path);
|
||||
if (!loaded)
|
||||
{
|
||||
LOG("failed to load %s", m_pattern_path.c_str());
|
||||
m_tip_texture = nullptr;
|
||||
@@ -413,3 +429,47 @@ bool Brush::load()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Brush::preload()
|
||||
{
|
||||
if (!m_brush_path.empty() && !m_tip_texture && !m_tip_img)
|
||||
{
|
||||
m_tip_img = std::make_shared<Image>();
|
||||
if (!m_tip_img->load(m_brush_path))
|
||||
return false;
|
||||
}
|
||||
if (!m_dual_path.empty() && !m_dual_texture && !m_dual_img)
|
||||
{
|
||||
m_dual_img = std::make_shared<Image>();
|
||||
if (!m_dual_img->load(m_dual_path))
|
||||
return false;
|
||||
}
|
||||
if (!m_pattern_path.empty() && !m_pattern_texture && !m_pattern_img)
|
||||
{
|
||||
m_pattern_img = std::make_shared<Image>();
|
||||
if (!m_pattern_img->load(m_pattern_path))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Brush::unload()
|
||||
{
|
||||
m_tip_texture = nullptr;
|
||||
m_tip_img = nullptr;
|
||||
m_dual_texture = nullptr;
|
||||
m_dual_img = nullptr;
|
||||
m_pattern_texture = nullptr;
|
||||
m_pattern_img = nullptr;
|
||||
}
|
||||
|
||||
bool Brush::valid()
|
||||
{
|
||||
if (!m_brush_path.empty() && !Asset::exist(m_brush_path))
|
||||
return false;
|
||||
if (!m_dual_path.empty() && !Asset::exist(m_dual_path))
|
||||
return false;
|
||||
if (!m_pattern_path.empty() && !Asset::exist(m_pattern_path))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user