diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-01 14:58:55 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-01 14:58:55 +0200 |
commit | 85a8bd54726fe4edc70676b797ed90f519dbbf7d (patch) | |
tree | 36c9f98cc947ea01e8317083e63ac75655e375d7 /tile-shader.hpp | |
parent | c29af0d0c0903eb24bf6fc2c2ef8593563b128c9 (diff) |
a
Diffstat (limited to 'tile-shader.hpp')
-rw-r--r-- | tile-shader.hpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tile-shader.hpp b/tile-shader.hpp index 34348814..ed771969 100644 --- a/tile-shader.hpp +++ b/tile-shader.hpp @@ -1,16 +1,25 @@ #pragma once +#include "tile-atlas.hpp" +#include <vector> +#include <utility> #include <Magnum/GL/AbstractShaderProgram.h> #include <Magnum/GL/Texture.h> #include <Magnum/Math/Color.h> #include <Magnum/Math/Vector2.h> #include <Magnum/Math/Matrix4.h> +struct tile_atlas; + namespace Magnum::Examples { struct tile_shader : GL::AbstractShaderProgram { + using shared_sampler = std::shared_ptr<tile_atlas>; + using sampler_tuple = std::pair<shared_sampler, int>; + typedef GL::Attribute<0, Vector3> Position; typedef GL::Attribute<1, Vector2> TextureCoordinates; + typedef GL::Attribute<2, int> SamplerId; explicit tile_shader(); @@ -21,11 +30,18 @@ struct tile_shader : GL::AbstractShaderProgram static Vector2 project(Vector3 pt); - tile_shader& bindTexture(GL::Texture2D& texture); + [[nodiscard]] int bind_sampler(const shared_sampler& atlas); + void clear_samplers(); + + tile_shader& bind_texture(GL::Texture2D& texture, int id); private: + std::vector<sampler_tuple> samplers; Vector2 scale_, camera_offset_; - enum { TextureUnit = 0 }; + + static constexpr int MAX_SAMPLERS = 16; + + enum { SamplerIdAttribute = 1, }; enum { ScaleUniform = 0, OffsetUniform = 3, }; }; |