Skip to content

Commit 96a542b

Browse files
committed
Fix SDL2 builds and most SDL_FRect hacks.
1 parent 6545b61 commit 96a542b

File tree

4 files changed

+59
-30
lines changed

4 files changed

+59
-30
lines changed

src/SDLmzx.h

+58-9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ __M_BEGIN_DECLS
3939
#endif
4040
#endif
4141

42+
#include <limits.h>
43+
4244
/* SDL1 backwards compatibility for SDL2 ************************************/
4345

4446
#if !SDL_VERSION_ATLEAST(2,0,0)
@@ -242,8 +244,8 @@ typedef SDL_GameControllerButton SDL_GamepadButton;
242244
#define SDL_GAMEPAD_BUTTON_BACK SDL_CONTROLLER_BUTTON_BACK
243245
#define SDL_GAMEPAD_BUTTON_GUIDE SDL_CONTROLLER_BUTTON_GUIDE
244246
#define SDL_GAMEPAD_BUTTON_START SDL_CONTROLLER_BUTTON_START
245-
#define SDL_GAMEPAD_BUTTON_LEFT_STICK SDL_CONTROLLER_BUTTON_LEFT_STICK
246-
#define SDL_GAMEPAD_BUTTON_RIGHT_STICK SDL_CONTROLLER_BUTTON_RIGHT_STICK
247+
#define SDL_GAMEPAD_BUTTON_LEFT_STICK SDL_CONTROLLER_BUTTON_LEFTSTICK
248+
#define SDL_GAMEPAD_BUTTON_RIGHT_STICK SDL_CONTROLLER_BUTTON_RIGHTSTICK
247249
#define SDL_GAMEPAD_BUTTON_LEFT_SHOULDER SDL_CONTROLLER_BUTTON_LEFTSHOULDER
248250
#define SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
249251
#define SDL_GAMEPAD_BUTTON_DPAD_UP SDL_CONTROLLER_BUTTON_DPAD_UP
@@ -308,23 +310,70 @@ static inline void SDL_SetJoystickEventsEnabled(SDL_bool enabled)
308310
#define SDL_DestroyPalette(p) SDL_FreePalette(p)
309311
#define SDL_CreatePixelFormat(f) SDL_AllocFormat(f)
310312
#define SDL_DestroyPixelFormat(pf) SDL_FreeFormat(pf)
311-
#define SDL_GetMasksForPixelFormatEnum(f,b,r,g,b,a) SDL_PixelFormatEnumToMasks(f,b,r,g,b,a)
313+
#define SDL_GetMasksForPixelFormatEnum(f,b,R,G,B,A) SDL_PixelFormatEnumToMasks(f,b,R,G,B,A)
314+
#endif
315+
316+
/**
317+
* SDL_rect.h
318+
*/
319+
#if SDL_VERSION_ATLEAST(2,0,0)
320+
#if !SDL_VERSION_ATLEAST(2,0,10)
321+
struct SDL_FRect
322+
{
323+
float x;
324+
float y;
325+
float w;
326+
float h;
327+
};
328+
#endif
329+
330+
#define SDL_F_TO_INT(f) \
331+
((f) >= INT_MAX) ? INT_MAX : ((f) <= INT_MIN) ? INT_MIN : (int)(f)
332+
333+
/* SDL_RenderTexture support function--convert an SDL_FRect to SDL_Rect. */
334+
static inline SDL_Rect sdl_frect_to_rect(const SDL_FRect *src)
335+
{
336+
SDL_Rect tmp =
337+
{
338+
SDL_F_TO_INT(src->x),
339+
SDL_F_TO_INT(src->y),
340+
SDL_F_TO_INT(src->w),
341+
SDL_F_TO_INT(src->h)
342+
};
343+
return tmp;
344+
}
312345
#endif
313346

314-
/* SDL_render.h */
347+
/**
348+
* SDL_render.h
349+
*/
315350
#if !SDL_VERSION_ATLEAST(3,0,0) && SDL_VERSION_ATLEAST(2,0,0)
316351
typedef int SDL_RendererLogicalPresentation;
317352
#define SDL_LOGICAL_PRESENTATION_DISABLED 0
318-
#define SDL_SCALEMODE_BEST SDL_ScaleModeBest
319-
#define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear
320-
#define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest
321-
#define SDL_SetRenderClipRect(r, rect) SDL_RenderSetClipRect(r, rect)
353+
#define SDL_SCALEMODE_BEST SDL_ScaleModeBest
354+
#define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear
355+
#define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest
356+
#define SDL_SetRenderClipRect(r, rect) SDL_RenderSetClipRect(r, rect)
357+
#define SDL_SetRenderLogicalSize(r, w, h) SDL_RenderSetLogicalSize(r, w, h)
322358

