diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index 548b3b6b..f6f3640d 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -54,25 +54,24 @@ inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, if (count) *count = 0; const int num_modes = SDL_GetNumDisplayModes(displayID); - SDL_DisplayMode** result = static_cast(SDL_malloc(sizeof(SDL_DisplayMode*) * num_modes)); - if (result) { - SDL_DisplayMode *modes = (SDL_DisplayMode *)((Uint8 *)result + ((num_modes + 1) * sizeof(*result))); - for (i = 0; i < num_modes; ++i) { - if (SDL_GetDisplayMode(displayID, i, &modes[i]) == 0) { - result[i] = modes++; - } - } - result[i] = NULL; - - if (count) { - *count = num_modes; - } + SDL_DisplayMode** result = static_cast(SDL_malloc(sizeof(SDL_DisplayMode*) * (num_modes + 1))); + SDL_DisplayMode* modes = static_cast(SDL_malloc(sizeof(SDL_DisplayMode) * num_modes)); + if (!result || !modes) { + SDL_free(result); SDL_free(modes); - } else { - if (count) { - *count = 0; - } + return NULL; + } + for (i = 0; i < num_modes; i++) { + if (SDL_GetDisplayMode(displayID, i, &modes[i]) == 0) { + result[i] = &modes[i]; + } } + result[i] = NULL; + + if (count) { + *count = num_modes; + } + return result; } @@ -142,6 +141,11 @@ inline SDL_HapticID* SDL_GetHaptics(int *count) // https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh +#define SDL_CreateWindow(title, w, h, flags) SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, flags) +#define SDL_SetWindowFullscreen(...) (SDL_SetWindowFullscreen(__VA_ARGS__) == 0) + +#define SDL_GL_MakeCurrent(...) (SDL_GL_MakeCurrent(__VA_ARGS__) == 0) + #define SDL_GetDisplayForWindow SDL_GetWindowDisplayIndex #define SDL_SetWindowFullscreenMode(...) (SDL_SetWindowDisplayMode(__VA_ARGS__) == 0) // #define SDL_GetClosestFullscreenDisplayMode SDL_GetClosestDisplayMode @@ -176,3 +180,6 @@ static void SDL_ShowCursor() { SDL_ShowCursor(SDL_ENABLE); } #define SDL_SYSTEM_CURSOR_EW_RESIZE SDL_SYSTEM_CURSOR_SIZEWE #define SDL_SYSTEM_CURSOR_PROGRESS SDL_SYSTEM_CURSOR_WAITARROW +// https://wiki.libsdl.org/SDL3/README-migration#sdl_inith + +#define SDL_Init(...) (SDL_Init(__VA_ARGS__) == 0) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h index 36443152..b439434d 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h @@ -14,7 +14,20 @@ typedef SDL_PixelFormat SDL2_PixelFormat; #define SDL_GetRGB(pixel, format, palette, r,g,b) SDL_GetRGB(pixel, format, r,g,b) #define SDL_MapRGB(format, palette, r,g,b) SDL_MapRGB(format, r,g,b) -#define SDL_GetPixelFormatDetails SDL_AllocFormat +template +SDL_PixelFormatDetails* SDL_GetPixelFormatDetails(T format) { + if constexpr (std::is_same_v) { + return SDL_AllocFormat(format); + } else { + return SDL_AllocFormat(format->format); + } +} + + +static bool operator!=(SDL_PixelFormatDetails* lhs, SDL_PixelFormatEnum rhs) +{ + return lhs->format == rhs; +} #define SDL_CreatePalette SDL_AllocPalette #define SDL_DestroyPalette SDL_FreePalette diff --git a/3rdparty/sdl3-shim/SDL3/SDL_surface.h b/3rdparty/sdl3-shim/SDL3/SDL_surface.h index eaf2241a..792eb37c 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_surface.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_surface.h @@ -4,25 +4,33 @@ #include "SDL_pixels.h" // https://wiki.libsdl.org/SDL3/README-migration#sdl_surfaceh -struct SDL_SurfaceShim : SDL_Surface { - SDL_PixelFormat format; - - explicit SDL_SurfaceShim(const SDL_Surface* s) - : SDL_Surface(*s), format(static_cast(s->format->format)) {} -}; -#define SDL_Surface SDL_SurfaceShim #define SDL_FillSurfaceRect(...) (SDL_FillRect(__VA_ARGS__) == 0) #define SDL_DestroySurface SDL_FreeSurface -#define SDL_CreateSurface(width, height, format) (SDL_Surface*)SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format) ,format) +#define SDL_LockSurface(...) (SDL_LockSurface(__VA_ARGS__) == 0) + +template +SDL_Surface* SDL_CreateSurface( int width, int height, T format) { + if constexpr (std::is_same_v) { + return SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format) ,format); + } else { + return SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format->format) ,format->format); + } +} inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat format) { - const SDL_PixelFormatDetails* formatDetails = SDL_AllocFormat(format); - return static_cast(SDL_ConvertSurface(surface, formatDetails, 0)); + SDL_PixelFormatDetails* formatDetails = SDL_AllocFormat(format); + SDL_Surface* result = SDL_ConvertSurface(surface, formatDetails, 0); + SDL_free(formatDetails); + return result; }; +inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, const SDL_PixelFormatDetails* formatDetails) +{ + return SDL_ConvertSurface(surface, formatDetails, 0); +} #define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear #define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest @@ -30,5 +38,4 @@ inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat for #define SDL_BlitSurfaceScaled(surface, rect, destSurface, destRect, scaleMode) (SDL_BlitScaled(surface, rect, destSurface, destRect) == 0) #define SDL_SetSurfaceColorKey(...) (SDL_SetColorKey(__VA_ARGS__) == 0) -#define SDL_LoadBMP_IO (SDL_Surface*)SDL_LoadBMP_RW -#define SDL_LoadBMP(file) (SDL_Surface*)SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1) //yoinked the existing SDL_LoadBMP macro so it could be cast +#define SDL_LoadBMP_IO SDL_LoadBMP_RW diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index 53d2a83c..64667f2c 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -903,14 +903,7 @@ MxResult IsleApp::SetupWindow() if (m_fullScreen) { flags |= SDL_WINDOW_FULLSCREEN; } - window = SDL_CreateWindow( - WINDOW_TITLE, - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - g_targetWidth, - g_targetHeight, - flags - ); + window = SDL_CreateWindow(WINDOW_TITLE, g_targetWidth, g_targetHeight, flags); SDL_SetWindowData(window, ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM, &m_videoParam); #endif