14   Tex::Tex(Ren& r, 
const pixelfmt::Id fmt, 
const int access, 
const geom::Size s) :
 
   15     h_(SDL_CreateTexture(r.unsafeRaw(), pixelfmt::
id::unsafe::toSDLEnum(fmt), access, s.w, s.h))
 
   21   Tex::~Tex() noexcept {
 
   23       SDL_DestroyTexture(h_);
 
   27   Tex::Tex(Tex&& that) noexcept :
 
   32   Tex& Tex::operator=(Tex&& that) noexcept {
 
   37   void swap(Tex& a, Tex& b) noexcept {
 
   43     SDL_BlendMode tmp = SDL_BLENDMODE_NONE;
 
   44     throwOnErr(SDL_GetTextureBlendMode(unsafeRaw(), &tmp));
 
   47   void Tex::setBlendMode(
const BlendMode m) {
 
   51   uint8_t Tex::getAlphaMod() {
 
   53     throwOnErr(SDL_GetTextureAlphaMod(unsafeRaw(), &res));
 
   56   void Tex::setAlphaMod(
const uint8_t i) {
 
   57     throwOnErr(SDL_SetTextureAlphaMod(unsafeRaw(), i));
 
   60   RGB Tex::getRGBMod() {
 
   62     throwOnErr(SDL_GetTextureColorMod(unsafeRaw(), &res.r, &res.g, &res.b));
 
   65   void Tex::setRGBMod(
const RGB i) {
 
   66     throwOnErr(SDL_SetTextureColorMod(unsafeRaw(), i.r, i.g, i.b));
 
   69   TextureInfo Tex::query() {
 
   74     throwOnErr(SDL_QueryTexture(unsafeRaw(), &format, &access, &res.size.w, &res.size.h));
 
   76     res.fmt = pixelfmt::id::unsafe::fromSDLEnum(format);
 
   77     res.type = textureType::unsafe::fromSDLEnum(access);
 
   86   SDL_Texture* Tex::unsafeRaw() noexcept {
 
   87     assert(h_ != 
nullptr);
 
   90   const SDL_Texture* Tex::unsafeRaw() const noexcept {
 
   91     assert(h_ != 
nullptr);
 
   95   StaticTex::StaticTex(Ren& r, 
const pixelfmt::Id fmt, 
const geom::Size s) :
 
   96     Tex(r, fmt, SDL_TEXTUREACCESS_STATIC, s) {}
 
   99   LockTex::LockTex() noexcept :
 
  101     format_(pixelfmt::
Id::unknown)
 
  103   LockTex::LockTex(Ren& r, 
const pixelfmt::Id fmt, 
const geom::Size s) :
 
  104     Tex(r, fmt, SDL_TEXTUREACCESS_STREAMING, s),
 
  108   pixelfmt::Id LockTex::format() const noexcept {
 
  109     assert(h_ != 
nullptr); 
 
  114   RenTex::RenTex(Ren& r, 
const pixelfmt::Id fmt, 
const geom::Size s) :
 
  115     Tex(r, fmt, SDL_TEXTUREACCESS_TARGET, s) {}
 
  118   TexLock::TexLock() noexcept :
 
  123   TexLock::TexLock(LockTex& tex, 
const SDL_Rect* r) :
 
  129     throwOnErr(SDL_LockTexture(tex.unsafeRaw(), r, &h_, &pitch));
 
  130     pitch_ = static_cast<unsigned int>(pitch);
 
  132   TexLock::TexLock(LockTex& tex, 
const SDL_Rect r) :
 
  135    TexLock::TexLock(LockTex& tex) :
 
  136     TexLock(tex, nullptr) {}
 
  137   TexLock::TexLock(LockTex& tex, 
const geom::RectWH r) :
 
  138     TexLock(tex, r.sdl()) {}
 
  139   TexLock::TexLock(LockTex& tex, 
const geom::RectXY r) :
 
  140     TexLock(tex, r.wh()) {}
 
  142   TexLock::~TexLock() noexcept {
 
  144       assert(t_ != 
nullptr);
 
  145       SDL_UnlockTexture(t_->unsafeRaw());
 
  153   TexLock::TexLock(TexLock&& that) noexcept :
 
  158   TexLock& TexLock::operator=(TexLock&& that) noexcept {
 
  163   void swap(TexLock& a, TexLock& b) noexcept {
 
  167     swap(a.pitch_, b.pitch_);
 
  170   TexLock& TexLock::drawPoint(
const RGBA c, 
const geom::Pos p) noexcept {
 
  171     const SDL_PixelFormat f = pixelfmt::PixelFmtStorage::instance().get(t_->format());
 
  174     const uint32_t mask = static_cast<uint32_t>((~0 << f.BitsPerPixel));
 
  176     uint32_t& val = unsafePoint(p);
 
  177     val = (val & mask) | SDL_MapRGBA(&f, c.r, c.g, c.b, c.a);
 
  181   RGBA TexLock::getPoint(
const geom::Pos p) 
const noexcept {
 
  182     const SDL_PixelFormat f = pixelfmt::PixelFmtStorage::instance().get(t_->format());
 
  185     SDL_GetRGBA(unsafePoint(p), &f, &c.r, &c.g, &c.b, &c.a);
 
  190   uint32_t& TexLock::unsafePoint(
const geom::Pos p) noexcept {
 
  191     return *reinterpret_cast<uint32_t*>(
 
  192       static_cast<char*>(unsafeRaw()) +
 
  193         static_cast<unsigned int>(p.y)*pitch_ +
 
  194         static_cast<unsigned int>(p.x)*pixelfmt::byteSizeOf(t_->format())
 
  197   const uint32_t& TexLock::unsafePoint(
const geom::Pos p) 
const noexcept {
 
  198     return *reinterpret_cast<const uint32_t*>(static_cast<const char*>(unsafeRaw()) + static_cast<unsigned int>(p.y)*pitch_ + p.x);
 
  206   void* TexLock::unsafeRaw() noexcept {
 
  207     assert(h_ != 
nullptr);
 
  210   const void* TexLock::unsafeRaw() const noexcept {
 
  211     assert(h_ != 
nullptr);