Open
Description
Raster estimator is possible with VSYNC timestamps.
- Properties needed: Screen height, screen VBI size.
- VBI size can be assumed as 45 by default, unless overriden by user of module (e.g. platform specific VBI-size-detecting APIs)
// Run this after a 10-second refresh cycle counting initialization at startup (but keep counting beyond, to incrementally improve accuracy sufficiently enough for beam racing apps)
var accurateRefreshRate = hertz.getCurrentFrequency();
var scanoutPercentage = hertz.getRasterScanoutPercentage();
// Common VBI size for maximum raster accuracy, adjust as needed. VGA 480p has 45, and HDTV 1080p has 45
// Or optionally use #ifdef type for plat-specific APIs like Linux modelines or Windows QueryDisplayConfig()
var blanking = 45;
// Vertical screen resolution
var height = screen.height;
// Signal vertical total. You could ignore blanking, with a bit more error margin
// (fine for frameslice beamracing for emulators, ala WinUAE lagless sync, but in a more crossplatform way)
var verticalTotal = height + blanking;
// Estimated current raster scan line number at this instant on the GPU output, assuming portrait-mode display
var raster = scanoutPercentage * verticalTotal;
// OPTIONAL: If your VSYNC timestamp is end-of-VBI rather than start-of-VBI, then compensate
// However, most frame presentation APIs (running at max rate) unblock at end of refresh cycle (beginning of VBI)
// raster += blanking
// raster = (raster % verticaltotal);
While you can guesstimate the raster during javascript, you can't do any rasterdemos because you can't use VSYNC OFF + high framerates in a web browser outside requestAnimationFrame(). But this generic math code is highly portable to other languages.
Metadata
Metadata
Assignees
Labels
No labels
Activity