texture.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <QOpenGLFunctions_3_3_Core>
  3. #include <QString>
  4. namespace Render::GL {
  5. class Texture : protected QOpenGLFunctions_3_3_Core {
  6. public:
  7. enum class Format { RGB, RGBA, Depth };
  8. enum class Filter { Nearest, Linear };
  9. enum class Wrap { Repeat, ClampToEdge, ClampToBorder };
  10. Texture();
  11. ~Texture() override;
  12. auto load_from_file(const QString &path) -> bool;
  13. auto create_empty(int width, int height,
  14. Format format = Format::RGBA) -> bool;
  15. void bind(int unit = 0);
  16. void unbind();
  17. void set_filter(Filter min_filter, Filter mag_filter);
  18. void set_wrap(Wrap s_wrap, Wrap t_wrap);
  19. [[nodiscard]] auto get_width() const -> int { return m_width; }
  20. [[nodiscard]] auto get_height() const -> int { return m_height; }
  21. private:
  22. GLuint m_texture = 0;
  23. int m_width = 0;
  24. int m_height = 0;
  25. Format m_format = Format::RGBA;
  26. [[nodiscard]] static auto get_gl_format(Format format) -> GLenum;
  27. [[nodiscard]] static auto get_gl_filter(Filter filter) -> GLenum;
  28. [[nodiscard]] static auto get_gl_wrap(Wrap wrap) -> GLenum;
  29. };
  30. } // namespace Render::GL