Support rendering texture_view's in ui::painter

This commit is contained in:
Nikita Lisitsa 2022-02-10 13:29:37 +03:00
parent d01008114b
commit 93fd269c02
3 changed files with 8 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include <psemek/ui/font.hpp>
#include <psemek/gfx/color.hpp>
#include <psemek/gfx/texture.hpp>
#include <psemek/gfx/texture_view.hpp>
#include <psemek/geom/box.hpp>
#include <psemek/geom/simplex.hpp>
@ -15,6 +16,7 @@ namespace psemek::ui
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_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}) = 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}) = 0;
virtual void begin_stencil() = 0;

View file

@ -19,6 +19,7 @@ namespace psemek::ui
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_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}) 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}) override;
void begin_stencil() override;

View file

@ -342,6 +342,11 @@ void main()
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)
{
draw_subimage(rect, *tex.texture, geom::cast<float>(tex.part), color);
}
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)
{
auto & batch = impl().batch<textured_batch>(textured_batch{&tex});