implement brush outline

This commit is contained in:
2019-01-18 11:11:00 +01:00
parent 580fab77c6
commit 8315b32550
4 changed files with 18 additions and 2 deletions

View File

@@ -161,7 +161,15 @@ void App::initShaders()
"out mediump vec4 frag;\n"
"void main() {\n"
" mediump float stroke = 1.0 - texture(tex, uv).r;\n"
" frag = vec4(col.rgb, stroke * alpha);\n"
" int zero_count = 0;\n"
" for (int x = -1; x <= 1; x++){\n"
" for (int y = -1; y <= 1; y++){\n"
" if (textureOffset(tex, uv, ivec2(x, y)).r == 1.0) \n"
" zero_count++;\n"
" }\n"
" }\n"
" float edge = (zero_count > 1 && zero_count < 9) ? 0.75 : 0.0;\n"
" frag = vec4(col.rgb, edge);\n"
"}\n";
// TEXTURE COMP ERASE
static const char* shader_comp_erase_f =

View File

@@ -1090,8 +1090,9 @@ bool Canvas::create(int width, int height)
}
m_sampler.create(GL_NEAREST);
m_sampler.create(GL_LINEAR);
m_sampler_brush.create();
m_sampler_brush.create(GL_LINEAR, GL_CLAMP_TO_BORDER);
m_sampler_brush.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
m_sampler_brush.set_border({ 1, 1, 1, 1 });
m_sampler_bg.create(GL_NEAREST);
m_sampler_mask.create(GL_LINEAR);
m_sampler_stencil.create(GL_LINEAR, GL_REPEAT);

View File

@@ -134,6 +134,12 @@ void Sampler::set_filter(GLint filter_min, GLint filter_mag)
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, filter_mag);
#endif // USE_SAMPLER
}
void Sampler::set_border(glm::vec4 rgba)
{
#if USE_SAMPLER
glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(rgba));
#endif // USE_SAMPLER
}
void Sampler::bind(int unit) const
{
current_unit = unit;

View File

@@ -32,6 +32,7 @@ public:
bool create(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE);
void set(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE);
void set_filter(GLint filter_min, GLint filter_mag);
void set_border(glm::vec4 rgba);
void bind(int unit) const;
void unbind();
bool ready() const { return id != 0; }