1 #ifndef SDLSURFACEPTR_HH
2 #define SDLSURFACEPTR_HH
42 Uint32 rMask, Uint32 gMask, Uint32 bMask, Uint32 aMask)
44 assert((depth % 8) == 0);
45 unsigned pitch = width * (depth >> 3);
46 unsigned size = height * pitch;
48 surface = SDL_CreateRGBSurfaceFrom(
49 buffer.
data(), width, height, depth, 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;
68 if (surface) SDL_FreeSurface(surface);
71 void reset(SDL_Surface* surface_ =
nullptr)
77 [[nodiscard]] SDL_Surface*
get()
81 [[nodiscard]]
const SDL_Surface*
get()
const
88 std::swap(surface, other.surface);
89 std::swap(buffer, other.buffer );
94 std::swap(surface, other.surface);
95 std::swap(buffer, other.buffer);
117 [[nodiscard]]
explicit operator bool()
const
119 return get() !=
nullptr;
124 assert(y <
unsigned(surface->h));
125 return static_cast<Uint8*
>(surface->pixels) + y * surface->pitch;
133 SDL_Surface* surface;
168 template<U
int32 FLAGS>
178 if (SDL_InitSubSystem(FLAGS) < 0) {
180 "SDL init failed (", FLAGS,
"): ", SDL_GetError());
184 SDL_QuitSubSystem(FLAGS);