Browse Source

move constructors

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
4fecdb3f88
3 changed files with 19 additions and 8 deletions
  1. 16
    4
      libswan/include/swan/gfxutil.h
  2. 2
    3
      libswan/src/OS.cc
  3. 1
    1
      libswan/src/gfxutil.cc

+ 16
- 4
libswan/include/swan/gfxutil.h View File

@@ -31,7 +31,13 @@ private:
class TexColorMod {
public:
TexColorMod(const TexColorMod &) = delete;
TexColorMod(TexColorMod &&) = delete;
TexColorMod(TexColorMod &&mod) noexcept {
tex_ = mod.tex_;
r_ = mod.r_;
g_ = mod.g_;
b_ = mod.b_;
mod.tex_ = nullptr;
}

TexColorMod(SDL_Texture *tex, uint8_t r, uint8_t g, uint8_t b): tex_(tex) {
SDL_GetTextureColorMod(tex_, &r_, &g_, &b_);
@@ -39,7 +45,8 @@ public:
}

~TexColorMod() {
SDL_SetTextureColorMod(tex_, r_, g_, b_);
if (tex_)
SDL_SetTextureColorMod(tex_, r_, g_, b_);
}

private:
@@ -50,7 +57,11 @@ private:
class TexAlphaMod {
public:
TexAlphaMod(const TexAlphaMod &) = delete;
TexAlphaMod(TexAlphaMod &&) = delete;
TexAlphaMod(TexAlphaMod &&mod) noexcept {
tex_ = mod.tex_;
alpha_ = mod.alpha_;
mod.tex_ = nullptr;
}

TexAlphaMod(SDL_Texture *tex, uint8_t alpha): tex_(tex) {
SDL_GetTextureAlphaMod(tex_, &alpha_);
@@ -58,7 +69,8 @@ public:
}

~TexAlphaMod() {
SDL_SetTextureAlphaMod(tex_, alpha_);
if (tex_)
SDL_SetTextureAlphaMod(tex_, alpha_);
}

private:

+ 2
- 3
libswan/src/OS.cc View File

@@ -16,9 +16,8 @@ bool isTTY(FILE *f) {

Dynlib::Dynlib(const std::string &path) {
handle_ = dlopen((path + ".so").c_str(), RTLD_LAZY);
if (handle_ == nullptr) {
if (!handle_)
throw std::runtime_error(dlerror());
}
}

Dynlib::Dynlib(Dynlib &&dl) noexcept {
@@ -27,7 +26,7 @@ Dynlib::Dynlib(Dynlib &&dl) noexcept {
}

Dynlib::~Dynlib() {
if (handle_ != nullptr)
if (handle_)
dlclose(handle_);
}


+ 1
- 1
libswan/src/gfxutil.cc View File

@@ -49,7 +49,7 @@ TexLock::TexLock(TexLock &&lock) noexcept {
}

TexLock::~TexLock() {
if (tex_ != nullptr)
if (tex_)
SDL_UnlockTexture(tex_);
}


Loading…
Cancel
Save