texture.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef SIMPLE_GRAPHICAL_TEXTURE_H
  2. #define SIMPLE_GRAPHICAL_TEXTURE_H
  3. #include <tuple>
  4. #include "common_def.h"
  5. #include "pixel_format.h"
  6. namespace simple::graphical
  7. {
  8. class texture
  9. {
  10. public:
  11. enum class access
  12. {
  13. basic = SDL_TEXTUREACCESS_STATIC,
  14. streaming = SDL_TEXTUREACCESS_STREAMING,
  15. render_target = SDL_TEXTUREACCESS_TARGET
  16. };
  17. enum class flip_direction
  18. {
  19. none = SDL_FLIP_NONE,
  20. horizontal = SDL_FLIP_HORIZONTAL,
  21. vertical = SDL_FLIP_VERTICAL
  22. };
  23. std::tuple<bool, access, int2, pixel_format::type> info() const noexcept;
  24. protected:
  25. SDL_Texture* guts() const;
  26. explicit texture(SDL_Texture* guts);
  27. private:
  28. SDL_Texture* _guts;
  29. explicit texture(SDL_Renderer*, SDL_Surface*);
  30. explicit texture(SDL_Renderer*, pixel_format::type, int2 size, access);
  31. friend class renderer;
  32. };
  33. class basic_texture;
  34. class streaming_texture;
  35. class render_texture;
  36. class basic_texture : public texture
  37. {
  38. public:
  39. basic_texture(const streaming_texture &) noexcept;
  40. basic_texture(const render_texture &) noexcept;
  41. private:
  42. using texture::texture;
  43. friend class streaming_texture;
  44. friend class render_texture;
  45. friend class renderer;
  46. };
  47. class streaming_texture : public texture
  48. {
  49. public:
  50. explicit streaming_texture(const basic_texture &);
  51. private:
  52. using texture::texture;
  53. friend class basic_texture;
  54. friend class renderer;
  55. };
  56. class render_texture : public texture
  57. {
  58. public:
  59. explicit render_texture(const basic_texture &);
  60. private:
  61. using texture::texture;
  62. friend class basic_texture;
  63. friend class renderer;
  64. };
  65. using static_texture = basic_texture;
  66. struct texture_view
  67. {
  68. basic_texture texture;
  69. // TODO: make invalid ranges flip the texture
  70. range2D region = {int2{0,0}, range2D::limit().upper()};
  71. int2 pivot;
  72. texture::flip_direction flip;
  73. texture_view(basic_texture, range2D, int2 pivot = int2::zero(), texture::flip_direction flip = texture::flip_direction::none);
  74. texture_view(basic_texture, int2 pivot = int2::zero(), texture::flip_direction flip = texture::flip_direction::none);
  75. };
  76. using ::operator |;
  77. using ::operator &;
  78. using ::operator &&;
  79. } // namespace simple::graphical
  80. template<> struct simple::support::define_enum_flags_operators<simple::graphical::texture::flip_direction>
  81. : std::true_type {};
  82. #endif /* end of include guard */