Rose
Texture.h
1 
8 #pragma once
9 
10 #include <memory>
11 #include <map>
12 #include <SDL.h>
13 #include "Types.h"
14 
15 namespace rose::gm {
16 
17  class TextureRuntimeError : public std::runtime_error {
18  public:
19  ~TextureRuntimeError() override = default;
20 
21  explicit TextureRuntimeError(const std::string &what) : std::runtime_error(what) {}
22  explicit TextureRuntimeError(const char *what) : std::runtime_error(what) {}
23  };
24 
29  public:
34  void operator()(SDL_Texture *sdlTexture) {
35  if (sdlTexture != nullptr)
36  SDL_DestroyTexture(sdlTexture);
37  }
38  };
39 
40  class Context;
41 
46  class Texture : public std::unique_ptr<SDL_Texture,TextureDestroy> {
47  public:
48  Texture() = default;
49 
50  Texture(const Texture&) = delete;
51  Texture(Texture &&) = default;
52  Texture& operator=(const Texture &) = delete;
53  Texture& operator=(Texture &&) = default;
54 
63  Texture(Context& context, SDL_PixelFormatEnum format, SDL_TextureAccess access, int width, int height);
64 
72  Texture(Context &context, Size size);
73 
74  int setBlendMode(SDL_BlendMode blendMode) {
75  return SDL_SetTextureBlendMode(get(), blendMode);
76  }
77 
78  [[nodiscard]] Size getSize() const {
79  Size size{};
80  SDL_QueryTexture(get(), nullptr, nullptr, &size.w, &size.h);
81  return size;
82  }
83 
84  int setAlphaMod(float alpha);
85  };
86 }
Definition: GraphicsModel.cpp:20
A functor to destroy an SDL_Texture in a std::unique_ptr (rose::sdl::Texture)
Definition: Texture.h:28
Definition: Texture.h:17
void operator()(SDL_Texture *sdlTexture)
Call the SDL API to destroy an SDL_Texture.
Definition: Texture.h:34
Abstraction of SDL_Texture.
Definition: Texture.h:46
Context
Definition: GraphicsModel.h:76
A size in integer dimensions.
Definition: Types.h:230