rolmodl
C++ API for the Simple Directmedia Library 2 (SDL2)
Tex.hpp
1 #pragma once
2 
3 #include "forwarddecl/Tex.hpp"
4 
5 #include "forwarddecl/Ren.hpp"
6 #include "Base.hpp"
7 #include "PixelFmt.hpp"
8 #include "Geom.hpp"
9 
10 namespace rolmodl {
11  enum class TextureType {
12  Static, Lock, Ren
13  };
14  namespace textureType::unsafe {
15  constexpr TextureType fromSDLEnum(const int a) noexcept {
16  if (a == SDL_TEXTUREACCESS_STATIC)
17  return TextureType::Static;
18  if (a == SDL_TEXTUREACCESS_STREAMING)
19  return TextureType::Lock;
20  // if (a == SDL_TEXTUREACCESS_TARGET)
21  return TextureType::Ren;
22  }
23  constexpr int toSDLEnum(const TextureType a) noexcept {
24  if (a == TextureType::Static)
25  return SDL_TEXTUREACCESS_STATIC;
26  if (a == TextureType::Lock)
27  return SDL_TEXTUREACCESS_STREAMING;
28  // if (a == TextureType::Ren)
29  return SDL_TEXTUREACCESS_TARGET;
30  }
31  }
32 
33  struct TextureInfo {
34  public:
35  pixelfmt::Id fmt;
36  TextureType type;
37  geom::Size size;
38  };
39 
40  class Tex {
41  public:
42  ~Tex() noexcept;
43 
44  Tex(const Tex& that) = delete;
45  Tex(Tex&& that) noexcept;
46 
47  Tex& operator=(const Tex& that) = delete;
48  Tex& operator=(Tex&& that) noexcept;
49 
50  friend void swap(Tex& a, Tex& b) noexcept;
51 
52  BlendMode getBlendMode();
53  void setBlendMode(const BlendMode m);
54 
55  uint8_t getAlphaMod();
56  void setAlphaMod(const uint8_t i);
57 
58  RGB getRGBMod();
59  void setRGBMod(const RGB i);
60 
61  TextureInfo query();
62 
63  SDL_Texture* unsafeRaw() noexcept;
64  const SDL_Texture* unsafeRaw() const noexcept;
65 
66  protected:
67  Tex() noexcept;
68  Tex(Ren& r, const pixelfmt::Id fmt, const int access, const geom::Size s);
69 
70  SDL_Texture* h_;
71  };
72 
73  class StaticTex : public Tex {
74  public:
75  StaticTex(Ren& r, const pixelfmt::Id fmt, const geom::Size s);
76  };
77 
78  class LockTex : public Tex {
79  public:
80  LockTex(Ren& r, const pixelfmt::Id fmt, const geom::Size s);
81 
82  pixelfmt::Id format() const noexcept;
83 
84  private:
85  LockTex() noexcept;
86 
87  pixelfmt::Id format_;
88  };
89 
90  class RenTex : public Tex {
91  public:
92  RenTex(Ren& r, const pixelfmt::Id fmt, const geom::Size s);
93  };
94 
95 
96  class TexLock {
97  public:
98  explicit TexLock(LockTex& tex);
99  TexLock(LockTex& tex, const geom::RectWH r);
100  TexLock(LockTex& tex, const geom::RectXY r);
101  ~TexLock() noexcept;
102 
103  TexLock(const TexLock& that) = delete;
104  TexLock(TexLock&& that) noexcept;
105 
106  TexLock& operator=(const TexLock& that) = delete;
107  TexLock& operator=(TexLock&& that) noexcept;
108 
109  friend void swap(TexLock& a, TexLock& b) noexcept;
110 
111  TexLock& drawPoint(const RGBA c, const geom::Pos p) noexcept;
112  RGBA getPoint(const geom::Pos p) const noexcept;
113 
114  uint32_t& unsafePoint(const geom::Pos p) noexcept;
115  const uint32_t& unsafePoint(const geom::Pos p) const noexcept;
116 
117  void* unsafeRaw() noexcept;
118  const void* unsafeRaw() const noexcept;
119 
120  private:
121  TexLock() noexcept;
122  TexLock(LockTex& tex, const SDL_Rect* r);
123  TexLock(LockTex& tex, const SDL_Rect r);
124 
125  LockTex* t_;
126  void* h_;
127  unsigned int pitch_;
128  };
129 }
rolmodl::LockTex
Definition: Tex.hpp:78
PixelFmt.hpp
rolmodl::Ren
Renderer class that does not support rendering to texture. Use rolmodl::TexRen for rendering to textu...
Definition: Ren.hpp:305
rolmodl::RGBA
RGBA color type. Has an alpha component.
Definition: Base.hpp:377
rolmodl::geom::Size
int dimensions data type. The value is in pixels. Semantically different from rolmodl::geom::Pos.
Definition: Geom.hpp:31
Geom.hpp
rolmodl::RGB
RGB color type. No alpha component.
Definition: Base.hpp:355
rolmodl::TexLock
Definition: Tex.hpp:96
rolmodl::geom::RectXY
Rectangle represented by its top left corner coordinates and its bottom right corner coordinates.
Definition: Geom.hpp:87
rolmodl::geom::RectWH
Rectangle represented by its top left corner coordinates, width, and height.
Definition: Geom.hpp:59
rolmodl::RenTex
Definition: Tex.hpp:90
rolmodl::TextureInfo
Definition: Tex.hpp:33
rolmodl
Main namespace.
Definition: Base.cpp:7
rolmodl::Tex
Definition: Tex.hpp:40
rolmodl::BlendMode
BlendMode
Describes how colors are combined when rendering twice to the same place.
Definition: Ren.hpp:21
rolmodl::geom::Pos
int point data type. The value is in pixels. Semantically different from rolmodl::geom::Size.
Definition: Geom.hpp:18
rolmodl::StaticTex
Definition: Tex.hpp:73