rolmodl
C++ API for the Simple Directmedia Library 2 (SDL2)
SWTex.hpp
1 #pragma once
2 
3 #include "forwarddecl/SWTex.hpp"
4 
5 #include "forwarddecl/Geom.hpp"
6 #include "forwarddecl/PixelFmt.hpp"
7 #include "forwarddecl/Base.hpp"
8 #include "Win.hpp"
9 
10 namespace rolmodl {
11  class SWTex_Base {
12  public:
13  SWTex_Base(const geom::Size s, const pixelfmt::Id fmt);
14  ~SWTex_Base() noexcept;
15 
16  SWTex_Base(const SWTex_Base& that) = delete;
17  SWTex_Base(SWTex_Base&& that) noexcept;
18 
19  SWTex_Base& operator=(const SWTex_Base& that) = delete;
20  SWTex_Base& operator=(SWTex_Base&& that) noexcept;
21 
22  friend void swap(SWTex_Base& a, SWTex_Base& b) noexcept;
23 
24  pixelfmt::Id fmtId() noexcept;
25  pixelfmt::Id fmtId() const noexcept;
26 
27  SDL_PixelFormat& fmt() noexcept;
28  SDL_PixelFormat& fmt() const noexcept;
29 
30  unsigned int pitch() noexcept;
31  unsigned int pitch() const noexcept;
32 
33  int w() noexcept;
34  int w() const noexcept;
35  int h() noexcept;
36  int h() const noexcept;
37 
38  bool mustLock() noexcept;
39  bool mustLock() const noexcept;
40 
41  SDL_Surface* unsafeRaw() noexcept;
42  const SDL_Surface* unsafeRaw() const noexcept;
43 
44  uint32_t& unsafePoint(const geom::Pos p) noexcept;
45  const uint32_t& unsafePoint(const geom::Pos p) const noexcept;
46 
47  void* unsafeRawPixels() noexcept;
48  const void* unsafeRawPixels() const noexcept;
49 
50  protected:
51  SWTex_Base();
52 
53  friend class Win_SW;
54  friend class SWTex;
55  friend class SWTex_RLE;
56  SDL_Surface* h_;
57 
58  friend class SWTex_RLELock;
59  SWTex_Base& drawPoint(const RGBA c, const geom::Pos p) noexcept;
60  RGBA getPoint(const geom::Pos p) const noexcept;
61  };
62 
63  class SWTex : public SWTex_Base {
64  public:
65  SWTex(const geom::Size s, const pixelfmt::Id fmt);
66  explicit SWTex(SWTex_RLE&& rle) noexcept;
67 
68  SWTex& drawPoint(const RGBA c, const geom::Pos p) noexcept;
69  RGBA getPoint(const geom::Pos p) const noexcept;
70 
71  private:
72  friend class Win_SW;
73  SWTex();
74  };
75 
76  class SWTex_RLE : public SWTex_Base {
77  public:
78  SWTex_RLE(const geom::Size s, const pixelfmt::Id fmt);
79  explicit SWTex_RLE(SWTex&& nonRle) noexcept;
80  };
81 
82  class SWTex_RLELock {
83  public:
84  explicit SWTex_RLELock(SWTex_RLE& tex);
85  ~SWTex_RLELock() noexcept;
86 
87  SWTex_RLELock(const SWTex_RLELock& that) = delete;
88  SWTex_RLELock(SWTex_RLELock&& that) noexcept;
89 
90  SWTex_RLELock& operator=(const SWTex_RLELock& that) = delete;
91  SWTex_RLELock& operator=(SWTex_RLELock&& that) noexcept;
92 
93  friend void swap(SWTex_RLELock& a, SWTex_RLELock& b) noexcept;
94 
95  SWTex_RLELock& drawPoint(const RGBA c, const geom::Pos p) noexcept;
96  RGBA getPoint(const geom::Pos p) const noexcept;
97 
98  private:
99  SWTex_RLELock() noexcept;
100 
101  SWTex_RLE* h_;
102  };
103 
104  class Win_SW : public Win_Base {
105  public:
106  using Win_Base::Win_Base;
107  ~Win_SW() noexcept; // todo: we could rely on the SDL_Surface do not free flag instead
108 
109  SWTex& swtex();
110 
111  private:
112  SWTex tex;
113  };
114 }
rolmodl::SWTex_RLELock
Definition: SWTex.hpp:82
rolmodl::SWTex
Definition: SWTex.hpp:63
rolmodl::RGBA
RGBA color type. Has an alpha component.
Definition: Base.hpp:377
rolmodl::SWTex_RLE
Definition: SWTex.hpp:76
rolmodl::geom::Size
int dimensions data type. The value is in pixels. Semantically different from rolmodl::geom::Pos.
Definition: Geom.hpp:31
rolmodl
Main namespace.
Definition: Base.cpp:7
rolmodl::SWTex_Base
Definition: SWTex.hpp:11
rolmodl::geom::Pos
int point data type. The value is in pixels. Semantically different from rolmodl::geom::Size.
Definition: Geom.hpp:18
Win.hpp
rolmodl::Win_Base
Common window class. Use rolmodl::Win for use with accelerated rendering (rolmodl::Ren) and rolmodl::...
Definition: Win.hpp:212
rolmodl::Win_SW
Definition: SWTex.hpp:104