implement selection mask with lasso tool
This commit is contained in:
@@ -457,11 +457,13 @@ void ui::Canvas::stroke_commit()
|
||||
m_tex2[i].bind();
|
||||
m_sampler.bind(0);
|
||||
m_sampler_bg.bind(1);
|
||||
m_sampler_mask.bind(2);
|
||||
if (m_state == kCanvasMode::Erase)
|
||||
{
|
||||
ui::ShaderManager::use(kShader::CompErase);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
|
||||
ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->m_brush.m_tip_opacity);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
|
||||
@@ -469,7 +471,11 @@ void ui::Canvas::stroke_commit()
|
||||
m_tex2[i].bind();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_tmp[i].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
m_smask.m_rtt[i].bindTexture();
|
||||
m_plane.draw_fill();
|
||||
m_smask.m_rtt[i].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_tmp[i].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_tex2[i].unbind();
|
||||
@@ -479,14 +485,20 @@ void ui::Canvas::stroke_commit()
|
||||
ui::ShaderManager::use(kShader::CompDraw);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
|
||||
ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->m_brush.m_tip_opacity);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Mask, m_smask_active);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_tex2[i].bind();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_tmp[i].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
m_smask.m_rtt[i].bindTexture();
|
||||
m_plane.draw_fill();
|
||||
m_smask.m_rtt[i].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_tmp[i].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_tex2[i].unbind();
|
||||
@@ -699,7 +711,7 @@ bool ui::Canvas::create(int width, int height)
|
||||
m_sampler_brush.create();
|
||||
m_sampler_brush.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
|
||||
m_sampler_bg.create(GL_NEAREST);
|
||||
m_sampler_mask.create(GL_NEAREST);
|
||||
m_sampler_mask.create(GL_LINEAR);
|
||||
m_plane.create<1>(1, 1);
|
||||
m_plane_brush.create<1>(1, 1);
|
||||
m_mesh.create();
|
||||
@@ -707,6 +719,8 @@ bool ui::Canvas::create(int width, int height)
|
||||
{
|
||||
l.create(width, height, "");
|
||||
}
|
||||
m_smask.create(width*2, height*2, "mask");
|
||||
m_smask.clear({1, 1, 1, 1});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1246,7 +1260,7 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path)
|
||||
return std::move(thumb);
|
||||
}
|
||||
|
||||
void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj)> observer)
|
||||
void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj)> observer, Layer& layer)
|
||||
{
|
||||
// save viewport and clear color states
|
||||
GLint vp[4];
|
||||
@@ -1256,18 +1270,18 @@ void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const
|
||||
GLboolean blend = glIsEnabled(GL_BLEND);
|
||||
|
||||
// prepare common states
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
glViewport(0, 0, layer.w, layer.h);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glm::mat4 proj = glm::perspective(glm::radians(90.f), 1.f, .1f, 100.f);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
glm::mat4 plane_camera = glm::lookAt(glm::vec3(0), m_plane_origin[i], m_plane_tangent[i]);
|
||||
m_layers[m_current_layer_idx].m_rtt[i].bindFramebuffer();
|
||||
layer.m_rtt[i].bindFramebuffer();
|
||||
|
||||
observer(plane_camera, proj);
|
||||
|
||||
m_layers[m_current_layer_idx].m_rtt[i].unbindFramebuffer();
|
||||
layer.m_rtt[i].unbindFramebuffer();
|
||||
}
|
||||
|
||||
// restore viewport and clear color states
|
||||
@@ -1277,6 +1291,11 @@ void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj)> observer)
|
||||
{
|
||||
draw_objects(observer, m_layers[m_current_layer_idx]);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ui::Layer::destroy()
|
||||
|
||||
Reference in New Issue
Block a user