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

Handle to an owned renderer. More...

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

Public Member Functions

void Destroy ()
 Destroy the rendering context for a window and free all associated textures.
 
RendererShared share ()
 Move this renderer into a RendererShared.
 
constexpr ResourceUnique (std::nullptr_t=nullptr)
 Default constructor.
 
constexpr ResourceUnique (base::value_type value, DELETER deleter={})
 Constructs from raw type.
 
constexpr ResourceUnique (ResourceUnique &&other)
 Move constructor.
 
 ResourceUnique (const ResourceUnique &other)=delete
 
- Public Member Functions inherited from SDL::ResourceUnique< RendererRef >
constexpr ResourceUnique (std::nullptr_t=nullptr)
 Default constructor.
 
constexpr ResourceUnique (base::value_type value, DefaultDeleter< RendererRef > deleter={})
 Constructs from raw type.
 
constexpr ResourceUnique (ResourceUnique &&other)
 Move constructor.
 
 ResourceUnique (const ResourceUnique &other)=delete
 
 ~ResourceUnique ()
 Destructor.
 
constexpr ResourceUniqueoperator= (ResourceUnique other)
 Assignment operator.
 
void reset ()
 Resets the value, destroying the resource if not nullptr.
 
- Public Member Functions inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
RESOURCE release ()
 Returns reference and reset this.
 
- Public Member Functions inherited from SDL::ResourcePtrBase< RESOURCE >
constexpr operator bool () const
 Check if not null.
 
constexpr bool operator== (const ResourcePtrBase &other) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr reference operator* () const
 Gets reference.
 
constexpr const referenceoperator-> () const
 Gets addressable reference.
 
constexpr referenceoperator-> ()
 Gets addressable reference.
 
reference get () const
 Get reference.
 

Static Public Member Functions

static Renderer Create (WindowRef window)
 Create a 2D rendering context for a window.
 
static Renderer Create (WindowRef window, StringParam name)
 Create a 2D rendering context for a window.
 
static Renderer CreateWithProperties (PropertiesRef props)
 Create a 2D rendering context for a window, with the specified properties.
 
static Renderer CreateSoftware (SurfaceRef surface)
 Create a 2D software rendering context for a surface.
 

Additional Inherited Members

- Public Types inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
using deleter = DELETER
 The deleter type.
 
- Public Types inherited from SDL::ResourcePtrBase< RESOURCE >
using reference = RESOURCE
 The reference resource type.
 
using value_type = typename reference::value_type
 The raw resource type.
 
- Protected Member Functions inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
constexpr ResourceOwnerBase (base::value_type value={}, DELETER deleter={})
 Constructs from raw type.
 
void free ()
 Frees resource.
 
- Protected Member Functions inherited from SDL::ResourcePtrBase< RESOURCE >
constexpr ResourcePtrBase (value_type value={})
 Constructs from raw type.
 
referenceget ()
 Get reference.
 

Detailed Description

Category:
Resource
See also
RendererRef

Member Function Documentation

◆ Create() [1/2]

static Renderer SDL::Renderer::Create ( WindowRef  window)
inlinestatic

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.
Returns
a valid rendering context on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
See also
Renderer.CreateWithProperties
Renderer.CreateSoftware
Renderer.Destroy
GetNumRenderDrivers
GetRenderDriver
RendererRef.GetName

◆ Create() [2/2]

static Renderer SDL::Renderer::Create ( WindowRef  window,
StringParam  name 
)
inlinestatic

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 RendererRef.SetLogicalPresentation() to change the content size and scaling options.

Parameters
windowthe window where rendering is displayed.
namethe name of the rendering driver to initialize, or nullptr to let SDL choose one.
Returns
a valid rendering context 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
Renderer.CreateWithProperties
Renderer.CreateSoftware
Renderer.Destroy
GetNumRenderDrivers
GetRenderDriver
RendererRef.GetName

◆ CreateSoftware()

static Renderer SDL::Renderer::CreateSoftware ( SurfaceRef  surface)
inlinestatic

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

Parameters
surfacethe Surface structure representing the surface where rendering is done.
Returns
a valid rendering context 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
Renderer.Destroy

◆ CreateWithProperties()

static Renderer SDL::Renderer::CreateWithProperties ( PropertiesRef  props)
inlinestatic

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 RendererRef.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.
Parameters
propsthe properties to use.
Returns
a valid rendering context 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
Properties.Create
Renderer.Create
Renderer.CreateSoftware
Renderer.Destroy
RendererRef.GetName

◆ Destroy()

void SDL::Renderer::Destroy ( )
inline

This should be called before destroying the associated window.

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

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