diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-29 17:46:04 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-29 17:46:04 +0100 |
commit | cd1e7b6564e8508f84e84706557b89eb5471a978 (patch) | |
tree | 6df6b34a255a03d1284c0987a6179b37f04c2375 /shaders | |
parent | 09b1b3e7e4b80415db18e3944d548e7ab36f47cd (diff) |
shaders: lazy-initialize tint uniform
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/tile.cpp | 11 | ||||
-rw-r--r-- | shaders/tile.hpp | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/shaders/tile.cpp b/shaders/tile.cpp index 7fa703fc..c1c0ce79 100644 --- a/shaders/tile.cpp +++ b/shaders/tile.cpp @@ -30,8 +30,8 @@ tile_shader::tile_shader() CORRADE_INTERNAL_ASSERT_OUTPUT(link()); set_scale({640, 480}); - setUniform(OffsetUniform, Vector2{}); set_tint({1, 1, 1, 1}); + setUniform(OffsetUniform, Vector2{}); } tile_shader::~tile_shader() = default; @@ -51,17 +51,20 @@ tile_shader& tile_shader::set_camera_offset(Vector2d camera_offset) tile_shader& tile_shader::set_tint(const Vector4& tint) { - if (tint != _tint) - setUniform(TintUniform, _tint = tint); + _tint = tint; return *this; } void tile_shader::_draw() { + fm_assert(_camera_offset[0] < 1 << 24 && _camera_offset[1] < 1 << 24); + + if (_tint != _real_tint) + setUniform(TintUniform, _real_tint = _tint); + if (const auto offset = Vector2{(float)_camera_offset[0], (float)_camera_offset[1]}; offset != _real_camera_offset) { - fm_assert(offset[0] < 1 << 24 && offset[1] < 1 << 24); _real_camera_offset = offset; setUniform(OffsetUniform, offset); } diff --git a/shaders/tile.hpp b/shaders/tile.hpp index 5d763331..72f36c40 100644 --- a/shaders/tile.hpp +++ b/shaders/tile.hpp @@ -39,7 +39,7 @@ private: void _draw(); Vector2d _camera_offset; - Vector4 _tint; + Vector4 _tint, _real_tint; Vector2 _scale; Vector2 _real_camera_offset; |