summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-18 01:55:30 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-18 01:55:30 +0200
commitaebec6e9b095149252bf1e4642c211ae98efdf84 (patch)
treedfb9919de3fa8bb1a7ff99c9cb3fcbf17186e7c2 /shaders
parent2ce80cb4a85cc47dc10f0b70839b2d0f2381cca8 (diff)
a
Diffstat (limited to 'shaders')
-rw-r--r--shaders/tile-shader.cpp14
-rw-r--r--shaders/tile-shader.hpp23
-rw-r--r--shaders/tile-shader.vert2
3 files changed, 23 insertions, 16 deletions
diff --git a/shaders/tile-shader.cpp b/shaders/tile-shader.cpp
index 20b2230f..4c694c9e 100644
--- a/shaders/tile-shader.cpp
+++ b/shaders/tile-shader.cpp
@@ -1,5 +1,6 @@
#include "shaders/tile-shader.hpp"
#include "loader.hpp"
+#include "compat/assert.hpp"
#include <algorithm>
#include <Corrade/Containers/Reference.h>
#include <Corrade/Utility/Resource.h>
@@ -36,12 +37,17 @@ tile_shader& tile_shader::set_scale(const Vector2& scale)
return *this;
}
-tile_shader& tile_shader::set_camera_offset(Vector2 camera_offset)
+tile_shader& tile_shader::set_camera_offset(Vector2d camera_offset)
{
- CORRADE_INTERNAL_ASSERT(std::fabs(camera_offset[0]) <= std::scalbn(1.f, std::numeric_limits<float>::digits));
- CORRADE_INTERNAL_ASSERT(std::fabs(camera_offset[1]) <= std::scalbn(1.f, std::numeric_limits<float>::digits));
+ static constexpr auto MAX = std::numeric_limits<std::int32_t>::max();
+ ASSERT(std::fabs(camera_offset[0]) <= MAX);
+ ASSERT(std::fabs(camera_offset[1]) <= MAX);
if (camera_offset != camera_offset_)
- setUniform(OffsetUniform, 2*(camera_offset_ = camera_offset));
+ {
+ camera_offset_ = camera_offset;
+ setUniform(OffsetUniform, Vector2i{std::int32_t(camera_offset[0]*2), std::int32_t(camera_offset[1]*2)});
+ }
+
return *this;
}
diff --git a/shaders/tile-shader.hpp b/shaders/tile-shader.hpp
index 0dd2b631..af0d778c 100644
--- a/shaders/tile-shader.hpp
+++ b/shaders/tile-shader.hpp
@@ -15,31 +15,32 @@ struct tile_shader : GL::AbstractShaderProgram
Vector2 scale() const { return scale_; }
tile_shader& set_scale(const Vector2& scale);
- Vector2 camera_offset() const { return camera_offset_; }
- tile_shader& set_camera_offset(Vector2 camera_offset);
+ Vector2d camera_offset() const { return camera_offset_; }
+ tile_shader& set_camera_offset(Vector2d camera_offset);
Vector4 tint() const { return tint_; }
tile_shader& set_tint(const Vector4& tint);
- static constexpr Vector2 project(Vector3 pt);
- static constexpr Vector2 unproject(Vector2 px);
+ static constexpr Vector2d project(Vector3d pt);
+ static constexpr Vector2d unproject(Vector2d px);
private:
- Vector2 scale_, camera_offset_;
+ Vector2d camera_offset_;
+ Vector2 scale_;
Vector4 tint_;
enum { ScaleUniform = 0, OffsetUniform = 1, TintUniform = 2, };
};
-constexpr Vector2 tile_shader::project(const Vector3 pt)
+constexpr Vector2d tile_shader::project(const Vector3d pt)
{
- const float x = -pt[1], y = -pt[0], z = pt[2];
- return { x-y, (x+y+z*2)*.59f };
+ const auto x = -pt[0]*.5, y = pt[1]*.5, z = pt[2];
+ return { (x-y), (x+y+z)*.59 };
}
-constexpr Vector2 tile_shader::unproject(const Vector2 px)
+constexpr Vector2d tile_shader::unproject(const Vector2d px)
{
- const float X = px[0], Y = px[1];
- return { X/2 + 50.f * Y / 59, 50 * Y / 59 - X/2 };
+ const auto X = px[0], Y = px[1];
+ return { X/2 + 50 * Y / 59, 50 * Y / 59 - X/2 };
}
} // namespace floormat
diff --git a/shaders/tile-shader.vert b/shaders/tile-shader.vert
index 8b3f2dba..d28f25fb 100644
--- a/shaders/tile-shader.vert
+++ b/shaders/tile-shader.vert
@@ -1,7 +1,7 @@
precision highp float;
layout (location = 0) uniform vec2 scale;
-layout (location = 1) uniform vec2 offset;
+layout (location = 1) uniform ivec2 offset;
layout (location = 0) in vec4 position;
layout (location = 1) in vec2 texcoords;