diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-01 19:35:43 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-01 19:35:43 +0200 |
commit | 9436414c5002e86e64f90be3f10933fdba63943e (patch) | |
tree | 96dde7340044d2088d6948dada1b0da0f34d4c43 /tile-shader.cpp | |
parent | 85a8bd54726fe4edc70676b797ed90f519dbbf7d (diff) |
a
Diffstat (limited to 'tile-shader.cpp')
-rw-r--r-- | tile-shader.cpp | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/tile-shader.cpp b/tile-shader.cpp index b04054b4..64e23ed1 100644 --- a/tile-shader.cpp +++ b/tile-shader.cpp @@ -19,21 +19,19 @@ tile_shader::tile_shader() vert.addSource(loader.shader("shaders/tile-shader.vert")); frag.addSource(loader.shader("shaders/tile-shader.frag")); +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif CORRADE_INTERNAL_ASSERT_OUTPUT(GL::Shader::compile({vert, frag})); - +#ifdef __clang__ +# pragma clang diagnostic pop +#endif attachShaders({vert, frag}); CORRADE_INTERNAL_ASSERT_OUTPUT(link()); setUniform(ScaleUniform, Vector2{640, 480}); - - samplers.reserve(MAX_SAMPLERS); -} - -tile_shader& tile_shader::bind_texture(GL::Texture2D& texture, int id) -{ - texture.bind(id); - return *this; } tile_shader& tile_shader::set_scale(const Vector2& scale) @@ -42,6 +40,7 @@ tile_shader& tile_shader::set_scale(const Vector2& scale) setUniform(ScaleUniform, scale); return *this; } + tile_shader& tile_shader::set_camera_offset(Vector2 camera_offset) { CORRADE_INTERNAL_ASSERT(std::fabs(camera_offset[0]) <= std::scalbn(1.f, std::numeric_limits<float>::digits)); @@ -50,36 +49,11 @@ tile_shader& tile_shader::set_camera_offset(Vector2 camera_offset) setUniform(OffsetUniform, camera_offset); return *this; } + Vector2 tile_shader::project(Vector3 pt) { float x = pt[1], y = pt[0], z = pt[2]; return { x-y, (x+y+z*2)*.75f }; } -int tile_shader::bind_sampler(const tile_shader::shared_sampler& atlas) -{ - CORRADE_INTERNAL_ASSERT(samplers.size() < MAX_SAMPLERS); - auto sampler_comparator = [](const sampler_tuple& a, const sampler_tuple& b) { - const auto& [ptr1, n1] = a; - const auto& [ptr2, n2] = b; - return ptr1.get() < ptr2.get(); - }; - auto it = std::lower_bound(samplers.begin(), samplers.end(), - sampler_tuple{atlas, -1}, sampler_comparator); - int idx; - if (it == samplers.end()) { - idx = (int)samplers.size(); - samplers.emplace_back(atlas, idx); - } else - idx = it->second; - atlas->texture().bind(idx); - return idx; -} - -void tile_shader::clear_samplers() -{ - Magnum::GL::AbstractTexture::unbindImages(0, samplers.size()); - samplers.clear(); -} - } // namespace Magnum::Examples |