Store texcoords as float in texture_view
This commit is contained in:
parent
77d3e6e3f2
commit
f21fa3c2d6
5 changed files with 18 additions and 18 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <psemek/gfx/texture.hpp>
|
||||
#include <psemek/geom/box.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
|
|
@ -10,19 +12,19 @@ namespace psemek::gfx
|
|||
struct basic_texture_view
|
||||
{
|
||||
basic_texture<D, Target> const * texture = nullptr;
|
||||
geom::box<std::size_t, D> part;
|
||||
geom::box<float, D> part;
|
||||
|
||||
basic_texture_view(basic_texture<D, Target> const * texture = nullptr);
|
||||
basic_texture_view(basic_texture<D, Target> const * texture, geom::box<std::size_t, D> const & part);
|
||||
basic_texture_view(basic_texture<D, Target> const * texture, geom::box<float, D> const & part);
|
||||
|
||||
geom::vector<std::size_t, D> size() const { return part.dimensions(); }
|
||||
geom::vector<float, D> size() const { return part.dimensions(); }
|
||||
|
||||
std::size_t width() const
|
||||
float width() const
|
||||
{
|
||||
return part[0].length();
|
||||
}
|
||||
|
||||
std::size_t height() const
|
||||
float height() const
|
||||
{
|
||||
if constexpr (D >= 2)
|
||||
return part[1].length();
|
||||
|
|
@ -30,7 +32,7 @@ namespace psemek::gfx
|
|||
return 1;
|
||||
}
|
||||
|
||||
std::size_t depth() const
|
||||
float depth() const
|
||||
{
|
||||
if constexpr (D >= 3)
|
||||
return part[2].length();
|
||||
|
|
@ -47,13 +49,13 @@ namespace psemek::gfx
|
|||
{
|
||||
if (texture)
|
||||
{
|
||||
static const auto zero = geom::point<std::size_t, D>::zero();
|
||||
part = geom::span(zero, zero + texture->size());
|
||||
static const auto zero = geom::point<float, D>::zero();
|
||||
part = geom::span(zero, zero + geom::cast<float>(texture->size()));
|
||||
}
|
||||
}
|
||||
|
||||
template <std::size_t D, GLenum Target>
|
||||
basic_texture_view<D, Target>::basic_texture_view(basic_texture<D, Target> const * texture, geom::box<std::size_t, D> const & part)
|
||||
basic_texture_view<D, Target>::basic_texture_view(basic_texture<D, Target> const * texture, geom::box<float, D> const & part)
|
||||
: texture(texture)
|
||||
, part(part)
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ namespace psemek::ui
|
|||
{
|
||||
struct image
|
||||
{
|
||||
geom::box<std::size_t, 2> texcoords;
|
||||
geom::box<float, 2> texcoords;
|
||||
geom::box<float, 2> position;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ namespace psemek::ui
|
|||
image.position = g.position;
|
||||
image.position[0] += (std::round(image.position[0].min) - image.position[0].min);
|
||||
image.position[1] += (std::round(image.position[1].min) - image.position[1].min);
|
||||
image.texcoords = geom::cast<std::size_t>(*tc);
|
||||
image.texcoords = *tc;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -364,12 +364,10 @@ void main()
|
|||
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({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({p11, depth, color, part.corner(1.f, 1.f)});
|
||||
batch.vertices.push_back({p00, depth, color, tex.part.corner(0.f, 0.f)});
|
||||
batch.vertices.push_back({p10, depth, color, tex.part.corner(1.f, 0.f)});
|
||||
batch.vertices.push_back({p01, depth, color, tex.part.corner(0.f, 1.f)});
|
||||
batch.vertices.push_back({p11, depth, color, tex.part.corner(1.f, 1.f)});
|
||||
|
||||
batch.indices.insert(batch.indices.end(), {base + 0, base + 1, base + 2, base + 2, base + 1, base + 3});
|
||||
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ namespace psemek::ui
|
|||
if (*st->shadow_offset != geom::vector{0, 0})
|
||||
p.draw_rect(box + geom::cast<float>(*st->shadow_offset), *st->shadow_color);
|
||||
|
||||
p.draw_image(box, {image_.get(), geom::cast<std::size_t>(reg)}, color_);
|
||||
p.draw_image(box, {image_.get(), reg}, color_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue