Expand description
Minimal libretro wrapper for implementing Rust cores.
The crate exposes typed Rust wrappers for libretro.h plus a trait/macro
pair for exporting the required retro_* symbols from a Rust core.
Methodology:
- Keep public APIs Rust-first even when the underlying libretro ABI is C-first.
- Prefer strings, slices, enums, and return values over raw pointers or mutable out-params whenever the wrapper can do that conversion centrally.
- Keep raw ABI details private unless exposing them is necessary for a real core-development use case.
- Match libretro/OpenGL naming where it helps recognition, but not at the cost of forcing callers back into manual FFI plumbing.
API map:
Core,Runtime,Environment, andexport_core!are the primary core authoring surface.ContentContract,SystemInfo,GameInfo, andSystemAvInfodescribe startup metadata, content loading, geometry, and timing.- Input polling uses
Runtimehelpers with typed devices such asJoypadButton,AnalogStick,MouseButton, andPointerAxis. - Event-shaped frontend callbacks are registered through
CoreEventConfigwith DOM-style listener methods such asCoreEventConfig::add_keyboard_event_listener; callback-shaped frontend hooks with one active registration, such as frame timing, use explicitset_*_callbackmethods. - Optional frontend services are exposed as typed interfaces such as
VfsInterface,MidiInterface,MicrophoneInterface,PerfInterface,SensorInterface,LocationInterface, andCameraInterface. - Hardware rendering uses
HwRenderConfigfor context negotiation andGlfor typed OpenGL access.
ⓘ
use libretro::{
ContentContract, Core, CoreEventConfig, Environment, GameGeometry, HwRenderConfig,
JoypadButton, KeyboardEvent, PixelFormat, Runtime, SystemAvInfo, SystemInfo, SystemTiming,
VariableDefinition,
};
#[derive(Default)]
struct GlCore {
width: u32,
height: u32,
}
impl Core for GlCore {
fn system_info(&self) -> SystemInfo {
let mut info = SystemInfo::new("TestCore GL", "v1");
info.need_fullpath = false;
info
}
fn av_info(&self) -> SystemAvInfo {
SystemAvInfo {
geometry: GameGeometry {
base_width: 320,
base_height: 240,
max_width: 1024,
max_height: 1024,
aspect_ratio: 4.0 / 3.0,
},
timing: SystemTiming {
fps: 60.0,
sample_rate: 0.0,
},
}
}
fn configure_events(&mut self, events: &mut CoreEventConfig<Self>) {
events.add_keyboard_event_listener(Self::keyboard_event);
}
fn on_set_environment(&mut self, env: &mut Environment<'_>) {
ContentContract::new("bin")
.with_support_no_game(true)
.with_persistent_data(true)
.register_environment(env);
env.set_variables(&[VariableDefinition::new(
"testgl_resolution",
"Internal resolution; 320x240|640x480|1024x768",
)]);
}
fn load_game(
&mut self,
_game: Option<libretro::GameInfo<'_>>,
runtime: &mut Runtime<'_>,
) -> bool {
let mut env = runtime.environment();
env.set_pixel_format(PixelFormat::Xrgb8888)
&& env
.set_hw_render_from_candidates(&[
HwRenderConfig::opengl()
.with_depth(true)
.with_stencil(true)
.with_bottom_left_origin(true),
HwRenderConfig::opengles3()
.with_depth(true)
.with_stencil(true)
.with_bottom_left_origin(true),
])
.is_some()
}
fn run(&mut self, runtime: &mut Runtime<'_>) {
runtime.poll_input();
if runtime.joypad_pressed(0, JoypadButton::Up) {
// update state
}
runtime.video_refresh_hw(self.width, self.height, 0);
}
fn keyboard_event(&mut self, event: KeyboardEvent) {
if event.down {
// handle typed keyboard event
}
}
}
libretro::export_core!(GlCore::default());Macros§
- export_
core - Export a
Coreimplementation as the required libretroretro_*symbols.
Structs§
- Audio
Buffer Occupancy - Audio
Buffer Status - Audio
Latency Millis - Audio
Sample Rate Hz - Camera
Frame Size - Camera
Interface - Camera
RawFrame - Camera
Request - Camera
Texture Frame - Camera
Texture Id - Camera
Texture Target - Cheat
Code - Cheat
Index - Compat
Gl - GLES2-era drawing symbols for simple compatibility rendering.
- Compat
GlClear - Minimal GL entry points needed for legal hardware framebuffer setup.
- Compat
Texture Gl - Texture/uniform/blend symbols layered on top of
CompatGl. - Content
Contract - Content
Info Override - Per-extension content override registered with the frontend.
- Controller
Description - Controller
Device Subclass - Controller
Info - Core
Event Config - Event-listener registration for frontend-to-core notifications.
- Core
Option Category - Core
Option Definition - Core
Option Display - Core
Option Value - Core
Options - Core
Options Version - Core
Proc Address - Device
Power - Disk
Control Interface Version - Disk
Index - Emulated
Address - Environment
- Typed wrapper around libretro environment commands.
- Extended
Game Info - Extended
Message - Fake
Attach Shader Call - Fake
Bind Attrib Location Call - Fake
Bind Buffer Base Call - Fake
Bind Buffer Range Call - Fake
Blend Equation Separate Call - Fake
Blend Func Separate Call - Fake
Copy Buffer SubData Call - Fake
Create Shader Call - Fake
Draw Arrays Call - Fake
Draw Elements Call - Fake
GlConfig - Fake
GlSnapshot - Fake
Vertex Attrib Pointer Call - Fast
Forward Ratio - Fast
Forwarding Override - Frame
Time - Game
Geometry - Game
Info - Gl
- Ergonomic OpenGL access for libretro hardware-rendered cores.
- GlBuffer
- GlBuffer
Binding Index - GlBuffer
Byte Offset - GlBuffer
Byte Size - GlBuffer
Range - GlColor
Write Mask - GlDraw
Range - GlElement
Byte Offset - GlElement
Range - GlElement
Vertex Range - GlFramebuffer
- GlInstance
Count - GlPolygon
Offset - GlProgram
- GlQuery
- GlRect
- GlRenderbuffer
- GlRenderbuffer
Size - GlShader
- GlStencil
Mask - GlStencil
Reference - GlSync
- GlSync
Timeout - GlTexture
- GlTexture
Level - GlTexture
Offset2D - GlTexture
Offset3D - GlTexture
Size2D - GlTexture
Size3D - GlTexture
Unit - GlUniform
Location - GlVersion
Info - GlVertex
Array - GlVertex
Attrib Byte Offset - GlVertex
Attrib Divisor - GlVertex
Attrib F32Layout - GlVertex
Attrib Location - GlVertex
Attrib Stride - HwRender
Config - Hardware-rendering context request sent to the frontend.
- HwRender
Context Negotiation Interface - HwRender
Interface - Input
Descriptor - Input
Descriptor Id - Input
Descriptor Index - Input
Port - Joypad
Button Set - Keyboard
Character - Keyboard
Event - LedIndex
- LedInterface
- Location
Interface - Location
Interval Meters - Location
Interval Millis - Location
Position - Logger
- Frontend logger with stderr fallback.
- Memory
MapDescriptor - Memory
MapLen - Memory
MapMask - Memory
MapOffset - Microphone
- Microphone
Interface - Microphone
Params - Microphone
Rate Hz - Midi
Delta Micros - Midi
Interface - Netpacket
- Netpacket
Flags - Netpacket
Session - Netplay
Client Id - Perf
Counter - Perf
Interface - Perf
Tick - Perf
Time Micros - Performance
Level - Pointer
Index - Preferred
HwRender - RawAudio
Buffer Status Callback - RawAudio
Callback - RawContent
Info Override - RawFrame
Time Callback - RawGame
Info - RawHw
Render Callback - RawInput
Descriptor - RawKeyboard
Callback - RawLog
Callback - RawMessage
- RawSystem
Info - RawVariable
- Refresh
Rate Hz - Rumble
Interface - Rumble
Strength - RunLoop
Rate Hz - Runtime
- Per-frame access to frontend callbacks and services.
- Sensor
Interface - Sensor
Rate Hz - Software
Framebuffer - Software
Framebuffer Request - Subsystem
Id - Subsystem
Info - Subsystem
Memory Info - Subsystem
Memory Type - Subsystem
RomInfo - System
AvInfo - System
Info - Static metadata returned to the frontend by
Core::system_info. - System
Timing - Throttle
State - Variable
Definition - VfsDirectory
- VfsFile
- VfsInterface
- VfsInterface
Version - VfsMetadata
- glsym
- Typed OpenGL symbol table resolved from libretro’s hardware-render callbacks.
Enums§
- Analog
Axis - Analog
Stick - Audio
Callback State - AvEnable
- Camera
Capability - Controller
Device - Core
Memory - Core
Options Build Error - CpuFeature
- Disk
Tray State - Framebuffer
Memory Access - Framebuffer
Memory Type - GlBlend
Equation - GlBlend
Factor - GlBuffer
Target - GlBuffer
Usage - GlCapability
- GlCull
Face Mode - GlDepth
Function - GlDraw
Mode - GlFramebuffer
Attachment - GlFramebuffer
Buffer - GlFramebuffer
Target - GlFramebuffer
Texture2D Target - GlFront
Face Winding - GlIndex
Type - GlIndexed
Buffer Target - GlPixel
Store Alignment - GlQuery
Target - GlRenderbuffer
Internal Format - GlRenderbuffer
Target - GlShader
Stage - GlStencil
Face - GlStencil
Function - GlStencil
Operation - GlSync
Wait Result - GlTexture
Data Type - GlTexture
Filter - GlTexture
Format - GlTexture
Internal Format - GlTexture
MagFilter - GlTexture
MinFilter - GlTexture
Target - GlTexture
Wrap - GlVertex
Attrib F32Components - HwContext
Type - HwRender
Context Negotiation Interface Type - HwRender
Interface Type - Input
Device Capability - Joypad
Button - Keyboard
Key - Keyboard
Modifier - Language
- LedState
- Lightgun
Axis - Lightgun
Button - LogLevel
- Memory
Descriptor Alignment - Memory
Descriptor Flag - Memory
Descriptor MinAccess Size - Memory
Region - Message
Kind - Message
Progress - Message
Target - Microphone
Read Error - Mouse
Axis - Mouse
Button - Mouse
Wheel - Netpacket
Delivery - Netpacket
Target - Pixel
Format - Pointer
Axis - Power
State - Region
- Rumble
Effect - Savestate
Context - Sensor
- Sensor
Action - Sensor
Input - Serialization
Quirk - Throttle
Mode - VfsFile
Access - VfsFile
Access Hint - VfsSeek
Position - VfsStat
Flag - Video
Rotation
Constants§
- OPENGL_
COMPATIBILITY_ HW_ RENDER_ LABEL - OPENGL_
MODERN_ PREFERRED_ HW_ RENDER_ LABEL - RETRO_
API_ VERSION - RETRO_
DEVICE_ ANALOG - RETRO_
DEVICE_ ID_ ANALOG_ X - RETRO_
DEVICE_ ID_ ANALOG_ Y - RETRO_
DEVICE_ ID_ JOYPAD_ A - RETRO_
DEVICE_ ID_ JOYPAD_ B - RETRO_
DEVICE_ ID_ JOYPAD_ DOWN - RETRO_
DEVICE_ ID_ JOYPAD_ L - RETRO_
DEVICE_ ID_ JOYPAD_ L2 - RETRO_
DEVICE_ ID_ JOYPAD_ L3 - RETRO_
DEVICE_ ID_ JOYPAD_ LEFT - RETRO_
DEVICE_ ID_ JOYPAD_ MASK - RETRO_
DEVICE_ ID_ JOYPAD_ R - RETRO_
DEVICE_ ID_ JOYPAD_ R2 - RETRO_
DEVICE_ ID_ JOYPAD_ R3 - RETRO_
DEVICE_ ID_ JOYPAD_ RIGHT - RETRO_
DEVICE_ ID_ JOYPAD_ SELECT - RETRO_
DEVICE_ ID_ JOYPAD_ START - RETRO_
DEVICE_ ID_ JOYPAD_ UP - RETRO_
DEVICE_ ID_ JOYPAD_ X - RETRO_
DEVICE_ ID_ JOYPAD_ Y - RETRO_
DEVICE_ ID_ LIGHTGUN_ IS_ OFFSCREEN - RETRO_
DEVICE_ ID_ LIGHTGUN_ SCREEN_ X - RETRO_
DEVICE_ ID_ LIGHTGUN_ SCREEN_ Y - RETRO_
DEVICE_ ID_ LIGHTGUN_ TRIGGER - RETRO_
DEVICE_ ID_ MOUSE_ LEFT - RETRO_
DEVICE_ ID_ MOUSE_ WHEELUP - RETRO_
DEVICE_ ID_ MOUSE_ X - RETRO_
DEVICE_ ID_ POINTER_ PRESSED - RETRO_
DEVICE_ ID_ POINTER_ Y - RETRO_
DEVICE_ INDEX_ ANALOG_ BUTTON - RETRO_
DEVICE_ INDEX_ ANALOG_ LEFT - RETRO_
DEVICE_ JOYPAD - RETRO_
DEVICE_ KEYBOARD - RETRO_
DEVICE_ LIGHTGUN - RETRO_
DEVICE_ MOUSE - RETRO_
DEVICE_ NONE - RETRO_
DEVICE_ POINTER - RETRO_
ENVIRONMENT_ GET_ CURRENT_ SOFTWARE_ FRAMEBUFFER - RETRO_
ENVIRONMENT_ GET_ GAME_ INFO_ EXT - RETRO_
ENVIRONMENT_ GET_ LOG_ INTERFACE - RETRO_
ENVIRONMENT_ GET_ PREFERRED_ HW_ RENDER - RETRO_
ENVIRONMENT_ GET_ VARIABLE - RETRO_
ENVIRONMENT_ GET_ VARIABLE_ UPDATE - RETRO_
ENVIRONMENT_ SET_ CONTENT_ INFO_ OVERRIDE - RETRO_
ENVIRONMENT_ SET_ CONTROLLER_ INFO - RETRO_
ENVIRONMENT_ SET_ FASTFORWARDING_ OVERRIDE - RETRO_
ENVIRONMENT_ SET_ GEOMETRY - RETRO_
ENVIRONMENT_ SET_ HW_ RENDER - RETRO_
ENVIRONMENT_ SET_ INPUT_ DESCRIPTORS - RETRO_
ENVIRONMENT_ SET_ KEYBOARD_ CALLBACK - RETRO_
ENVIRONMENT_ SET_ MESSAGE - RETRO_
ENVIRONMENT_ SET_ PIXEL_ FORMAT - RETRO_
ENVIRONMENT_ SET_ PROC_ ADDRESS_ CALLBACK - RETRO_
ENVIRONMENT_ SET_ SUPPORT_ NO_ GAME - RETRO_
ENVIRONMENT_ SET_ VARIABLES - RETRO_
HW_ FRAME_ BUFFER_ VALID - RETRO_
MEMORY_ ROM - RETRO_
MEMORY_ RTC - RETRO_
MEMORY_ SAVE_ RAM - RETRO_
MEMORY_ SYSTEM_ RAM - RETRO_
MEMORY_ VIDEO_ RAM - RETRO_
REGION_ NTSC - RETRO_
REGION_ PAL
Traits§
- Core
- Trait implemented by a Rust libretro core.
Functions§
- bounded_
game_ geometry - configure_
fake_ gl_ for_ testing - exact_
audio_ frames_ per_ video_ frame - fake_
get_ ⚠proc_ address_ for_ testing - Returns fake GL procedure addresses for tests.
- fixed_
system_ av_ info - game_
geometry - opengl_
compatibility_ hw_ render_ candidates - opengl_
modern_ preferred_ hw_ render_ candidates - reset_
fake_ gl_ for_ testing - silent_
stereo_ frames - silent_
stereo_ frames_ for_ video_ frame - snapshot_
fake_ gl_ for_ testing - system_
av_ info
Type Aliases§
- AvEnable
Flags - Camera
Capabilities - CpuFeatures
- Framebuffer
Memory Access Flags - Framebuffer
Memory Types - Input
Device Capabilities - Keyboard
Modifiers - Memory
Descriptor Flags - Serialization
Quirks - VfsFile
Access Flags - VfsFile
Access Hints - VfsStat
Flags - retro_
audio_ sample_ batch_ t - retro_
audio_ sample_ t - retro_
environment_ t - retro_
input_ poll_ t - retro_
input_ state_ t - retro_
video_ refresh_ t