implement stencil from file
This commit is contained in:
@@ -195,7 +195,7 @@
|
||||
<node height="20" pad="1" width="100%" dir="row">
|
||||
<slider-h id="tip-stencil" width="1" grow="1"/>
|
||||
<node width="20" pad="0" margin="0 0 0 2">
|
||||
<button text="..." height="20"></button>
|
||||
<button id="tip-stencil-load" text="..." height="20"></button>
|
||||
</node>
|
||||
</node>
|
||||
<node height="20" pad="1" width="100%"><slider-h id="tip-wet"/></node>
|
||||
|
||||
@@ -154,6 +154,10 @@ void App::init_sidebar()
|
||||
// if (canvas)
|
||||
// canvas->m_brush = stroke->m_canvas->m_brush;
|
||||
// };
|
||||
stroke->on_stencil_changed = [this](Node*target, uint16_t id) {
|
||||
Canvas::I->m_current_brush.m_tex_stencil_id = id;
|
||||
stroke->m_preview->draw_stroke();
|
||||
};
|
||||
|
||||
layers->on_layer_add = [this](Node*) {
|
||||
canvas->m_canvas->layer_add(layers->m_layers.back()->m_label_text.c_str());
|
||||
|
||||
@@ -86,7 +86,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
|
||||
else if (canvas->m_canvas->m_show_tmp && canvas->m_canvas->m_current_layer_idx == layer_index)
|
||||
{
|
||||
sampler.bind(0);
|
||||
auto& paper = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
auto& paper = TextureManager::get(canvas->m_canvas->m_current_stroke->m_brush.m_tex_stencil_id);
|
||||
ShaderManager::use(kShader::CompDraw);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_int(kShaderUniform::TexStroke, 1);
|
||||
|
||||
@@ -8,6 +8,7 @@ public:
|
||||
int id = 0;
|
||||
std::string m_name;
|
||||
uint16_t m_tex_id = 0;
|
||||
uint16_t m_tex_stencil_id = const_hash("data/paper.jpg");
|
||||
glm::vec4 m_tip_color{1, 0, 0, 1};
|
||||
float m_tip_size = 0;
|
||||
float m_tip_spacing = 0;
|
||||
|
||||
@@ -290,7 +290,7 @@ void Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz)
|
||||
m_sampler.bind(0);
|
||||
m_sampler.bind(1);
|
||||
m_sampler.bind(2);
|
||||
auto& paper = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
auto& paper = TextureManager::get(m_current_stroke->m_brush.m_tex_stencil_id);
|
||||
ShaderManager::use(kShader::CompDraw);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
//ShaderManager::u_int(kShaderUniform::TexA, 0);
|
||||
@@ -346,7 +346,7 @@ void Canvas::stroke_draw()
|
||||
auto m_brush = m_current_stroke->m_brush;
|
||||
auto samples = m_current_stroke->compute_samples();
|
||||
auto& tex = TextureManager::get(m_brush.m_tex_id);
|
||||
auto& stencil = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
auto& stencil = TextureManager::get(m_brush.m_tex_stencil_id);
|
||||
auto ortho_proj = glm::ortho(0.f, (float)m_width, 0.f, (float)m_height, -1.f, 1.f);
|
||||
|
||||
std::vector<vertex_t> B{
|
||||
@@ -832,7 +832,7 @@ void Canvas::stroke_commit()
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& paper = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
auto& paper = TextureManager::get(m_current_stroke->m_brush.m_tex_stencil_id);
|
||||
|
||||
ShaderManager::use(kShader::CompDraw);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
|
||||
@@ -201,7 +201,7 @@ void NodeCanvas::draw()
|
||||
else if(m_canvas->m_current_stroke && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index)
|
||||
{
|
||||
m_sampler.bind(0);
|
||||
auto& paper = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
auto& paper = TextureManager::get(m_canvas->m_current_stroke->m_brush.m_tex_stencil_id);
|
||||
ShaderManager::use(kShader::CompDraw);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_int(kShaderUniform::TexStroke, 1);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "log.h"
|
||||
#include "node_panel_stroke.h"
|
||||
#include "canvas.h"
|
||||
#include "node_button.h"
|
||||
#include "app.h"
|
||||
|
||||
Node* NodePanelStroke::clone_instantiate() const
|
||||
{
|
||||
@@ -85,6 +87,17 @@ void NodePanelStroke::init_controls()
|
||||
|
||||
m_preview->m_brush = Canvas::I->m_current_brush;
|
||||
m_preview->draw_stroke();
|
||||
|
||||
auto load_stencil = find<NodeButton>("tip-stencil-load");
|
||||
load_stencil->on_click = [this](Node*) {
|
||||
App::I.pick_image([this](std::string path) {
|
||||
if (TextureManager::load(path.c_str()))
|
||||
{
|
||||
if (on_stencil_changed)
|
||||
on_stencil_changed(this, const_hash(path.c_str()));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
void NodePanelStroke::init_slider(NodeSliderH*& target, const char* id, float Brush::* prop)
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
NodeCheckBox* m_tip_sat_pressure;
|
||||
NodeCheckBox* m_tip_val_pressure;
|
||||
std::function<void(Node* target)> on_stroke_change;
|
||||
std::function<void(Node* target, uint16_t id)> on_stencil_changed;
|
||||
std::map<NodeSliderH*, std::function<float(float)>> m_curves;
|
||||
|
||||
virtual Node* clone_instantiate() const override;
|
||||
|
||||
@@ -80,7 +80,7 @@ void NodeStrokePreview::draw_stroke()
|
||||
tex.bind();
|
||||
m_sampler_brush.bind(0);
|
||||
|
||||
auto& stencil = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
auto& stencil = TextureManager::get(b.m_tex_stencil_id);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
stencil.bind();
|
||||
m_sampler.bind(1);
|
||||
|
||||
Reference in New Issue
Block a user