summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-15 22:21:17 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-15 22:21:17 +0200
commitd5955d35b9fd32b31b4cd7b5b6f286e1b9c43494 (patch)
tree1f6893c7c7177088d6fd7166d78b87262ec201dc
parent1e8d16fe10917664f9520008f224f19692c3a668 (diff)
a
-rw-r--r--draw/wall-mesh.cpp4
-rw-r--r--draw/wall-mesh.hpp2
-rw-r--r--draw/wireframe-mesh.cpp9
-rw-r--r--draw/wireframe-mesh.hpp6
-rw-r--r--shaders/tile-shader.frag2
-rw-r--r--src/tile-atlas.cpp13
-rw-r--r--src/tile-atlas.hpp6
7 files changed, 21 insertions, 21 deletions
diff --git a/draw/wall-mesh.cpp b/draw/wall-mesh.cpp
index 81201598..c15be873 100644
--- a/draw/wall-mesh.cpp
+++ b/draw/wall-mesh.cpp
@@ -2,7 +2,7 @@
#include "tile-atlas.hpp"
#include "shaders/tile-shader.hpp"
#include "chunk.hpp"
-#include <Magnum/GL/RectangleTexture.h>
+#include <Magnum/GL/Texture.h>
#include <Magnum/GL/MeshView.h>
namespace floormat {
@@ -49,7 +49,7 @@ void wall_mesh::draw(tile_shader& shader, chunk& c)
_vertex_buffer.setSubData(0, data);
}
- const GL::RectangleTexture* last_texture = nullptr;
+ const GL::Texture2D* last_texture = nullptr;
Magnum::GL::MeshView mesh{_mesh};
for (std::size_t i = 0; i < COUNT; i++)
{
diff --git a/draw/wall-mesh.hpp b/draw/wall-mesh.hpp
index 364f3831..b021ef95 100644
--- a/draw/wall-mesh.hpp
+++ b/draw/wall-mesh.hpp
@@ -27,7 +27,7 @@ private:
using quad = std::array<vertex, 4>;
using vertex_array = std::array<quad, COUNT>;
- using texture_array = std::array<GL::RectangleTexture*, COUNT>;
+ using texture_array = std::array<GL::Texture2D*, COUNT>;
static void maybe_add_tile(vertex_array& data, texture_array& textures, tile& x, std::size_t pos);
static void add_wall(vertex_array& data, texture_array& textures, tile_image& img, std::size_t pos);
diff --git a/draw/wireframe-mesh.cpp b/draw/wireframe-mesh.cpp
index 0b6846d7..b0ba7676 100644
--- a/draw/wireframe-mesh.cpp
+++ b/draw/wireframe-mesh.cpp
@@ -12,18 +12,17 @@
namespace floormat::wireframe
{
-GL::RectangleTexture mesh_base::make_constant_texture()
+GL::Texture2D mesh_base::make_constant_texture()
{
const Vector4ub data[] = { {255, 255, 255, 255} };
Trade::ImageData2D img{PixelFormat::RGBA8Unorm, {1, 1}, {},
Containers::arrayView(data, 1), {}, {}};
- GL::RectangleTexture tex;
+ GL::Texture2D tex;
tex.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
.setMinificationFilter(GL::SamplerFilter::Nearest)
- .setMaxAnisotropy(1)
- .setStorage(GL::textureFormat(img.format()), img.size())
- .setSubImage({}, std::move(img));
+ .setStorage(1, GL::textureFormat(img.format()), img.size())
+ .setSubImage(0, {}, std::move(img));
return tex;
}
diff --git a/draw/wireframe-mesh.hpp b/draw/wireframe-mesh.hpp
index bd15a0bf..40471f8d 100644
--- a/draw/wireframe-mesh.hpp
+++ b/draw/wireframe-mesh.hpp
@@ -7,7 +7,7 @@
#include <Magnum/Math/Vector2.h>
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/Mesh.h>
-#include "Magnum/GL/RectangleTexture.h"
+#include "Magnum/GL/Texture.h"
namespace floormat {
@@ -28,9 +28,9 @@ concept traits = requires (const T& x) {
struct mesh_base
{
- static GL::RectangleTexture make_constant_texture();
+ static GL::Texture2D make_constant_texture();
GL::Buffer _vertex_buffer{{}, GL::BufferUsage::DynamicDraw}, _texcoords_buffer, _index_buffer;
- GL::RectangleTexture _texture = make_constant_texture();
+ GL::Texture2D _texture = make_constant_texture();
GL::Mesh _mesh;
mesh_base(GL::MeshPrimitive primitive, Containers::ArrayView<const void> index_data,
diff --git a/shaders/tile-shader.frag b/shaders/tile-shader.frag
index 13bc462c..5c070ebe 100644
--- a/shaders/tile-shader.frag
+++ b/shaders/tile-shader.frag
@@ -1,6 +1,6 @@
precision highp float;
-uniform sampler2DRect sampler;
+uniform sampler2D sampler;
layout (location = 2) uniform vec4 tint = vec4(1, 1, 1, 1);
noperspective in vec2 frag_texcoords;
diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp
index ea5a7791..c3b2449c 100644
--- a/src/tile-atlas.cpp
+++ b/src/tile-atlas.cpp
@@ -20,8 +20,8 @@ tile_atlas::tile_atlas(Containers::StringView name, const ImageView2D& image, Ve
.setMinificationFilter(GL::SamplerFilter::Linear)
.setMaxAnisotropy(1)
.setBorderColor(Color4{1, 0, 0, 1})
- .setStorage(GL::textureFormat(image.format()), image.size())
- .setSubImage({}, image);
+ .setStorage(1, GL::textureFormat(image.format()), image.size())
+ .setSubImage(0, {}, image);
}
std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t id_) const
@@ -31,11 +31,12 @@ std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t id_) const
const Vector2ui id = { (UnsignedInt)id_ % dims_[0], (UnsignedInt)id_ / dims_[0] };
const Vector2 p0(id * sz), p1(sz);
const auto x0 = p0.x(), x1 = p1.x()-1, y0 = p0.y(), y1 = p1.y()-1;
+ Vector2 size{size_};
return {{
- { x0+x1, y0+y1 }, // bottom right
- { x0+x1, y0 }, // top right
- { x0, y0+y1 }, // bottom left
- { x0, y0 } // top left
+ { (x0+x1)/size[0], (y0+y1)/size[1] }, // bottom right
+ { (x0+x1)/size[0], y0/size[1] }, // top right
+ { x0/size[0], (y0+y1)/size[1] }, // bottom left
+ { x0/size[0], y0/size[1] } // top left
}};
}
diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp
index 81cfc857..08a090a4 100644
--- a/src/tile-atlas.hpp
+++ b/src/tile-atlas.hpp
@@ -1,6 +1,6 @@
#pragma once
#include <Magnum/Magnum.h>
-#include <Magnum/GL/RectangleTexture.h>
+#include <Magnum/GL/Texture.h>
#include <array>
#include <string>
@@ -21,11 +21,11 @@ struct tile_atlas final
static constexpr std::array<UnsignedShort, 6> indices(std::size_t N);
Vector2ui pixel_size() const { return size_; }
Vector2ui num_tiles() const { return dims_; }
- GL::RectangleTexture& texture() { return tex_; }
+ GL::Texture2D& texture() { return tex_; }
Containers::StringView name() const { return name_; }
private:
- GL::RectangleTexture tex_;
+ GL::Texture2D tex_;
std::string name_;
Vector2ui size_, dims_;
};