1#ifndef SDLSURFACEPTR_HH
2#define SDLSURFACEPTR_HH
40 Uint32 rMask, Uint32 gMask, Uint32 bMask, Uint32 aMask)
42 assert((depth % 8) == 0);
43 unsigned pitch = width * (depth >> 3);
44 unsigned size = height * pitch;
46 surface = SDL_CreateRGBSurfaceFrom(
48 narrow<int>(width), narrow<int>(height),
49 narrow<int>(depth), narrow<int>(pitch),
50 rMask, gMask, bMask, aMask);
51 if (!surface)
throw std::bad_alloc();
60 : surface(other.surface)
61 , buffer(std::move(other.buffer))
63 other.surface =
nullptr;
71 if (surface) SDL_FreeSurface(surface);
74 void reset(SDL_Surface* surface_ =
nullptr)
80 [[nodiscard]] SDL_Surface*
get()
84 [[nodiscard]]
const SDL_Surface*
get()
const
91 std::swap(surface, other.surface);
92 std::swap(buffer, other.buffer );
97 std::swap(surface, other.surface);
98 std::swap(buffer, other.buffer);
120 [[nodiscard]]
explicit operator bool()
const
122 return get() !=
nullptr;
127 assert(y <
unsigned(surface->h));
128 return static_cast<Uint8*
>(surface->pixels) + y * surface->pitch;
136 SDL_Surface* surface;
148 void operator()(SDL_Renderer* r)
const { SDL_DestroyRenderer(r); }
154 void operator()(SDL_Window* w)
const { SDL_DestroyWindow(w); }
160 void operator()(SDL_PixelFormat* p)
const { SDL_FreeFormat(p); }
171template<U
int32 FLAGS>
183 if (SDL_InitSubSystem(FLAGS) < 0) {
185 "SDL init failed (", FLAGS,
"): ", SDL_GetError());
189 SDL_QuitSubSystem(FLAGS);
std::unique_ptr< SDL_PixelFormat, SDLFreeFormat > SDLAllocFormatPtr
std::unique_ptr< SDL_Window, SDLDestroyWindow > SDLWindowPtr
std::unique_ptr< Uint8, SDLFreeWav > SDLWavPtr
std::unique_ptr< SDL_Renderer, SDLDestroyRenderer > SDLRendererPtr
std::unique_ptr< SDL_Texture, SDLDestroyTexture > SDLTexturePtr
~SDLSubSystemInitializer()
SDLSubSystemInitializer & operator=(SDLSubSystemInitializer &&)=delete
SDLSubSystemInitializer(SDLSubSystemInitializer &&)=delete
SDLSubSystemInitializer & operator=(const SDLSubSystemInitializer &)=delete
SDLSubSystemInitializer()
SDLSubSystemInitializer(const SDLSubSystemInitializer &)=delete
Wrapper around a SDL_Surface.
void reset(SDL_Surface *surface_=nullptr)
const void * getLinePtr(unsigned y) const
SDLSurfacePtr & operator=(SDLSurfacePtr &&other) noexcept
SDL_Surface & operator*()
const SDL_Surface * operator->() const
SDLSurfacePtr & operator=(const SDLSurfacePtr &)=delete
const SDL_Surface & operator*() const
SDL_Surface * operator->()
SDLSurfacePtr(SDLSurfacePtr &&other) noexcept
SDLSurfacePtr(SDL_Surface *surface_=nullptr)
SDLSurfacePtr(const SDLSurfacePtr &)=delete
SDLSurfacePtr(unsigned width, unsigned height, unsigned depth, Uint32 rMask, Uint32 gMask, Uint32 bMask, Uint32 aMask)
Create a (software) surface with uninitialized pixel content.
void swap(SDLSurfacePtr &other) noexcept
const SDL_Surface * get() const
void * getLinePtr(unsigned y)
Thrown when a subsystem initialisation fails.
This class manages the lifetime of a block of memory.
void resize(size_t size)
Grow or shrink the memory block.
const T * data() const
Returns pointer to the start of the memory buffer.
void operator()(SDL_Renderer *r) const
void operator()(SDL_Texture *t) const
void operator()(SDL_Window *w) const
void operator()(Uint8 *w) const