Renderer logical size is now implemented as a render target

This fixes rounding errors with coordinate scaling and gives more flexibility in the presentation, as well as making it easy to maintain device independent resolution as windows move between different pixel density displays.

By default when a renderer is created, it will match the window size so window coordinates and render coordinates are 1-1.

Mouse and touch events are no longer filtered to change their coordinates, instead you can call SDL_ConvertEventToRenderCoordinates() to explicitly map event coordinates into the rendering viewport.

SDL_RenderWindowToLogical() and SDL_RenderLogicalToWindow() have been renamed SDL_RenderCoordinatesFromWindow() and SDL_RenderCoordinatesToWindow() and take floating point coordinates in both directions.

The viewport, clipping state, and scale for render targets are now persistent and will remain set whenever they are active.
This commit is contained in:
Sam Lantinga
2023-02-03 12:25:46 -08:00
parent 93fc72a405
commit dcd17f5473
28 changed files with 1113 additions and 910 deletions

View File

@@ -45,18 +45,31 @@ typedef struct SDL_DRect
typedef struct SDL_RenderDriver SDL_RenderDriver;
/* Rendering view state */
typedef struct SDL_RenderViewState
{
int pixel_w;
int pixel_h;
SDL_Rect viewport;
SDL_Rect clip_rect;
SDL_bool clipping_enabled;
SDL_FPoint scale;
} SDL_RenderViewState;
/* Define the SDL texture structure */
struct SDL_Texture
{
const void *magic;
Uint32 format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
int modMode; /**< The texture modulation mode */
SDL_BlendMode blendMode; /**< The texture blend mode */
SDL_ScaleMode scaleMode; /**< The texture scale mode */
SDL_Color color; /**< Texture modulation values */
Uint32 format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
int modMode; /**< The texture modulation mode */
SDL_BlendMode blendMode; /**< The texture blend mode */
SDL_ScaleMode scaleMode; /**< The texture scale mode */
SDL_Color color; /**< Texture modulation values */
SDL_RenderViewState view; /**< Target texture view state */
SDL_Renderer *renderer;
@@ -212,37 +225,19 @@ struct SDL_Renderer
Uint64 simulate_vsync_interval_ns;
Uint64 last_present;
/* The logical resolution for rendering */
int logical_w;
int logical_h;
int logical_w_backup;
int logical_h_backup;
/* Support for logical output coordinates */
SDL_Texture *logical_target;
SDL_RendererLogicalPresentation logical_presentation_mode;
SDL_ScaleMode logical_scale_mode;
SDL_Rect logical_src_rect;
SDL_FRect logical_dst_rect;
/* Whether or not to force the viewport to even integer intervals */
SDL_bool integer_scale;
SDL_RenderViewState *view;
SDL_RenderViewState main_view;
/* The drawable area within the window */
SDL_DRect viewport;
SDL_DRect viewport_backup;
/* The clip rectangle within the window */
SDL_DRect clip_rect;
SDL_DRect clip_rect_backup;
/* Whether or not the clipping rectangle is used. */
SDL_bool clipping_enabled;
SDL_bool clipping_enabled_backup;
/* The render output coordinate scale */
SDL_FPoint scale;
SDL_FPoint scale_backup;
/* The pixel to point coordinate scale */
/* The window pixel to point coordinate scale */
SDL_FPoint dpi_scale;
/* Whether or not to scale relative mouse motion */
SDL_bool relative_scaling;
/* The method of drawing lines */
SDL_RenderLineMethod line_method;
@@ -264,8 +259,8 @@ struct SDL_Renderer
SDL_RenderCommand *render_commands_pool;
Uint32 render_command_generation;
Uint32 last_queued_color;
SDL_DRect last_queued_viewport;
SDL_DRect last_queued_cliprect;
SDL_Rect last_queued_viewport;
SDL_Rect last_queued_cliprect;
SDL_bool last_queued_cliprect_enabled;
SDL_bool color_queued;
SDL_bool viewport_queued;