summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tile-atlas.cpp2
-rw-r--r--src/wall-atlas.cpp54
-rw-r--r--src/wall-atlas.hpp65
3 files changed, 120 insertions, 1 deletions
diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp
index 298e7f9e..1867189f 100644
--- a/src/tile-atlas.cpp
+++ b/src/tile-atlas.cpp
@@ -20,7 +20,7 @@ tile_atlas::tile_atlas(StringView path, StringView name, const ImageView2D& imag
fm_soft_assert(size_ % Vector2ui{tile_count} == Vector2ui());
tex_.setLabel(path_)
.setWrapping(GL::SamplerWrapping::ClampToEdge)
- .setMagnificationFilter(GL::SamplerFilter::Linear)
+ .setMagnificationFilter(GL::SamplerFilter::Nearest)
.setMinificationFilter(GL::SamplerFilter::Linear)
.setMaxAnisotropy(1)
.setBorderColor(Color4{1, 0, 0, 1})
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
new file mode 100644
index 00000000..9b711f60
--- /dev/null
+++ b/src/wall-atlas.cpp
@@ -0,0 +1,54 @@
+#include "wall-atlas.hpp"
+#include "compat/assert.hpp"
+#include <utility>
+#include <Magnum/ImageView.h>
+#include <Magnum/GL/TextureFormat.h>
+
+namespace floormat {
+
+size_t wall_atlas::enum_to_index(enum rotation r)
+{
+ fm_debug_assert(r < rotation_COUNT);
+
+ auto x = uint8_t(r);
+ x >>= 1;
+ return x;
+}
+
+wall_atlas::wall_atlas(wall_info info, const ImageView2D& image,
+ ArrayView<const wall_frame_set> rotations,
+ ArrayView<const wall_frame> frames) :
+ _array{NoInit, frames.size()}, _info(std::move(info))
+{
+ fm_assert(info.depth > 0);
+ fm_assert(rotations.size() <= _rotations.size());
+ _rotation_count = (uint8_t)rotations.size();
+ for (auto i = 0uz; const auto& fr : frames)
+ _array[i++] = fr;
+ for (auto i = 0uz; const auto& r : rotations)
+ _rotations[i++] = r;
+
+ _texture.setLabel(_name)
+ .setWrapping(GL::SamplerWrapping::ClampToEdge)
+ .setMagnificationFilter(GL::SamplerFilter::Nearest)
+ .setMinificationFilter(GL::SamplerFilter::Linear)
+ .setMaxAnisotropy(1)
+ .setBorderColor(Color4{1, 0, 0, 1})
+ .setStorage(1, GL::textureFormat(image.format()), image.size())
+ .setSubImage(0, {}, image);
+}
+
+wall_atlas::wall_atlas() = default;
+wall_atlas::~wall_atlas() noexcept = default;
+const wall_frame_set& wall_atlas::frameset(size_t i) const { return _rotations[i]; }
+const wall_frame_set& wall_atlas::frameset(enum rotation r) const { return frameset(enum_to_index(r)); }
+const ArrayView<const wall_frame> wall_atlas::array() const { return _array; }
+StringView wall_atlas::name() const { return _info.name; }
+
+ArrayView<const wall_frame> wall_frames::items(const wall_atlas& a) const
+{
+ fm_debug_assert(index != (uint32_t)-1);
+ return { a.array() + index, count };
+}
+
+} // namespace floormat
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
new file mode 100644
index 00000000..02d0ce91
--- /dev/null
+++ b/src/wall-atlas.hpp
@@ -0,0 +1,65 @@
+#pragma once
+#include "src/rotation.hpp"
+#include <array>
+#include <Corrade/Containers/Array.h>
+#include <Corrade/Containers/String.h>
+#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Color.h>
+#include <Magnum/GL/Texture.h>
+
+namespace floormat {
+
+struct wall_atlas;
+
+struct wall_frame
+{
+ Vector2ui offset = { (unsigned)-1, (unsigned)-1 };
+};
+
+struct wall_frames
+{
+ uint32_t index = (uint32_t)-1, count = (uint32_t)-1;
+ Vector2ui pixel_size;
+ Color4 tint_mult{1,1,1,1};
+ Color3 tint_add;
+ uint8_t from_rotation = (uint8_t)-1;
+ bool mirrored : 1 = false;
+ ArrayView<const wall_frame> items(const wall_atlas& a) const;
+};
+
+struct wall_frame_set
+{
+ wall_frames wall, overlay, side, top;
+ wall_frames corner_L, corner_R;
+};
+
+struct wall_info
+{
+ String name = "(unnamed)"_s;
+ float depth = 1;
+};
+
+struct wall_atlas final
+{
+ wall_atlas();
+ wall_atlas(wall_info info,
+ const ImageView2D& image,
+ ArrayView<const wall_frame_set> rotations,
+ ArrayView<const wall_frame> frames);
+ ~wall_atlas() noexcept;
+ static size_t enum_to_index(enum rotation x);
+ const wall_frame_set& frameset(size_t i) const;
+ const wall_frame_set& frameset(enum rotation r) const;
+ const ArrayView<const wall_frame> array() const;
+ StringView name() const;
+
+private:
+ String _name;
+ std::array<wall_frame_set, 4> _rotations;
+ Array<wall_frame> _array;
+ GL::Texture2D _texture;
+ wall_info _info;
+ uint8_t _rotation_count = 0;
+};
+
+} // namespace floormat