SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::RendererBase Struct Reference

A structure representing rendering state. More...

Inheritance diagram for SDL::RendererBase:
Inheritance graph
[legend]

Public Member Functions

 RendererBase (WindowRef window)
 Create a 2D rendering context for a window.
 
 RendererBase (WindowBase &window, StringParam name)
 Create a 2D rendering context for a window.
 
 RendererBase (PropertiesBase &props)
 Create a 2D rendering context for a window, with the specified properties.
 
 RendererBase (SurfaceBase &surface)
 Create a 2D software rendering context for a surface.
 
WindowRef GetWindow ()
 Get the window associated with a renderer.
 
const char * GetName () const
 Get the name of a renderer.
 
Point GetOutputSize () const
 Get the output size in pixels of a rendering context.
 
void GetOutputSize (int *w, int *h) const
 Get the output size in pixels of a rendering context.
 
Point GetCurrentOutputSize () const
 Get the current output size in pixels of a rendering context.
 
void GetCurrentOutputSize (int *w, int *h) const
 Get the current output size in pixels of a rendering context.
 
PropertiesRef GetProperties () const
 Get the properties associated with a renderer.
 
void ResetTarget ()
 Set target texture back to window.
 
void SetTarget (OptionalTexture texture)
 Set a texture as the current rendering target.
 
TextureRef GetTarget () const
 Get the current render target.
 
void SetLogicalPresentation (SDL_Point size, RendererLogicalPresentation mode)
 Set a device-independent resolution and presentation mode for rendering.
 
void GetLogicalPresentation (SDL_Point *size, RendererLogicalPresentation *mode)
 Get device independent resolution and presentation mode for rendering.
 
void GetLogicalPresentation (int *w, int *h, RendererLogicalPresentation *mode) const
 Get device independent resolution and presentation mode for rendering.
 
FRect GetLogicalPresentationRect () const
 Get the final presentation rectangle for rendering.
 
FPoint RenderCoordinatesFromWindow (const SDL_FPoint &window_coord) const
 Get a point in render coordinates when given a point in window coordinates.
 
FPoint RenderCoordinatesToWindow (const SDL_FPoint &coord) const
 Get a point in window coordinates when given a point in render coordinates.
 
void ConvertEventToRenderCoordinates (Event *event) const
 Convert the coordinates in an event to render coordinates.
 
void ResetViewport ()
 Reset the drawing area for rendering to the entire target.
 
void SetViewport (OptionalRef< const SDL_Rect > rect)
 Set the drawing area for rendering on the current target.
 
Rect GetViewport () const
 Get the drawing area for the current target.
 
bool IsViewportSet () const
 Return whether an explicit rectangle was set as the viewport.
 
Rect GetSafeArea () const
 Get the safe area for rendering within the current viewport.
 
void ResetClipRect ()
 Reset the clip rectangle for rendering to the entire render target.
 
void SetClipRect (OptionalRef< const SDL_Rect > rect)
 Set the clip rectangle for rendering on the specified target.
 
Rect GetClipRect () const
 Get the clip rectangle for the current target.
 
bool IsClipEnabled () const
 Get whether clipping is enabled on the given render target.
 
void SetScale (SDL_FPoint scale)
 Set the drawing scale for rendering on the current target.
 
FPoint GetScale () const
 Get the drawing scale for the current target.
 
void GetScale (float *scaleX, float *scaleY) const
 Get the drawing scale for the current target.
 
void SetDrawColor (SDL_Color c)
 Set the color used for drawing operations.
 
void SetDrawColor (SDL_FColor c)
 Set the color used for drawing operations (Rect, Line and Clear).
 
FColor GetDrawColor () const
 Get the color used for drawing operations (Rect, Line and Clear).
 
void GetDrawColor (SDL_Color *c) const
 Get the color used for drawing operations (Rect, Line and Clear).
 
void GetDrawColor (SDL_FColor *c) const
 Get the color used for drawing operations (Rect, Line and Clear).
 
void GetDrawColor (Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const
 Get the color used for drawing operations (Rect, Line and Clear).
 
void GetDrawColor (float *r, float *g, float *b, float *a) const
 Get the color used for drawing operations (Rect, Line and Clear).
 
void SetColorScale (float scale)
 Set the color scale used for render operations.
 
float GetColorScale () const
 Get the color scale used for render operations.
 
void SetDrawBlendMode (BlendMode blendMode)
 Set the blend mode used for drawing operations (Fill and Line).
 
BlendMode GetDrawBlendMode () const
 Get the blend mode used for drawing operations.
 
void RenderClear ()
 Clear the current rendering target with the drawing color.
 
void RenderPoint (SDL_FPoint p)
 Draw a point on the current rendering target at subpixel precision.
 
void RenderPoints (SpanRef< const SDL_FPoint > points)
 Draw multiple points on the current rendering target at subpixel precision.
 
void RenderLine (SDL_FPoint p1, SDL_FPoint p2)
 Draw a line on the current rendering target at subpixel precision.
 
void RenderLines (SpanRef< const SDL_FPoint > points)
 Draw a series of connected lines on the current rendering target at subpixel precision.
 
void RenderRect (OptionalRef< const SDL_FRect > rect)
 Draw a rectangle on the current rendering target at subpixel precision.
 
void RenderRects (SpanRef< const SDL_FRect > rects)
 Draw some number of rectangles on the current rendering target at subpixel precision.
 
void RenderFillRect (OptionalRef< const SDL_FRect > rect)
 Fill a rectangle on the current rendering target with the drawing color at subpixel precision.
 
void RenderFillRects (SpanRef< const SDL_FRect > rects)
 Fill some number of rectangles on the current rendering target with the drawing color at subpixel precision.
 
void RenderTexture (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FRect > dstrect)
 Copy a portion of the texture to the current rendering target at subpixel precision.
 
void RenderTextureRotated (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FRect > dstrect, double angle, OptionalRef< const SDL_FPoint > center={}, FlipMode flip=SDL_FLIP_NONE)
 Copy a portion of the source texture to the current rendering target, with rotation and flipping, at subpixel precision.
 
void RenderTextureAffine (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FPoint > origin, OptionalRef< const SDL_FPoint > right, OptionalRef< const SDL_FPoint > down)
 Copy a portion of the source texture to the current rendering target, with affine transform, at subpixel precision.
 
void RenderTextureTiled (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, float scale, OptionalRef< const SDL_FRect > dstrect)
 Tile a portion of the texture to the current rendering target at subpixel precision.
 
void RenderTexture9Grid (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, OptionalRef< const SDL_FRect > dstrect)
 Perform a scaled copy using the 9-grid algorithm to the current rendering target at subpixel precision.
 
void RenderGeometry (OptionalTexture texture, std::span< const Vertex > vertices, std::span< const int > indices={})
 Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (TextureBase.SetColorMod and TextureBase.SetAlphaMod are ignored).
 
void RenderGeometryRaw (OptionalTexture texture, const float *xy, int xy_stride, const FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices)
 Render a list of triangles, optionally using a texture and indices into the vertex arrays Color and alpha modulation is done per vertex (TextureBase.SetColorMod and TextureBase.SetAlphaMod are ignored).
 
Surface ReadPixels (OptionalRef< const SDL_Rect > rect={}) const
 Read pixels from the current rendering target.
 
void Present ()
 Update the screen with any rendering performed since the previous call.
 
void Flush ()
 Force the rendering context to flush any pending commands and state.
 
void SetVSync (int vsync)
 Toggle VSync of the given renderer.
 
int GetVSync () const
 Get VSync of the given renderer.
 
void RenderDebugText (FPoint p, StringParam str)
 Draw debug text to an RendererBase.
 
template<class... ARGS>
void RenderDebugTextFormat (FPoint p, std::string_view fmt, ARGS... args)
 Draw debug text to an SDL_Renderer.
 
constexpr Resource (T resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
- Public Member Functions inherited from SDL::Resource< SDL_Renderer * >
constexpr Resource (SDL_Renderer * resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other)=delete
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr bool operator== (const Resource &other) const=default
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr SDL_Renderer * get () const
 Return contained resource;.
 
constexpr SDL_Renderer * release (SDL_Renderer * newResource={})
 Return contained resource and empties or replace value.
 
constexpr const SDL_Renderer * operator-> () const
 Access to fields.
 
constexpr SDL_Renderer * operator-> ()
 Access to fields.
 

Detailed Description

Since
This struct is available since SDL 3.2.0.
Category:
Resource
See also
Renderer
RendererRef

Constructor & Destructor Documentation

◆ RendererBase() [1/4]

SDL::RendererBase::RendererBase ( WindowRef  window)
inline

By default the rendering size matches the window size in pixels, but you can call SDL_SetRenderLogicalPresentation() to change the content size and scaling options.

It renderer creation fails for any reason this object is falsy; call GetError() for more information.

Parameters
windowthe window where rendering is displayed.
Thread safety:
This function should only be called on the main thread.

◆ RendererBase() [2/4]

SDL::RendererBase::RendererBase ( WindowBase window,
StringParam  name 
)
inline

If you want a specific renderer, you can specify its name here. A list of available renderers can be obtained by calling GetRenderDriver() multiple times, with indices from 0 to GetNumRenderDrivers()-1. If you don't need a specific renderer, specify nullptr and SDL will attempt to choose the best option for you, based on what is available on the user's system.

If name is a comma-separated list, SDL will try each name, in the order listed, until one succeeds or all of them fail.

By default the rendering size matches the window size in pixels, but you can call RendererBase.SetLogicalPresentation() to change the content size and scaling options.

It renderer creation fails for any reason this object is falsy; call GetError() for more information.

Parameters
windowthe window where rendering is displayed.
namethe name of the rendering driver to initialize, or nullptr to let SDL choose one.
Postcondition
a valid rendering context.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetNumRenderDrivers
GetRenderDriver
RendererBase.GetName

◆ RendererBase() [3/4]

SDL::RendererBase::RendererBase ( PropertiesBase props)
inline

These are the supported properties:

  • prop::Renderer.CREATE_NAME_STRING: the name of the rendering driver to use, if a specific one is desired
  • prop::Renderer.CREATE_WINDOW_POINTER: the window where rendering is displayed, required if this isn't a software renderer using a surface
  • prop::Renderer.CREATE_SURFACE_POINTER: the surface where rendering is displayed, if you want a software renderer without a window
  • prop::Renderer.CREATE_OUTPUT_COLORSPACE_NUMBER: an Colorspace value describing the colorspace for output to the display, defaults to COLORSPACE_SRGB. The direct3d11, direct3d12, and metal renderers support COLORSPACE_SRGB_LINEAR, which is a linear color space and supports HDR output. If you select COLORSPACE_SRGB_LINEAR, drawing still uses the sRGB colorspace, but values can go beyond 1.0 and float (linear) format textures can be used for HDR content.
  • prop::Renderer.CREATE_PRESENT_VSYNC_NUMBER: non-zero if you want present synchronized with the refresh rate. This property can take any value that is supported by RendererBase.SetVSync() for the renderer.

With the vulkan renderer:

  • prop::Renderer.CREATE_VULKAN_INSTANCE_POINTER: the VkInstance to use with the renderer, optional.
  • prop::Renderer.CREATE_VULKAN_SURFACE_NUMBER: the VkSurfaceKHR to use with the renderer, optional.
  • prop::Renderer.CREATE_VULKAN_PHYSICAL_DEVICE_POINTER: the VkPhysicalDevice to use with the renderer, optional.
  • prop::Renderer.CREATE_VULKAN_DEVICE_POINTER: the VkDevice to use with the renderer, optional.
  • prop::Renderer.CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER: the queue family index used for rendering.
  • prop::Renderer.CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER: the queue family index used for presentation.

It renderer creation fails for any reason this object is falsy; call GetError() for more information.

Parameters
propsthe properties to use.
Postcondition
a valid rendering context.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Properties.Properties
RendererBase.GetName

◆ RendererBase() [4/4]

SDL::RendererBase::RendererBase ( SurfaceBase surface)
inline

Two other API which can be used to create RendererBase: RendererBase.RendererBase() and CreateWindowAndRenderer(). These can also create a software renderer, but they are intended to be used with an WindowBase as the final destination and not an SurfaceBase.

Parameters
surfacethe Surface structure representing the surface where rendering is done.
Postcondition
a valid rendering context.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

Member Function Documentation

◆ ConvertEventToRenderCoordinates()

void SDL::RendererBase::ConvertEventToRenderCoordinates ( Event event) const
inline

This takes into account several states:

Various event types are converted with this function: mouse, touch, pen, etc.

Touch coordinates are converted from normalized coordinates in the window to non-normalized rendering coordinates.

Relative mouse coordinates (xrel and yrel event fields) are also converted. Applications that do not want these fields converted should use RendererBase.RenderCoordinatesFromWindow() on the specific event fields instead of converting the entire event structure.

Once converted, coordinates may be outside the rendering area.

Parameters
eventthe event to modify.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderCoordinatesFromWindow

◆ Flush()

void SDL::RendererBase::Flush ( )
inline

You do not need to (and in fact, shouldn't) call this function unless you are planning to call into OpenGL/Direct3D/Metal/whatever directly, in addition to using an RendererBase.

This is for a very-specific case: if you are using SDL's render API, and you plan to make OpenGL/D3D/whatever calls in addition to SDL render API calls. If this applies, you should call this function between calls to SDL's render API and the low-level API you're using in cooperation.

In all other cases, you can ignore this function.

This call makes SDL flush any pending rendering work it was queueing up to do later in a single batch, and marks any internal cached state as invalid, so it'll prepare all its state again later, from scratch.

This means you do not need to save state in your rendering code to protect the SDL renderer. However, there lots of arbitrary pieces of Direct3D and OpenGL state that can confuse things; you should use your best judgment and be prepared to make changes if specific state needs to be protected.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetClipRect()

Rect SDL::RendererBase::GetClipRect ( ) const
inline

Each render target has its own clip rectangle. This function gets the cliprect for the current render target.

Returns
an Rect structure with the current clipping area or an empty rectangle if clipping is disabled.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.IsClipEnabled
RendererBase.SetClipRect

◆ GetColorScale()

float SDL::RendererBase::GetColorScale ( ) const
inline
Returns
a float representing the current color scale on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetColorScale

◆ GetCurrentOutputSize() [1/2]

Point SDL::RendererBase::GetCurrentOutputSize ( ) const
inline

If a rendering target is active, this will return the size of the rendering target in pixels, otherwise if a logical size is set, it will return the logical size, otherwise it will return the value of GetOutputSize().

Returns
the size on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetOutputSize()

◆ GetCurrentOutputSize() [2/2]

void SDL::RendererBase::GetCurrentOutputSize ( int *  w,
int *  h 
) const
inline

If a rendering target is active, this will return the size of the rendering target in pixels, otherwise return the value of RendererBase.GetOutputSize().

Rendering target or not, the output will be adjusted by the current logical presentation state, dictated by RendererBase.SetLogicalPresentation().

Parameters
wa pointer filled in with the current width.
ha pointer filled in with the current height.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetOutputSize

◆ GetDrawBlendMode()

BlendMode SDL::RendererBase::GetDrawBlendMode ( ) const
inline
Returns
the current BlendMode on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetDrawBlendMode

◆ GetDrawColor() [1/5]

FColor SDL::RendererBase::GetDrawColor ( ) const
inline
Returns
the color on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetDrawColor(SDL_FColor*)
SetDrawColor()

◆ GetDrawColor() [2/5]

void SDL::RendererBase::GetDrawColor ( float *  r,
float *  g,
float *  b,
float *  a 
) const
inline
Parameters
ra pointer filled in with the red value used to draw on the rendering target.
ga pointer filled in with the green value used to draw on the rendering target.
ba pointer filled in with the blue value used to draw on the rendering target.
aa pointer filled in with the alpha value used to draw on the rendering target.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetDrawColor

◆ GetDrawColor() [3/5]

void SDL::RendererBase::GetDrawColor ( SDL_Color *  c) const
inline
Parameters
ca pointer filled in with the color channel values used to draw on the rendering target. must not be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetDrawColor(SDL_FColor*)
SetDrawColor()

◆ GetDrawColor() [4/5]

void SDL::RendererBase::GetDrawColor ( SDL_FColor *  c) const
inline
Parameters
ca pointer filled in with the color channel values used to draw on the rendering target. must not be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetDrawColor(SDL_Color*)
SetDrawColor()

◆ GetDrawColor() [5/5]

void SDL::RendererBase::GetDrawColor ( Uint8 *  r,
Uint8 *  g,
Uint8 *  b,
Uint8 *  a 
) const
inline
Parameters
ra pointer filled in with the red value used to draw on the rendering target.
ga pointer filled in with the green value used to draw on the rendering target.
ba pointer filled in with the blue value used to draw on the rendering target.
aa pointer filled in with the alpha value used to draw on the rendering target; usually SDL_ALPHA_OPAQUE (255).
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetDrawColor

◆ GetLogicalPresentation() [1/2]

void SDL::RendererBase::GetLogicalPresentation ( int *  w,
int *  h,
RendererLogicalPresentation mode 
) const
inline

This function gets the width and height of the logical rendering output, or the output size in pixels if a logical resolution is not enabled.

Each render target has its own logical presentation state. This function gets the state for the current render target.

Parameters
wan int to be filled with the width.
han int to be filled with the height.
modethe presentation mode used.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetLogicalPresentation

◆ GetLogicalPresentation() [2/2]

void SDL::RendererBase::GetLogicalPresentation ( SDL_Point *  size,
RendererLogicalPresentation mode 
)
inline

This function gets the width and height of the logical rendering output, or the output size in pixels if a logical resolution is not enabled.

Parameters
sizea Point to be filled with the width and height.
modethe presentation mode used.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetLogicalPresentation

◆ GetLogicalPresentationRect()

FRect SDL::RendererBase::GetLogicalPresentationRect ( ) const
inline

This function returns the calculated rectangle used for logical presentation, based on the presentation mode and output size. If logical presentation is disabled, it will fill the rectangle with the output size, in pixels.

Each render target has its own logical presentation state. This function gets the rectangle for the current render target.

Returns
the rect with the final presentation rectangle on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetLogicalPresentation

◆ GetName()

const char * SDL::RendererBase::GetName ( ) const
inline
Returns
the name of the selected renderer.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetOutputSize() [1/2]

Point SDL::RendererBase::GetOutputSize ( ) const
inline

This returns the true output size in pixels, ignoring any render targets or logical size and presentation.

Returns
Point on success or std::nullopt on failure; call GetError() for more information.

◆ GetOutputSize() [2/2]

void SDL::RendererBase::GetOutputSize ( int *  w,
int *  h 
) const
inline

This returns the true output size in pixels, ignoring any render targets or logical size and presentation.

For the output size of the current rendering target, with logical size adjustments, use RendererBase.GetCurrentOutputSize() instead.

Parameters
wa pointer filled in with the width in pixels.
ha pointer filled in with the height in pixels.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetCurrentOutputSize

◆ GetProperties()

PropertiesRef SDL::RendererBase::GetProperties ( ) const
inline

The following read-only properties are provided by SDL:

  • prop::Renderer.NAME_STRING: the name of the rendering driver
  • prop::Renderer.WINDOW_POINTER: the window where rendering is displayed, if any
  • prop::Renderer.SURFACE_POINTER: the surface where rendering is displayed, if this is a software renderer without a window
  • prop::Renderer.VSYNC_NUMBER: the current vsync setting
  • prop::Renderer.MAX_TEXTURE_SIZE_NUMBER: the maximum texture width and height
  • prop::Renderer.TEXTURE_FORMATS_POINTER: a (const PixelFormat *) array of pixel formats, terminated with PIXELFORMAT_UNKNOWN, representing the available texture formats for this renderer.
  • prop::Renderer.OUTPUT_COLORSPACE_NUMBER: an Colorspace value describing the colorspace for output to the display, defaults to COLORSPACE_SRGB.
  • prop::Renderer.HDR_ENABLED_BOOLEAN: true if the output colorspace is COLORSPACE_SRGB_LINEAR and the renderer is showing on a display with HDR enabled. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.
  • prop::Renderer.SDR_WHITE_POINT_FLOAT: the value of SDR white in the COLORSPACE_SRGB_LINEAR colorspace. When HDR is enabled, this value is automatically multiplied into the color scale. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.
  • prop::Renderer.HDR_HEADROOM_FLOAT: the additional high dynamic range that can be displayed, in terms of the SDR white point. When HDR is not enabled, this will be 1.0. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.

With the direct3d renderer:

  • prop::Renderer.D3D9_DEVICE_POINTER: the IDirect3DDevice9 associated with the renderer

With the direct3d11 renderer:

  • prop::Renderer.D3D11_DEVICE_POINTER: the ID3D11Device associated with the renderer
  • prop::Renderer.D3D11_SWAPCHAIN_POINTER: the IDXGISwapChain1 associated with the renderer. This may change when the window is resized.

With the direct3d12 renderer:

  • prop::Renderer.D3D12_DEVICE_POINTER: the ID3D12Device associated with the renderer
  • prop::Renderer.D3D12_SWAPCHAIN_POINTER: the IDXGISwapChain4 associated with the renderer.
  • prop::Renderer.D3D12_COMMAND_QUEUE_POINTER: the ID3D12CommandQueue associated with the renderer

With the vulkan renderer:

  • prop::Renderer.VULKAN_INSTANCE_POINTER: the VkInstance associated with the renderer
  • prop::Renderer.VULKAN_SURFACE_NUMBER: the VkSurfaceKHR associated with the renderer
  • prop::Renderer.VULKAN_PHYSICAL_DEVICE_POINTER: the VkPhysicalDevice associated with the renderer
  • prop::Renderer.VULKAN_DEVICE_POINTER: the VkDevice associated with the renderer
  • prop::Renderer.VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER: the queue family index used for rendering
  • prop::Renderer.VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER: the queue family index used for presentation
  • prop::Renderer.VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER: the number of swapchain images, or potential frames in flight, used by the Vulkan renderer

With the gpu renderer:

  • prop::Renderer.GPU_DEVICE_POINTER: the SDL_GPUDevice associated with the renderer
Returns
a valid property ID on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetSafeArea()

Rect SDL::RendererBase::GetSafeArea ( ) const
inline

Some devices have portions of the screen which are partially obscured or not interactive, possibly due to on-screen controls, curved edges, camera notches, TV overscan, etc. This function provides the area of the current viewport which is safe to have interactible content. You should continue rendering into the rest of the render target, but it should not contain visually important or interactible content.

Returns
the rect filled the area that is safe for interactive content.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetScale() [1/2]

FPoint SDL::RendererBase::GetScale ( ) const
inline

Each render target has its own scale. This function gets the scale for the current render target.

Returns
the scaling factors on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetScale

◆ GetScale() [2/2]

void SDL::RendererBase::GetScale ( float *  scaleX,
float *  scaleY 
) const
inline

Each render target has its own scale. This function gets the scale for the current render target.

Parameters
scaleXa pointer filled in with the horizontal scaling factor.
scaleYa pointer filled in with the vertical scaling factor.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetScale

◆ GetViewport()

Rect SDL::RendererBase::GetViewport ( ) const
inline

Each render target has its own viewport. This function gets the viewport for the current render target.

Returns
an Rect with the current drawing area.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.IsViewportSet
RendererBase.SetViewport

◆ GetVSync()

int SDL::RendererBase::GetVSync ( ) const
inline
Returns
the current vertical refresh sync interval on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetVSync

◆ GetWindow()

WindowRef SDL::RendererBase::GetWindow ( )
inline
Returns
the window on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ IsClipEnabled()

bool SDL::RendererBase::IsClipEnabled ( ) const
inline

Each render target has its own clip rectangle. This function checks the cliprect for the current render target.

Returns
true if clipping is enabled or false if not; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetClipRect
RendererBase.SetClipRect

◆ IsViewportSet()

bool SDL::RendererBase::IsViewportSet ( ) const
inline

This is useful if you're saving and restoring the viewport and want to know whether you should restore a specific rectangle or nullptr.

Each render target has its own viewport. This function checks the viewport for the current render target.

Returns
true if the viewport was set to a specific rectangle, or false if it was set to nullptr (the entire target).
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetViewport
RendererBase.SetViewport

◆ Present()

void SDL::RendererBase::Present ( )
inline

SDL's rendering functions operate on a backbuffer; that is, calling a rendering function such as RendererBase.RenderLine() does not directly put a line on the screen, but rather updates the backbuffer. As such, you compose your entire scene and present the composed backbuffer to the screen as a complete picture.

Therefore, when using SDL's rendering API, one does all drawing intended for the frame, and then calls this function once per frame to present the final drawing to the user.

The backbuffer should be considered invalidated after each present; do not assume that previous contents will exist between frames. You are strongly encouraged to call RendererBase.RenderClear() to initialize the backbuffer before starting each new frame's drawing, even if you plan to overwrite every pixel.

Please note, that in case of rendering to a texture - there is no need to call RendererBase.Present after drawing needed objects to a texture, and should not be done; you are only required to change back the rendering target to default via RendererBase.SetTarget(renderer, nullptr) afterwards, as textures by themselves do not have a concept of backbuffers. Calling RendererBase.Present while rendering to a texture will still update the screen with any current drawing that has been done to the window itself.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RendererBase
RendererBase.RenderClear
RendererBase.RenderFillRect
RendererBase.RenderFillRects
RendererBase.RenderLine
RendererBase.RenderLines
RendererBase.RenderPoint
RendererBase.RenderPoints
RendererBase.RenderRect
RendererBase.RenderRects
RendererBase.SetDrawBlendMode
RendererBase.SetDrawColor

◆ ReadPixels()

Surface SDL::RendererBase::ReadPixels ( OptionalRef< const SDL_Rect >  rect = {}) const
inline

The returned surface contains pixels inside the desired area clipped to the current viewport, and should be freed with SurfaceRef.reset().

Note that this returns the actual pixels on the screen, so if you are using logical presentation you should use RendererBase.GetLogicalPresentationRect() to get the area containing your content.

WARNING: This is a very slow operation, and should not be used frequently. If you're using this on the main rendering target, it should be called after rendering and before RendererBase.Present().

Parameters
rectan Rect structure representing the area to read, which will be clipped to the current viewport, or nullptr for the entire viewport.
Returns
a new Surface on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ RenderClear()

void SDL::RendererBase::RenderClear ( )
inline

This function clears the entire rendering target, ignoring the viewport and the clip rectangle. Note, that clearing will also set/fill all pixels of the rendering target to current renderer draw color, so make sure to invoke RendererBase.SetDrawColor() when needed.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetDrawColor

◆ RenderCoordinatesFromWindow()

FPoint SDL::RendererBase::RenderCoordinatesFromWindow ( const SDL_FPoint &  window_coord) const
inline

This takes into account several states:

Parameters
window_coordthe x, y coordinate in window coordinates.
Returns
a FPoint containing ther render coordinates on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetLogicalPresentation
RendererBase.SetScale

◆ RenderCoordinatesToWindow()

FPoint SDL::RendererBase::RenderCoordinatesToWindow ( const SDL_FPoint &  coord) const
inline

This takes into account several states:

Parameters
coordthe x, y coordinate in render coordinates.
Returns
a FPoint filled with window coordinates on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.SetLogicalPresentation
RendererBase.SetScale
RendererBase.SetViewport

◆ RenderDebugText()

void SDL::RendererBase::RenderDebugText ( FPoint  p,
StringParam  str 
)
inline

This function will render a string of text to an RendererBase. Note that this is a convenience function for debugging, with severe limitations, and not intended to be used for production apps and games.

Among these limitations:

  • It accepts UTF-8 strings, but will only renders ASCII characters.
  • It has a single, tiny size (8x8 pixels). One can use logical presentation or scaling to adjust it, but it will be blurry.
  • It uses a simple, hardcoded bitmap font. It does not allow different font selections and it does not support truetype, for proper scaling.
  • It does no word-wrapping and does not treat newline characters as a line break. If the text goes out of the window, it's gone.

For serious text rendering, there are several good options, such as SDL_ttf, stb_truetype, or other external libraries.

On first use, this will create an internal texture for rendering glyphs. This texture will live until the renderer is destroyed.

The text is drawn in the color specified by RendererBase.SetDrawColor().

Parameters
pthe x, y coordinates where the top-left corner of the text will draw.
strthe string to render.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE

◆ RenderDebugTextFormat()

template<class... ARGS>
void SDL::RendererBase::RenderDebugTextFormat ( FPoint  p,
std::string_view  fmt,
ARGS...  args 
)
inline

This function will render a std::format()-style format string to a renderer. Note that this is a convenience function for debugging, with severe limitations, and is not intended to be used for production apps and games.

For the full list of limitations and other useful information, see SDL_RenderDebugText.

Parameters
pthe x, y coordinates where the top-left corner of the text will draw.
fmtthe format string to draw.
argsadditional parameters matching {} tokens in the fmt string, if any.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RenderDebugText()
SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE

◆ RenderFillRect()

void SDL::RendererBase::RenderFillRect ( OptionalRef< const SDL_FRect >  rect)
inline
Parameters
recta pointer to the destination rectangle, or std::nullopt for the entire rendering target.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderFillRects

◆ RenderFillRects()

void SDL::RendererBase::RenderFillRects ( SpanRef< const SDL_FRect >  rects)
inline
Parameters
rectsa pointer to an array of destination rectangles.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderFillRect

◆ RenderLine()

void SDL::RendererBase::RenderLine ( SDL_FPoint  p1,
SDL_FPoint  p2 
)
inline
Parameters
p1the x,y coordinate of the start point.
p2the x,y coordinate of the end point.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderLines

◆ RenderLines()

void SDL::RendererBase::RenderLines ( SpanRef< const SDL_FPoint >  points)
inline
Parameters
pointsthe points along the lines.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderLine

◆ RenderPoint()

void SDL::RendererBase::RenderPoint ( SDL_FPoint  p)
inline
Parameters
pthe x, y coordinates of the point.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderPoints

◆ RenderPoints()

void SDL::RendererBase::RenderPoints ( SpanRef< const SDL_FPoint >  points)
inline
Parameters
pointsthe points to draw.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderPoint

◆ RenderRect()

void SDL::RendererBase::RenderRect ( OptionalRef< const SDL_FRect >  rect)
inline
Parameters
recta pointer to the destination rectangle, or std::nullopt to outline the entire rendering target.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderRects

◆ RenderRects()

void SDL::RendererBase::RenderRects ( SpanRef< const SDL_FRect >  rects)
inline
Parameters
rectsa pointer to an array of destination rectangles.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.RenderRect

◆ ResetClipRect()

void SDL::RendererBase::ResetClipRect ( )
inline

This is equivalent to SetClipRect(std::nullopt)

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetClipRect()
SetClipRect()
ClipEnabled()

◆ ResetViewport()

void SDL::RendererBase::ResetViewport ( )
inline

This is equivalent to SetViewport(std::nullopt)

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetViewport()
SetViewport()
ViewportSet()

◆ SetClipRect()

void SDL::RendererBase::SetClipRect ( OptionalRef< const SDL_Rect >  rect)
inline

Each render target has its own clip rectangle. This function sets the cliprect for the current render target.

Parameters
rectan Rect structure representing the clip area, relative to the viewport, or nullptr to disable clipping.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetClipRect
RendererBase.ResetClipRect()
RendererBase.IsClipEnabled

◆ SetColorScale()

void SDL::RendererBase::SetColorScale ( float  scale)
inline

The color scale is an additional scale multiplied into the pixel color value while rendering. This can be used to adjust the brightness of colors during HDR rendering, or changing HDR video brightness when playing on an SDR display.

The color scale does not affect the alpha channel, only the color brightness.

Parameters
scalethe color scale value.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetColorScale

◆ SetDrawBlendMode()

void SDL::RendererBase::SetDrawBlendMode ( BlendMode  blendMode)
inline

If the blend mode is not supported, the closest supported mode is chosen.

Parameters
blendModethe BlendMode to use for blending.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetDrawBlendMode

◆ SetDrawColor() [1/2]

void SDL::RendererBase::SetDrawColor ( SDL_Color  c)
inline

Set the color for drawing or filling rectangles, lines, and points, and for RendererBase.RenderClear().

Parameters
cthe color value used to draw on the rendering target.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetDrawColor

◆ SetDrawColor() [2/2]

void SDL::RendererBase::SetDrawColor ( SDL_FColor  c)
inline

Set the color for drawing or filling rectangles, lines, and points, and for RendererBase.RenderClear().

Parameters
cthe RGBA values used to draw on the rendering target.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetDrawColor

◆ SetLogicalPresentation()

void SDL::RendererBase::SetLogicalPresentation ( SDL_Point  size,
RendererLogicalPresentation  mode 
)
inline

This function sets the width and height of the logical rendering output. The renderer will act as if the current render target is always the requested dimensions, scaling to the actual resolution as necessary.

This can be useful for games that expect a fixed size, but would like to scale the output to whatever is available, regardless of how a user resizes a window, or if the display is high DPI.

Logical presentation can be used with both render target textures and the renderer's window; the state is unique to each render target, and this function sets the state for the current render target. It might be useful to draw to a texture that matches the window dimensions with logical presentation enabled, and then draw that texture across the entire window with logical presentation disabled. Be careful not to render both with logical presentation enabled, however, as this could produce double-letterboxing, etc.

You can disable logical coordinates by setting the mode to LOGICAL_PRESENTATION_DISABLED, and in that case you get the full pixel resolution of the render target; it is safe to toggle logical presentation during the rendering of a frame: perhaps most of the rendering is done to specific dimensions but to make fonts look sharp, the app turns off logical presentation while drawing text, for example.

For the renderer's window, letterboxing is drawn into the framebuffer if logical presentation is enabled during RendererBase.Present; be sure to reenable it before presenting if you were toggling it, otherwise the letterbox areas might have artifacts from previous frames (or artifacts from external overlays, etc). Letterboxing is never drawn into texture render targets; be sure to call RendererBase.RenderClear() before drawing into the texture so the letterboxing areas are cleared, if appropriate.

You can convert coordinates in an event into rendering coordinates using RendererBase.ConvertEventToRenderCoordinates().

Parameters
sizethe width and height of the logical resolution.
modethe presentation mode used.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.ConvertEventToRenderCoordinates
RendererBase.GetLogicalPresentation
RendererBase.GetLogicalPresentationRect

◆ SetScale()

void SDL::RendererBase::SetScale ( SDL_FPoint  scale)
inline

The drawing coordinates are scaled by the x/y scaling factors before they are used by the renderer. This allows resolution independent drawing with a single coordinate system.

If this results in scaling or subpixel drawing by the rendering backend, it will be handled using the appropriate quality hints. For best results use integer scaling factors.

Each render target has its own scale. This function sets the scale for the current render target.

Parameters
scalethe x, y scaling factors.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetScale

◆ SetViewport()

void SDL::RendererBase::SetViewport ( OptionalRef< const SDL_Rect >  rect)
inline

Drawing will clip to this area (separately from any clipping done with RendererBase.SetClipRect), and the top left of the area will become coordinate (0, 0) for future drawing commands.

The area's width and height must be >= 0.

Each render target has its own viewport. This function sets the viewport for the current render target.

Parameters
rectthe Rect structure representing the drawing area, or nullptr to set the viewport to the entire target.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetViewport
RendererBase.IsViewportSet

◆ SetVSync()

void SDL::RendererBase::SetVSync ( int  vsync)
inline

When a renderer is created, vsync defaults to SDL_RENDERER_VSYNC_DISABLED.

The vsync parameter can be 1 to synchronize present with every vertical refresh, 2 to synchronize present with every second vertical refresh, etc., SDL_RENDERER_VSYNC_ADAPTIVE for late swap tearing (adaptive vsync), or SDL_RENDERER_VSYNC_DISABLED to disable. Not every value is supported by every driver, so you should check the return value to see whether the requested setting is supported.

Parameters
vsyncthe vertical refresh sync interval.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetVSync

The documentation for this struct was generated from the following file: