libretro.drivers.video.multi¶
Types for delegating to different VideoDriver implementations at runtime,
depending on the player’s preferences
and available hardware resources.
Module Attributes
The default mapping from context types to |
Classes
A video driver that delegates to one of several possible |
- final class MultiVideoDriver[source]¶
Bases:
VideoDriverA video driver that delegates to one of several possible
VideoDrivers, depending on what the core or frontend requests.This class is useful for a
Corethat supports multiple graphics APIs, especially if it can switch between them at runtime.- __init__(drivers=mappingproxy({<HardwareContext.NONE: 0>: <class 'libretro.drivers.video.software.array.ArrayVideoDriver'>, <HardwareContext.OPENGL_CORE: 3>: <class 'libretro.drivers.video.opengl.moderngl.ModernGlVideoDriver'>, <HardwareContext.OPENGL: 1>: <class 'libretro.drivers.video.opengl.moderngl.ModernGlVideoDriver'>}), preferred=HardwareContext.NONE)[source]¶
Initialize a new multi-video driver with the preferred
HardwareContext.- Parameters:
drivers (
Mapping[HardwareContext,Callable[[],VideoDriver]]) – A map of hardware context types to callables; each callable should accept no arguments and return a new video driver instance. Defaults toDEFAULT_DRIVER_MAP.preferred (
HardwareContext) – The initial hardware context type to use.
- Raises:
TypeError – If any parameter is not consistent with its documented types.
ValueError – If
driversdoesn’t contain an entry for bothpreferredandHardwareContext.NONE.
- refresh(data, width, height, pitch)[source]¶
Delegate to the active video driver’s
VideoDriver.refresh()method.- Return type:
- property needs_reinit¶
Trueif no underlyingVideoDriverhas been initialized, a new graphics API has been requested withset_context(), or the active driver’sneeds_reinitisTrue.
- reinit()[source]¶
Initialize a new
VideoDriverinstance based on the most recent graphics API request, or reinitializes the current one if no new context has been requested.If initializing a new
VideoDriverthen itspixel_format,system_av_info,rotation, andshared_contextare set to the values used by the existing driver (if any) where supported.Note
Does not use
preferred_context.- Return type:
- property supported_contexts¶
The set of all graphics APIs supported by this driver. All video drivers must support at least
HardwareContext.NONE, which indicates software rendering capabilities.Tip
Most drivers won’t support more than one kind of graphics context (not counting
NONE), but this isn’t a hard requirement.
- property active_context¶
The hardware context that is currently exposed to the core. Must be an element of
supported_contexts.Will be
HardwareContext.NONEuntil the core successfully requests a graphics context usingEnvironmentCall.SET_HW_RENDER, at which point it will be set to the requested context type.Attention
This property does not necessarily indicate which graphics API is loaded and active; it specifically means the context type that the core requested.
For example, a core that uses software rendering wouldn’t request a hardware context, therefore this property would return
HardwareContext.NONEregardless of the actual graphics API in use.After all, most of RetroArch’s video drivers rely on hardware graphics APIs, even if the core doesn’t request them. If the core is only software-rendered, then what difference does it make?
- property preferred_context¶
The preferred hardware context for this driver. Cores that support multiple graphics APIs can use this to choose one without the player needing to specify it.
Can be a member of
supported_contexts(includingNONE) to indicate preference for that context, orNoneto disableEnvironmentCall.GET_PREFERRED_HW_RENDER.Setting or deleting this property will not affect the active context.
- Raises:
ValueError – If attempting to set a preferred context that this driver doesn’t support (i.e. that’s not in
supported_contexts).TypeError – If attempting to set a value that isn’t a
HardwareContext.
Note
Corresponds to
RETRO_ENVIRONMENT_GET_PREFERRED_HW_RENDER.
- set_context(callback)[source]¶
Request the use of a particular graphics context, including
HardwareContext.NONEto revert to software rendering. The driver won’t be reinitialized until the next call toreinit().- Parameters:
callback (
retro_hw_render_callback) – Aretro_hw_render_callbackwith the context parameters requested by the core, plus callbacks to run at certain points in the context’s lifecycle.- Raises:
TypeError – If
callbackis not aretro_hw_render_callback.UnsupportedContextError – If the driver cannot set the requested context with the requested parameters.
- Return type:
Note
Corresponds to
RETRO_ENVIRONMENT_SET_HW_RENDER.Note
There’s no need to set the callbacks; this is done by the
EnvironmentDriver.
- property current_framebuffer¶
The current framebuffer for the active graphics context. The core should use this framebuffer when rendering to the screen. Software-rendered graphics will be drawn to this framebuffer.
- Returns:
An integer identifier for the current framebuffer, or
Noneif the driver doesn’t support or need this feature.
Note
Corresponds to
retro_hw_render_callback.get_current_framebuffer.This property is generally only used by OpenGL and OpenGL ES, but it’s part of the general
retro_hw_render_callbackstructure for historical reasons.
- get_proc_address(sym)[source]¶
Return the address of the graphics API function with the given name.
- Parameters:
sym (
bytes) – The name of the function to look up.- Return type:
CFunctionType|None- Returns:
The address of the function if found,
Noneotherwise. Will also returnNoneif the driver doesn’t support or need this feature.- Raises:
Note
Corresponds to
retro_hw_render_callback.get_proc_address.This property is generally only used by OpenGL and OpenGL ES, but it’s part of the general
retro_hw_render_callbackstructure for historical reasons.
- property rotation¶
The angle by which the output should be rotated, in increments of 90 degrees.
If the video driver doesn’t support rotation, then this property will always return
Rotation.NONE.- Raises:
NotImplementedError – If setting or deleting this property on a
VideoDriverthat doesn’t support doing so.
Note
Corresponds to
RETRO_ENVIRONMENT_SET_ROTATION.
- property can_dupe¶
Whether the frontend can re-render the previous frame.
Trueif frame duping is supported,Falseif not.If
None, thenRETRO_ENVIRONMENT_GET_CAN_DUPEis unavailable to cores.- Raises:
NotImplementedError – If setting or deleting this property on a
VideoDriverthat doesn’t support doing so.
Note
Corresponds to
RETRO_ENVIRONMENT_GET_CAN_DUPE.
- property pixel_format¶
The pixel format that this driver uses for its frame buffer. If a driver doesn’t support setting the pixel format, then this property will always return
PixelFormat.RGB1555.- Raises:
TypeError – If trying to set a value that isn’t a
PixelFormat.NotImplementedError – If setting this property on a driver that doesn’t support
EnvironmentCall.SET_PIXEL_FORMAT.
Note
Corresponds to
RETRO_ENVIRONMENT_SET_PIXEL_FORMAT.
- property system_av_info¶
The system AV info for the current session. May be
Noneif not yet set.Initialized from
Core.get_system_av_info()some time after this driver is created. After being set, this video driver is immediately reinitialized if necessary.- Raises:
TypeError – If trying to set a value that isn’t a
retro_system_av_info.
Note
Corresponds to
RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO.The getter will return a copy of the driver’s
retro_system_av_infoobject to avoid accidental modification of the original.
- classmethod __new__(*args, **kwargs)¶
- property geometry¶
The active screen geometry. May be
Noneifsystem_av_infohasn’t been set yet.Note
Corresponds to
RETRO_ENVIRONMENT_SET_GEOMETRY.The getter will return a copy of the driver’s
retro_game_geometryobject to avoid accidental modification of the original.Caution
When setting this property, this driver’s values of
retro_game_geometry.max_widthandretro_game_geometry.max_heightare not updated.libretro.h guarantees that
RETRO_ENVIRONMENT_SET_GEOMETRYwill complete in constant time without needing to reinitialize the driver; this may not be possible if the driver’s framebuffer needs to be reallocated.
- get_software_framebuffer(width, height, flags)[source]¶
Return a framebuffer of the given size, usually (but not necessarily) mapped directly into GPU memory. Can be used to accelerate software rendering, as data doesn’t need to be copied between the core and the GPU.
- Parameters:
width (
int) – The width of the framebuffer, in pixels.height (
int) – The height of the framebuffer, in pixels.flags (
MemoryAccess) – Flags that describe how the core will access the framebuffer.
- Return type:
- Returns:
A
retro_framebufferobject with the requested properties, orNoneif not supported by thisVideoDriver.- Raises:
ValueError – If the framebuffer’s width or height is less than 1.
TypeError – If any parameter’s type is not consistent with this method’s signature.
Note
Corresponds to
RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER.
- property hw_render_interface¶
Returns a
retro_hw_render_interfacesubclass that can be used for rendering operations specific to thisVideoDriver.Will be
Noneif not supported or needed by this driver.Note
Corresponds to
RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE.
Whether to create a shared hardware context. Takes effect the next time the driver is reinitialized.
Note
Corresponds to
RETRO_ENVIRONMENT_SET_HW_SHARED_CONTEXT.This property is generally only used by OpenGL and OpenGL ES, but it has its own environment call for historical reasons.
- DEFAULT_DRIVER_MAP = mappingproxy({<HardwareContext.NONE: 0>: <class 'libretro.drivers.video.software.array.ArrayVideoDriver'>, <HardwareContext.OPENGL_CORE: 3>: <class 'libretro.drivers.video.opengl.moderngl.ModernGlVideoDriver'>, <HardwareContext.OPENGL: 1>: <class 'libretro.drivers.video.opengl.moderngl.ModernGlVideoDriver'>})¶
The default mapping from context types to
VideoDriverconstructors. Defaults may vary based on the platform and installed packages. They are as follows:HardwareContext.NONEAlways available and mapped to
ArrayVideoDriver.OPENGL_CORE,OPENGLMapped to
ModernGlVideoDriverifmodernglis installed, absent if not.
VideoDrivers for other graphics APIs have not yet been implemented.