render stroke preview to image
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
std::atomic_int NodeStrokePreview::s_instances{ 0 };
|
std::atomic_int NodeStrokePreview::s_instances{ 0 };
|
||||||
std::atomic_bool NodeStrokePreview::s_running{ false };
|
std::atomic_bool NodeStrokePreview::s_running{ false };
|
||||||
|
std::mutex NodeStrokePreview::s_render_mutex;
|
||||||
std::thread NodeStrokePreview::s_renderer;
|
std::thread NodeStrokePreview::s_renderer;
|
||||||
BlockingQueue<std::shared_ptr<NodeStrokePreview>> NodeStrokePreview::s_queue;
|
BlockingQueue<std::shared_ptr<NodeStrokePreview>> NodeStrokePreview::s_queue;
|
||||||
|
|
||||||
@@ -498,6 +499,27 @@ void NodeStrokePreview::draw_stroke_immediate()
|
|||||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image NodeStrokePreview::render_to_image()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> _lock(s_render_mutex);
|
||||||
|
|
||||||
|
App::I->render_task([this] {
|
||||||
|
auto new_size = m_preview_size;
|
||||||
|
if (!m_tex_preview.ready() || m_tex_preview.size() != new_size)
|
||||||
|
m_tex_preview.create((int)new_size.x, (int)new_size.y);
|
||||||
|
if (m_tex.size() != new_size)
|
||||||
|
{
|
||||||
|
m_rtt.create((int)new_size.x, (int)new_size.y);
|
||||||
|
m_rtt_mixer.create((int)new_size.x, (int)new_size.y);
|
||||||
|
m_tex.create((int)new_size.x, (int)new_size.y);
|
||||||
|
m_tex_dual.create((int)new_size.x, (int)new_size.y);
|
||||||
|
m_tex_background.create((int)new_size.x, (int)new_size.y);
|
||||||
|
}
|
||||||
|
draw_stroke_immediate();
|
||||||
|
});
|
||||||
|
return m_tex_preview.get_image();
|
||||||
|
}
|
||||||
|
|
||||||
void NodeStrokePreview::draw_stroke()
|
void NodeStrokePreview::draw_stroke()
|
||||||
{
|
{
|
||||||
if (m_size.x == 0 || m_size.y == 0)
|
if (m_size.x == 0 || m_size.y == 0)
|
||||||
@@ -519,6 +541,8 @@ void NodeStrokePreview::draw_stroke()
|
|||||||
auto node = s_queue.Get();
|
auto node = s_queue.Get();
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> _lock(s_render_mutex);
|
||||||
|
|
||||||
// if the brush is not already loaded, load it and then destroy it
|
// if the brush is not already loaded, load it and then destroy it
|
||||||
bool to_unload = (node->m_brush->m_tip_texture == nullptr);
|
bool to_unload = (node->m_brush->m_tip_texture == nullptr);
|
||||||
node->m_brush->preload();
|
node->m_brush->preload();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
using parent = NodeBorder;
|
using parent = NodeBorder;
|
||||||
static std::atomic_int s_instances;
|
static std::atomic_int s_instances;
|
||||||
static std::atomic_bool s_running;
|
static std::atomic_bool s_running;
|
||||||
|
static std::mutex s_render_mutex;
|
||||||
static std::thread s_renderer;
|
static std::thread s_renderer;
|
||||||
static BlockingQueue<std::shared_ptr<NodeStrokePreview>> s_queue;
|
static BlockingQueue<std::shared_ptr<NodeStrokePreview>> s_queue;
|
||||||
static void terminate_renderer();
|
static void terminate_renderer();
|
||||||
@@ -52,6 +53,7 @@ public:
|
|||||||
std::vector<StrokeFrame> stroke_draw_compute(Stroke& stroke) const;
|
std::vector<StrokeFrame> stroke_draw_compute(Stroke& stroke) const;
|
||||||
void draw_stroke();
|
void draw_stroke();
|
||||||
void draw_stroke_immediate();
|
void draw_stroke_immediate();
|
||||||
|
Image render_to_image();
|
||||||
virtual void draw() override;
|
virtual void draw() override;
|
||||||
virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom) override;
|
virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom) override;
|
||||||
virtual void destroy() override;
|
virtual void destroy() override;
|
||||||
|
|||||||
Reference in New Issue
Block a user