drag canvas, render layers and tmp, add/select layer, opacity for layer, color bucket filler
This commit is contained in:
@@ -2,25 +2,16 @@
|
||||
#include "log.h"
|
||||
#include "canvas.h"
|
||||
|
||||
void ui::Canvas::clear()
|
||||
void ui::Canvas::clear(const glm::vec4& c/*={0,0,0,1}*/)
|
||||
{
|
||||
m_fb.bindFramebuffer();
|
||||
|
||||
GLint vp[4];
|
||||
GLfloat cc[4];
|
||||
glGetIntegerv(GL_VIEWPORT, vp);
|
||||
m_layers[m_current_layer_idx].m_rtt.bindFramebuffer();
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
||||
|
||||
glClearColor(1, 1, 1, 0);
|
||||
glClearColor(c.r, c.g, c.b, c.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
|
||||
//
|
||||
|
||||
glViewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
|
||||
m_fb.unbindFramebuffer();
|
||||
m_layers[m_current_layer_idx].m_rtt.unbindFramebuffer();
|
||||
}
|
||||
void ui::Canvas::stroke_end()
|
||||
{
|
||||
@@ -45,6 +36,7 @@ void ui::Canvas::stroke_draw()
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
|
||||
auto proj = glm::ortho(0.f, (float)m_width, 0.f, (float)m_height, -1.f, 1.f);
|
||||
|
||||
auto m_brush = m_current_stroke->m_brush;
|
||||
auto samples = m_current_stroke->compute_samples();
|
||||
auto& tex = TextureManager::get(m_brush.m_tex_id);
|
||||
@@ -107,7 +99,7 @@ void ui::Canvas::stroke_draw()
|
||||
|
||||
glm::vec2 pad(1);
|
||||
glm::ivec2 tex_pos = glm::clamp(glm::floor(bb_min) - pad , { 0, 0 }, { m_width, m_height });
|
||||
glm::ivec2 tex_sz = glm::clamp(glm::ceil(bb_sz ) + pad*2.f, { 0, 0 }, { m_width, m_height });
|
||||
glm::ivec2 tex_sz = glm::clamp(glm::ceil(bb_sz ) + pad*2.f, { 0, 0 }, (glm::vec2)(glm::ivec2(m_width, m_height) - tex_pos));
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
|
||||
tex_pos.x, tex_pos.y,
|
||||
tex_pos.x, tex_pos.y,
|
||||
@@ -140,7 +132,7 @@ void ui::Canvas::stroke_commit()
|
||||
return;
|
||||
m_dirty = false;
|
||||
|
||||
m_fb.bindFramebuffer();
|
||||
m_layers[m_current_layer_idx].m_rtt.bindFramebuffer();
|
||||
|
||||
// copy to tmp2 for layer blending
|
||||
m_tex2.bind();
|
||||
@@ -164,7 +156,7 @@ void ui::Canvas::stroke_commit()
|
||||
ShaderManager::use(ui::kShader::StrokeLayer);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_int(kShaderUniform::TexBG, 1);
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->m_brush.m_tip_opacity); // TODO: if using opacity in commit, update blending to match the preview when rendering m_tmp in NodeCanvas
|
||||
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));
|
||||
m_plane.draw_fill();
|
||||
m_sampler.unbind();
|
||||
@@ -178,7 +170,7 @@ void ui::Canvas::stroke_commit()
|
||||
glViewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
|
||||
m_fb.unbindFramebuffer();
|
||||
m_layers[m_current_layer_idx].m_rtt.unbindFramebuffer();
|
||||
}
|
||||
void ui::Canvas::stroke_update(glm::vec2 point, float pressure)
|
||||
{
|
||||
@@ -205,21 +197,21 @@ void ui::Canvas::resize(int width, int height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_tmp.create(width, height);
|
||||
m_fb.create(width, height);
|
||||
m_tex.create(width, height);
|
||||
m_tex2.create(width, height);
|
||||
// m_tmp.create(width, height);
|
||||
// m_fb.create(width, height);
|
||||
// m_tex.create(width, height);
|
||||
// m_tex2.create(width, height);
|
||||
}
|
||||
bool ui::Canvas::create(int width, int height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_tmp.create(width, height);
|
||||
m_fb.create(width, height);
|
||||
//m_fb.create(width, height);
|
||||
m_tex.create(width, height);
|
||||
m_tex2.create(width, height); // TODO: destroy before recreating
|
||||
m_sampler.create(GL_LINEAR, GL_CLAMP_TO_EDGE);
|
||||
m_sampler_bg.create(GL_NEAREST, GL_CLAMP_TO_EDGE);
|
||||
m_sampler.create();
|
||||
m_sampler_bg.create();
|
||||
m_plane.create<1>(1, 1);
|
||||
m_mesh.create();
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user