diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 15:29:41 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 15:29:41 +0200 |
commit | 445caf6184cafbce361670ea6028ff76317976bc (patch) | |
tree | 0ff8c2c33211f7a738de8f6f5d6cec79aa776f36 /shaders/tile-shader.cpp | |
parent | f339fa747348e742859701331b529f86d7bd8453 (diff) |
a
Diffstat (limited to 'shaders/tile-shader.cpp')
-rw-r--r-- | shaders/tile-shader.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/shaders/tile-shader.cpp b/shaders/tile-shader.cpp new file mode 100644 index 00000000..835f94a0 --- /dev/null +++ b/shaders/tile-shader.cpp @@ -0,0 +1,54 @@ +#include "shaders/tile-shader.hpp" +#include "loader.hpp" +#include <algorithm> +#include <Corrade/Containers/Reference.h> +#include <Corrade/Utility/Resource.h> +#include <Magnum/GL/Context.h> +#include <Magnum/GL/Shader.h> +#include <Magnum/GL/Version.h> + +namespace Magnum::Examples { + +tile_shader::tile_shader() +{ + MAGNUM_ASSERT_GL_VERSION_SUPPORTED(GL::Version::GL460); + + GL::Shader vert{GL::Version::GL460, GL::Shader::Type::Vertex}; + GL::Shader frag{GL::Version::GL460, GL::Shader::Type::Fragment}; + + 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()); + + set_scale({640, 480}); + set_camera_offset({0, 0}); +} + +tile_shader& tile_shader::set_scale(const Vector2& scale) +{ + scale_ = 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)); + CORRADE_INTERNAL_ASSERT(std::fabs(camera_offset[1]) <= std::scalbn(1.f, std::numeric_limits<float>::digits)); + camera_offset_ = camera_offset; + setUniform(OffsetUniform, camera_offset); + return *this; +} + +} // namespace Magnum::Examples |