323359
static inline int SDL_SetRenderLogicalPresentation(SDL_Renderer *render,
324-
int w, int h, SDL_RendererLogicalPresentiation p, SDL_ScaleMode s)
360+
int w, int h, SDL_RendererLogicalPresentation p, SDL_ScaleMode s)
325361
{
326362
return SDL_SetRenderLogicalSize(render, w, h);
327363
}
364+
365+
static inline int SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture,
366+
const SDL_FRect *src_frect, const SDL_FRect *dest_frect)
367+
{
368+
SDL_Rect src_rect = sdl_frect_to_rect(src_frect);
369+
370+
#if SDL_VERSION_ATLEAST(2,0,10)
371+
return SDL_RenderCopyF(renderer, texture, &src_rect, dest_frect);
372+
#else
373+
SDL_Rect dest_rect = sdl_frect_to_rect(dest_frect);
374+
return SDL_RenderCopy(renderer, texture, &src_rect, &dest_rect);
375+
#endif
376+
}
328377
#endif
329378

330379
/* SDL_surface.h */

src/render_sdl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ boolean sdlrender_set_video_mode(struct graphics_data *graphics,
792792
// Flag removed in SDL3; all drivers support it and its presence needs to be
793793
// tested by trying to create a target texture instead.
794794
if(requires_blend_ops)
795-
sdl_renderer_flags |= SDL_RENDERER_TARGETTEXTURE;
795+
sdl_rendererflags |= SDL_RENDERER_TARGETTEXTURE;
796796
#endif
797797

798798
if(graphics->sdl_render_driver[0])

src/render_sdlaccel.c

-15
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,8 @@ static void sdlaccel_render_layer(struct graphics_data *graphics,
551551
SDL_Texture *chars_tex = render_data->sdl.texture[TEX_CHARS];
552552
SDL_Texture *bg_tex = render_data->sdl.texture[TEX_BACKGROUND];
553553

554-
#if SDL_VERSION_ATLEAST(3,0,0)
555554
SDL_FRect dest_bg = { offx, offy, w * CHAR_W, h * CHAR_H };
556555
SDL_FRect src_bg = { 0, 0, w, h };
557-
#else
558-
SDL_Rect dest_bg = { offx, offy, w * CHAR_W, h * CHAR_H };
559-
SDL_Rect src_bg = { 0, 0, w, h };
560-
#endif
561556
void *_bg;
562557
int bg_pitch;
563558
uint32_t *bg;
@@ -651,13 +646,8 @@ static void sdlaccel_render_layer(struct graphics_data *graphics,
651646
#else /* !RENDER_GEOMETRY */
652647
/* Render foreground and partially transparent chars. */
653648
{
654-
#if SDL_VERSION_ATLEAST(3,0,0)
655649
SDL_FRect dest_rect = { 0, 0, CHAR_W, CHAR_H };
656650
SDL_FRect src_rect = { 0, 0, CHAR_W, CHAR_H };
657-
#else
658-
SDL_Rect dest_rect = { 0, 0, CHAR_W, CHAR_H };
659-
SDL_Rect src_rect = { 0, 0, CHAR_W, CHAR_H };
660-
#endif
661651
next = layer->data;
662652
for(y = 0; y < h; y++)
663653
{
@@ -756,13 +746,8 @@ static void sdlaccel_sync_screen(struct graphics_data *graphics)
756746
struct sdlaccel_render_data *render_data = graphics->render_data;
757747
SDL_Renderer *renderer = render_data->sdl.renderer;
758748
SDL_Texture *screen_tex = render_data->sdl.texture[TEX_SCREEN];
759-
#if SDL_VERSION_ATLEAST(3,0,0)
760749
SDL_FRect src;
761750
SDL_FRect dest;
762-
#else
763-
SDL_Rect src;
764-
SDL_Rect dest;
765-
#endif
766751
int width = render_data->w;
767752
int height = render_data->h;
768753
int v_width, v_height;

src/render_softscale.c

-5
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,8 @@ static void softscale_sync_screen(struct graphics_data *graphics)
266266
SDL_Renderer *renderer = render_data->sdl.renderer;
267267
SDL_Texture *texture = render_data->sdl.texture[0];
268268
SDL_Rect *texture_rect = &(render_data->texture_rect);
269-
#if SDL_VERSION_ATLEAST(3,0,0)
270269
SDL_FRect src_rect;
271270
SDL_FRect dest_rect;
272-
#else
273-
SDL_Rect src_rect;
274-
SDL_Rect dest_rect;
275-
#endif
276271
int width = render_data->w;
277272
int height = render_data->h;
278273
int v_width, v_height;

0 commit comments

Comments
 (0)