11 static Arena instance;
28 SDL_Log(
"Invalid renderer passed to AllocateTexture");
32 if (width <= 0 || height <= 0) {
33 SDL_Log(
"Invalid texture dimensions: width=%d, height=%d", width, height);
37 SDL_Texture* texture =
38 SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
39 SDL_TEXTUREACCESS_STREAMING, width, height);
41 SDL_Log(
"Failed to create texture: %s", SDL_GetError());
46 std::unique_ptr<SDL_Texture, core::SDL_Texture_Deleter>(texture);
60 if (!texture || !surface) {
61 SDL_Log(
"Invalid texture or surface passed to UpdateTexture");
65 if (surface->pixels ==
nullptr) {
66 SDL_Log(
"Surface pixels are nullptr");
70 auto converted_surface =
71 std::unique_ptr<SDL_Surface, core::SDL_Surface_Deleter>(
72 SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA8888, 0),
75 if (!converted_surface) {
76 SDL_Log(
"SDL_ConvertSurfaceFormat failed: %s", SDL_GetError());
82 if (SDL_LockTexture(texture,
nullptr, &pixels, &pitch) != 0) {
83 SDL_Log(
"SDL_LockTexture failed: %s", SDL_GetError());
87 memcpy(pixels, converted_surface->pixels,
88 converted_surface->h * converted_surface->pitch);
90 SDL_UnlockTexture(texture);
95 SDL_Surface* surface =
96 SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, format);
98 SDL_Log(
"Failed to create surface: %s", SDL_GetError());
103 std::unique_ptr<SDL_Surface, core::SDL_Surface_Deleter>(surface);
108 if (!surface)
return;
SDL_Texture * AllocateTexture(SDL_Renderer *renderer, int width, int height)
SDL_Surface * AllocateSurface(int width, int height, int depth, int format)
std::array< uint16_t, kTotalTiles > layer2_buffer_
std::unordered_map< SDL_Texture *, std::unique_ptr< SDL_Texture, core::SDL_Texture_Deleter > > textures_
std::unordered_map< SDL_Surface *, std::unique_ptr< SDL_Surface, core::SDL_Surface_Deleter > > surfaces_
void FreeSurface(SDL_Surface *surface)
void FreeTexture(SDL_Texture *texture)
std::array< uint16_t, kTotalTiles > layer1_buffer_
void UpdateTexture(SDL_Texture *texture, SDL_Surface *surface)
Contains classes for handling graphical data.
Main namespace for the application.