summaryrefslogtreecommitdiffhomepage
path: root/shaders/shader.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-08-27 09:59:06 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-08-27 13:13:57 +0200
commit1c5eb68d2d791c87a2030e4b17fb26bdd7931888 (patch)
tree93086d7eb082f8a7d36840688eca87b42e4ba501 /shaders/shader.cpp
parent2a527f27e22ae35d4d8fccc66451745c7c93d1f9 (diff)
draw, main, shaders: now use shaders/tuc
Diffstat (limited to 'shaders/shader.cpp')
-rw-r--r--shaders/shader.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/shaders/shader.cpp b/shaders/shader.cpp
index 4b184057..22222842 100644
--- a/shaders/shader.cpp
+++ b/shaders/shader.cpp
@@ -12,7 +12,7 @@
namespace floormat {
-tile_shader::tile_shader()
+tile_shader::tile_shader(texture_unit_cache& tuc) : tuc{tuc}
{
constexpr auto min_version = GL::Version::GL330;
const auto version = GL::Context::current().version();
@@ -34,7 +34,7 @@ tile_shader::tile_shader()
set_tint({1, 1, 1, 1});
setUniform(OffsetUniform, Vector3(Vector2(_camera_offset), _depth_offset));
setUniform(EnableLightmapUniform, _enable_lightmap);
- setUniform(SamplerUniform, 0);
+ setUniform(SamplerUniform, _real_sampler = _sampler);
setUniform(LightmapSamplerUniform, 1);
}
@@ -67,7 +67,13 @@ tile_shader& tile_shader::set_lightmap_enabled(bool value)
return *this;
}
-void tile_shader::_draw()
+tile_shader& tile_shader::set_sampler(Int sampler)
+{
+ _sampler = sampler;
+ return *this;
+}
+
+void tile_shader::draw_pre(GL::AbstractTexture& tex)
{
fm_assert(std::fabs(_camera_offset[0]) < 1 << 24 && std::fabs(_camera_offset[1]) < 1 << 24);
fm_assert(std::fabs(_depth_offset) < 1 << 24);
@@ -75,12 +81,19 @@ void tile_shader::_draw()
if (_tint != _real_tint)
setUniform(TintUniform, _real_tint = _tint);
- if (const auto offset = Vector3(Vector2(_camera_offset), _depth_offset);
- offset != _real_camera_offset)
- {
- _real_camera_offset = offset;
- setUniform(OffsetUniform, offset);
- }
+ const auto offset = Vector3(Vector2(_camera_offset), _depth_offset);
+ if (offset != _real_camera_offset)
+ setUniform(OffsetUniform, _real_camera_offset = offset);
+
+ auto id = tuc.bind(tex);
+ set_sampler(id);
+ if (_sampler != _real_sampler)
+ setUniform(SamplerUniform, _real_sampler = _sampler);
+}
+
+void tile_shader::draw_post(GL::AbstractTexture& tex) // NOLINT(*-convert-member-functions-to-static)
+{
+ (void)tex;
}
float tile_shader::depth_value(const local_coords& xy, float offset) noexcept