#ifndef ENGINE_IMAGE_QUAD_H #define ENGINE_IMAGE_QUAD_H #include #include #include #include #include "base/vecmath.h" #include "engine/animatable.h" namespace eng { class Shader; class Texture; class ImageQuad final : public Animatable { public: ImageQuad(); ~ImageQuad() final; void Create(const std::string& asset_name, std::array num_frames = {1, 1}, int frame_width = 0, int frame_height = 0); void Destory(); void AutoScale(); void SetCustomShader(Shader* shader); template void SetCustomUniform(const std::string& name, T value) { custom_uniforms_[name] = UniformValue(value); } // Animatable interface. void SetFrame(size_t frame) final; size_t GetFrame() const final { return current_frame_; } size_t GetNumFrames() const final; void SetColor(const base::Vector4f& color) final { color_ = color; } base::Vector4f GetColor() const final { return color_; } // Drawable interface. void Draw(float frame_frac) final; private: using UniformValue = std::variant; Texture* texture_ = nullptr; Shader* custom_shader_ = nullptr; std::unordered_map custom_uniforms_; size_t current_frame_ = 0; std::array num_frames_ = {1, 1}; // horizontal, vertical int frame_width_ = 0; int frame_height_ = 0; base::Vector4f color_ = {1, 1, 1, 1}; std::string asset_name_; float GetFrameWidth() const; float GetFrameHeight() const; base::Vector2f GetUVOffset(size_t frame) const; }; } // namespace eng #endif // ENGINE_IMAGE_QUAD_H