Add triangle painting to ui::painter
This commit is contained in:
parent
d9fb3b1be6
commit
fec050307d
3 changed files with 17 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#include <psemek/gfx/color.hpp>
|
#include <psemek/gfx/color.hpp>
|
||||||
#include <psemek/gfx/texture.hpp>
|
#include <psemek/gfx/texture.hpp>
|
||||||
#include <psemek/geom/box.hpp>
|
#include <psemek/geom/box.hpp>
|
||||||
|
#include <psemek/geom/simplex.hpp>
|
||||||
|
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
@ -11,6 +12,7 @@ namespace psemek::ui
|
||||||
struct painter
|
struct painter
|
||||||
{
|
{
|
||||||
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_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_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 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;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ namespace psemek::ui
|
||||||
~painter_impl();
|
~painter_impl();
|
||||||
|
|
||||||
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_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_2d const & tex, gfx::color_rgba const & color) 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 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;
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,20 @@ void main()
|
||||||
batch.indices.insert(batch.indices.end(), {base + 0, base + 1, base + 2, base + 2, base + 1, base + 3});
|
batch.indices.insert(batch.indices.end(), {base + 0, base + 1, base + 2, base + 2, base + 1, base + 3});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void painter_impl::draw_triangle(geom::triangle<geom::point<float, 2>> const & tri, gfx::color_rgba const & color)
|
||||||
|
{
|
||||||
|
auto & batch = impl().batch<colored_batch>({});
|
||||||
|
|
||||||
|
std::uint32_t const depth = impl().depth++;
|
||||||
|
std::uint32_t const base = batch.vertices.size();
|
||||||
|
|
||||||
|
batch.vertices.push_back({tri[0], depth, color});
|
||||||
|
batch.vertices.push_back({tri[1], depth, color});
|
||||||
|
batch.vertices.push_back({tri[2], depth, color});
|
||||||
|
|
||||||
|
batch.indices.insert(batch.indices.end(), {base + 0, base + 1, base + 2});
|
||||||
|
}
|
||||||
|
|
||||||
void painter_impl::draw_glyph(font const & f, char32_t c, geom::box<float, 2> const & rect, gfx::color_rgba const & color)
|
void painter_impl::draw_glyph(font const & f, char32_t c, geom::box<float, 2> const & rect, gfx::color_rgba const & color)
|
||||||
{
|
{
|
||||||
auto tbox = f.texcoords(c);
|
auto tbox = f.texcoords(c);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue