Remove duplicated image draw API in ui::painter
This commit is contained in:
parent
329915ac1b
commit
77d3e6e3f2
4 changed files with 4 additions and 19 deletions
|
|
@ -15,9 +15,7 @@ namespace psemek::ui
|
||||||
virtual void draw_rect(geom::box<float, 2> const & rect, gfx::color_rgba const & color) = 0;
|
virtual void draw_rect(geom::box<float, 2> const & rect, gfx::color_rgba const & color) = 0;
|
||||||
virtual void draw_triangle(geom::triangle<geom::point<float, 2>> const & tri, gfx::color_rgba const & color) = 0;
|
virtual void draw_triangle(geom::triangle<geom::point<float, 2>> const & tri, gfx::color_rgba const & color) = 0;
|
||||||
virtual void draw_glyph(font const & f, char32_t c, geom::box<float, 2> const & rect, gfx::color_rgba const & color) = 0;
|
virtual void draw_glyph(font const & f, char32_t c, geom::box<float, 2> const & rect, gfx::color_rgba const & color) = 0;
|
||||||
virtual void draw_image(geom::box<float, 2> const & rect, gfx::texture_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}) = 0;
|
|
||||||
virtual void draw_image(geom::box<float, 2> const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) = 0;
|
virtual void draw_image(geom::box<float, 2> const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) = 0;
|
||||||
virtual void draw_subimage(geom::box<float, 2> const & rect, gfx::texture_2d const & tex, geom::box<float, 2> const & part, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) = 0;
|
|
||||||
|
|
||||||
virtual void begin_stencil() = 0;
|
virtual void begin_stencil() = 0;
|
||||||
virtual void commit_stencil() = 0;
|
virtual void commit_stencil() = 0;
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,7 @@ namespace psemek::ui
|
||||||
void draw_rect(geom::box<float, 2> const & rect, gfx::color_rgba const & color) override;
|
void draw_rect(geom::box<float, 2> const & rect, gfx::color_rgba const & color) override;
|
||||||
void draw_triangle(geom::triangle<geom::point<float, 2>> const & tri, gfx::color_rgba const & color) override;
|
void draw_triangle(geom::triangle<geom::point<float, 2>> const & tri, gfx::color_rgba const & color) override;
|
||||||
void draw_glyph(font const & f, char32_t c, geom::box<float, 2> const & rect, gfx::color_rgba const & color) override;
|
void draw_glyph(font const & f, char32_t c, geom::box<float, 2> const & rect, gfx::color_rgba const & color) override;
|
||||||
void draw_image(geom::box<float, 2> const & rect, gfx::texture_2d const & tex, gfx::color_rgba const & color) override;
|
|
||||||
void draw_image(geom::box<float, 2> const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) override;
|
void draw_image(geom::box<float, 2> const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) override;
|
||||||
void draw_subimage(geom::box<float, 2> const & rect, gfx::texture_2d const & tex, geom::box<float, 2> const & part, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) override;
|
|
||||||
|
|
||||||
void begin_stencil() override;
|
void begin_stencil() override;
|
||||||
void commit_stencil() override;
|
void commit_stencil() override;
|
||||||
|
|
|
||||||
|
|
@ -342,22 +342,9 @@ void main()
|
||||||
impl().draw_bbox |= rect;
|
impl().draw_bbox |= rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void painter_impl::draw_image(geom::box<float, 2> const & rect, gfx::texture_2d const & tex, gfx::color_rgba const & color)
|
|
||||||
{
|
|
||||||
geom::box<float, 2> part;
|
|
||||||
part[0] = {0.f, tex.width()};
|
|
||||||
part[1] = {0.f, tex.height()};
|
|
||||||
draw_subimage(rect, tex, part, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void painter_impl::draw_image(geom::box<float, 2> const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color, float rotation)
|
void painter_impl::draw_image(geom::box<float, 2> const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color, float rotation)
|
||||||
{
|
{
|
||||||
draw_subimage(rect, *tex.texture, geom::cast<float>(tex.part), color, rotation);
|
auto & batch = impl().batch<textured_batch>(textured_batch{tex.texture});
|
||||||
}
|
|
||||||
|
|
||||||
void painter_impl::draw_subimage(geom::box<float, 2> const & rect, gfx::texture_2d const & tex, geom::box<float, 2> const & part, gfx::color_rgba const & color, float rotation)
|
|
||||||
{
|
|
||||||
auto & batch = impl().batch<textured_batch>(textured_batch{&tex});
|
|
||||||
|
|
||||||
std::uint32_t const depth = impl().depth++;
|
std::uint32_t const depth = impl().depth++;
|
||||||
std::uint32_t const base = batch.vertices.size();
|
std::uint32_t const base = batch.vertices.size();
|
||||||
|
|
@ -377,6 +364,8 @@ void main()
|
||||||
p11 = c + geom::rotate(p11 - c, rotation);
|
p11 = c + geom::rotate(p11 - c, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto part = geom::cast<float>(tex.part);
|
||||||
|
|
||||||
batch.vertices.push_back({p00, depth, color, part.corner(0.f, 0.f)});
|
batch.vertices.push_back({p00, depth, color, part.corner(0.f, 0.f)});
|
||||||
batch.vertices.push_back({p10, depth, color, part.corner(1.f, 0.f)});
|
batch.vertices.push_back({p10, depth, color, part.corner(1.f, 0.f)});
|
||||||
batch.vertices.push_back({p01, depth, color, part.corner(0.f, 1.f)});
|
batch.vertices.push_back({p01, depth, color, part.corner(0.f, 1.f)});
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ namespace psemek::ui
|
||||||
if (*st->shadow_offset != geom::vector{0, 0})
|
if (*st->shadow_offset != geom::vector{0, 0})
|
||||||
p.draw_rect(box + geom::cast<float>(*st->shadow_offset), *st->shadow_color);
|
p.draw_rect(box + geom::cast<float>(*st->shadow_offset), *st->shadow_color);
|
||||||
|
|
||||||
p.draw_subimage(box, *image_, reg, color_);
|
p.draw_image(box, {image_.get(), geom::cast<std::size_t>(reg)}, color_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue