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

A structure representing rendering state. More...

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

Public Member Functions

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 (TextureRef texture)
 Set a texture as the current rendering target.
 
TextureRef GetTarget () const
 Get the current render target.
 
void SetLogicalPresentation (const 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 (const 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 (const 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 (const SDL_FPoint &p1, const 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 (TextureRef 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 (TextureRef 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 (TextureRef 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 (TextureRef 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 (TextureRef 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 (TextureRef 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 (TextureRef.SetColorMod and TextureRef.SetAlphaMod are ignored).
 
void RenderGeometryRaw (TextureRef 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 (TextureRef.SetColorMod and TextureRef.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 RendererRef.
 
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 from the underlying resource.
 
constexpr Resource (const ResourceHandle< Resource< T > > auto &resource)
 Constructs from pointer like.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
- Public Member Functions inherited from SDL::Resource< SDL_Renderer * >
constexpr Resource (SDL_Renderer * resource={})
 Constructs from the underlying resource.
 
constexpr Resource (const ResourceHandle< Resource< SDL_Renderer * > > auto &resource)
 Constructs from pointer like.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr operator value_type () const
 Converts back to underlying type.
 
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 const SDL_Renderer * operator-> () const
 Access to fields.
 
constexpr SDL_Renderer * operator-> ()
 Access to fields.
 

Static Public Member Functions

static void reset (SDL_Renderer *resource)
 Destroy the rendering context for a window and free all associated textures.
 

Additional Inherited Members

- Public Types inherited from SDL::Resource< SDL_Renderer * >
using value_type = SDL_Renderer *
 The raw resource type.
 

Detailed Description

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

Member Function Documentation

◆ ConvertEventToRenderCoordinates()

void SDL::RendererRef::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 RendererRef.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
RendererRef.RenderCoordinatesFromWindow

◆ Flush()

void SDL::RendererRef::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 RendererRef.

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::RendererRef::GetClipRect ( ) const
inline

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

Returns
a Rect structure filled in 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
RendererRef.IsClipEnabled
RendererRef.SetClipRect

◆ GetColorScale()

float SDL::RendererRef::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
RendererRef.SetColorScale

◆ GetCurrentOutputSize() [1/2]

Point SDL::RendererRef::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
RendererRef.GetOutputSize()

◆ GetCurrentOutputSize() [2/2]

void SDL::RendererRef::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 RendererRef.GetOutputSize().

Rendering target or not, the output will be adjusted by the current logical presentation state, dictated by RendererRef.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
RendererRef.GetOutputSize

◆ GetDrawBlendMode()

BlendMode SDL::RendererRef::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
RendererRef.SetDrawBlendMode

◆ GetDrawColor() [1/5]

FColor SDL::RendererRef::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::RendererRef::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
RendererRef.SetDrawColor

◆ GetDrawColor() [3/5]

void SDL::RendererRef::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::RendererRef::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::RendererRef::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
RendererRef.SetDrawColor

◆ GetLogicalPresentation() [1/2]

void SDL::RendererRef::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
RendererRef.SetLogicalPresentation

◆ GetLogicalPresentation() [2/2]

void SDL::RendererRef::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
RendererRef.SetLogicalPresentation

◆ GetLogicalPresentationRect()

FRect SDL::RendererRef::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
RendererRef.SetLogicalPresentation

◆ GetName()

const char * SDL::RendererRef::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.
See also
Renderer.Renderer

◆ GetOutputSize() [1/2]

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

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

Returns
Point on success.
Exceptions
Erroron failure.

◆ GetOutputSize() [2/2]

void SDL::RendererRef::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 RendererRef.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
RendererRef.GetCurrentOutputSize

◆ GetProperties()

PropertiesRef SDL::RendererRef::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::RendererRef::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::RendererRef::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
RendererRef.SetScale

◆ GetScale() [2/2]

void SDL::RendererRef::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
RendererRef.SetScale

◆ GetViewport()

Rect SDL::RendererRef::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
RendererRef.IsViewportSet
RendererRef.SetViewport

◆ GetVSync()

int SDL::RendererRef::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
RendererRef.SetVSync

◆ GetWindow()

WindowRef SDL::RendererRef::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::RendererRef::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
RendererRef.GetClipRect
RendererRef.SetClipRect

◆ IsViewportSet()

bool SDL::RendererRef::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
RendererRef.GetViewport
RendererRef.SetViewport

◆ Present()

void SDL::RendererRef::Present ( )
inline

SDL's rendering functions operate on a backbuffer; that is, calling a rendering function such as RendererRef.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 RendererRef.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 RendererRef.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 RendererRef.SetTarget(renderer, nullptr) afterwards, as textures by themselves do not have a concept of backbuffers. Calling RendererRef.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
Renderer.Renderer
RendererRef.RenderClear
RendererRef.RenderFillRect
RendererRef.RenderFillRects
RendererRef.RenderLine
RendererRef.RenderLines
RendererRef.RenderPoint
RendererRef.RenderPoints
RendererRef.RenderRect
RendererRef.RenderRects
RendererRef.SetDrawBlendMode
RendererRef.SetDrawColor

◆ ReadPixels()

Surface SDL::RendererRef::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 Surface.Destroy().

Note that this returns the actual pixels on the screen, so if you are using logical presentation you should use RendererRef.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 RendererRef.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::RendererRef::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 RendererRef.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
RendererRef.SetDrawColor

◆ RenderCoordinatesFromWindow()

FPoint SDL::RendererRef::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
RendererRef.SetLogicalPresentation
RendererRef.SetScale

◆ RenderCoordinatesToWindow()

FPoint SDL::RendererRef::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
RendererRef.SetLogicalPresentation
RendererRef.SetScale
RendererRef.SetViewport

◆ RenderDebugText()

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

This function will render a string of text to an RendererRef. 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 RendererRef.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::RendererRef::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::RendererRef::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
RendererRef.RenderFillRects

◆ RenderFillRects()

void SDL::RendererRef::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
RendererRef.RenderFillRect

◆ RenderLine()

void SDL::RendererRef::RenderLine ( const SDL_FPoint &  p1,
const 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
RendererRef.RenderLines

◆ RenderLines()

void SDL::RendererRef::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
RendererRef.RenderLine

◆ RenderPoint()

void SDL::RendererRef::RenderPoint ( const 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
RendererRef.RenderPoints

◆ RenderPoints()

void SDL::RendererRef::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
RendererRef.RenderPoint

◆ RenderRect()

void SDL::RendererRef::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
RendererRef.RenderRects

◆ RenderRects()

void SDL::RendererRef::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
RendererRef.RenderRect

◆ reset()

static void SDL::RendererRef::reset ( SDL_Renderer *  resource)
inlinestatic

This should be called before destroying the associated window.

Parameters
resourcethe rendering context.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Renderer.Create

◆ ResetClipRect()

void SDL::RendererRef::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::RendererRef::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::RendererRef::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
RendererRef.GetClipRect
RendererRef.ResetClipRect()
RendererRef.IsClipEnabled

◆ SetColorScale()

void SDL::RendererRef::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
RendererRef.GetColorScale

◆ SetDrawBlendMode()

void SDL::RendererRef::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
RendererRef.GetDrawBlendMode

◆ SetDrawColor() [1/2]

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

Set the color for drawing or filling rectangles, lines, and points, and for RendererRef.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
RendererRef.GetDrawColor

◆ SetDrawColor() [2/2]

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

Set the color for drawing or filling rectangles, lines, and points, and for RendererRef.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
RendererRef.GetDrawColor

◆ SetLogicalPresentation()

void SDL::RendererRef::SetLogicalPresentation ( const 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 RendererRef.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 RendererRef.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 RendererRef.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
RendererRef.ConvertEventToRenderCoordinates
RendererRef.GetLogicalPresentation
RendererRef.GetLogicalPresentationRect

◆ SetScale()

void SDL::RendererRef::SetScale ( const 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
RendererRef.GetScale

◆ SetViewport()

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

Drawing will clip to this area (separately from any clipping done with RendererRef.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
RendererRef.GetViewport
RendererRef.IsViewportSet

◆ SetVSync()

void SDL::RendererRef::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
RendererRef.GetVSync

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