summaryrefslogtreecommitdiffhomepage
path: root/atlas.hpp
blob: 43c858def74bfa3ecc0a6a75046710d3b768755d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
#include <Magnum/Math/Vector.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/Trade/ImageData.h>
#include <array>

namespace Magnum::Examples {

struct atlas_texture final
{
    atlas_texture(const Trade::ImageData2D& img, Vector2i dims);
    std::array<Vector2, 4> texcoords_for_id(int id) const;
    static std::array<Vector3, 4> floor_quad(Vector3 center, Vector2 size);
    static std::array<Vector3, 4> wall_quad(Vector3 center, Vector3 size);
    static std::array<UnsignedShort, 6> indices(int N);
    GL::Texture2D& texture() { return tex_; }
    constexpr int size() const { return dims_.product(); }
    constexpr Vector2i tile_size() const { return tile_size_; }

    atlas_texture(const atlas_texture&) = delete;
    atlas_texture& operator=(const atlas_texture&) = delete;
private:
    GL::Texture2D tex_;
    Vector2i size_, dims_, tile_size_;
};

} // namespace Magnum::Examples