implement brush outline
This commit is contained in:
@@ -161,7 +161,15 @@ void App::initShaders()
|
|||||||
"out mediump vec4 frag;\n"
|
"out mediump vec4 frag;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" mediump float stroke = 1.0 - texture(tex, uv).r;\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";
|
"}\n";
|
||||||
// TEXTURE COMP ERASE
|
// TEXTURE COMP ERASE
|
||||||
static const char* shader_comp_erase_f =
|
static const char* shader_comp_erase_f =
|
||||||
|
|||||||
@@ -1090,8 +1090,9 @@ bool Canvas::create(int width, int height)
|
|||||||
}
|
}
|
||||||
m_sampler.create(GL_NEAREST);
|
m_sampler.create(GL_NEAREST);
|
||||||
m_sampler.create(GL_LINEAR);
|
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_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
|
||||||
|
m_sampler_brush.set_border({ 1, 1, 1, 1 });
|
||||||
m_sampler_bg.create(GL_NEAREST);
|
m_sampler_bg.create(GL_NEAREST);
|
||||||
m_sampler_mask.create(GL_LINEAR);
|
m_sampler_mask.create(GL_LINEAR);
|
||||||
m_sampler_stencil.create(GL_LINEAR, GL_REPEAT);
|
m_sampler_stencil.create(GL_LINEAR, GL_REPEAT);
|
||||||
|
|||||||
@@ -134,6 +134,12 @@ void Sampler::set_filter(GLint filter_min, GLint filter_mag)
|
|||||||
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, filter_mag);
|
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, filter_mag);
|
||||||
#endif // USE_SAMPLER
|
#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
|
void Sampler::bind(int unit) const
|
||||||
{
|
{
|
||||||
current_unit = unit;
|
current_unit = unit;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
bool create(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE);
|
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(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE);
|
||||||
void set_filter(GLint filter_min, GLint filter_mag);
|
void set_filter(GLint filter_min, GLint filter_mag);
|
||||||
|
void set_border(glm::vec4 rgba);
|
||||||
void bind(int unit) const;
|
void bind(int unit) const;
|
||||||
void unbind();
|
void unbind();
|
||||||
bool ready() const { return id != 0; }
|
bool ready() const { return id != 0; }
|
||||||
|
|||||||
Reference in New Issue
Block a user