use super::*;
impl Default for RenderConfig {
fn default() -> Self {
Self {
mode: RenderMode::Auto,
preferred_backend: None,
present_mode: PresentMode::VSync,
antialiasing: AntialiasingMode::AnalyticalSdf,
color_space: ColorSpace::Srgb,
dirty_rect_optimization: true,
tile_size: DEFAULT_TILE_SIZE,
max_fps: DEFAULT_MAX_FPS,
max_frames_in_flight: DEFAULT_MAX_FRAMES_IN_FLIGHT,
hdr: false,
direct_gpu_present: false,
adaptive_switch_mode: AdaptiveSwitchMode::RecommendOnly,
}
}
}
impl RenderConfig {
#[must_use]
pub fn software() -> Self {
let mut cfg: Self = Self::default();
cfg.set_mode(RenderMode::Software);
cfg.set_preferred_backend(Some(GraphicsBackend::SoftwareCpu));
cfg.set_direct_gpu_present(false);
cfg
}
#[must_use]
pub fn software_reference() -> Self {
Self::software()
}
#[must_use]
pub fn hardware() -> Self {
let mut cfg: Self = Self::default();
cfg.set_mode(RenderMode::Hardware);
cfg
}
#[must_use]
pub fn hardware_direct() -> Self {
let mut cfg: Self = Self::hardware();
cfg.set_direct_gpu_present(true);
cfg
}
#[must_use]
pub fn with_direct_gpu_present(mut self, enabled: bool) -> Self {
self.set_direct_gpu_present(enabled);
self
}
#[must_use]
pub fn with_max_fps(mut self, max_fps: Option<u32>) -> Self {
self.set_max_fps(max_fps.unwrap_or(DEFAULT_MAX_FPS));
self
}
#[must_use]
pub fn max_fps_limit(&self) -> Option<u32> {
let raw: u32 = self.get_max_fps();
if raw == 0 { None } else { Some(raw) }
}
#[must_use]
pub fn with_max_frames_in_flight(mut self, max_frames_in_flight: u32) -> Self {
self.set_max_frames_in_flight(max_frames_in_flight.clamp(1, MAX_ALLOWED_FRAMES_IN_FLIGHT));
self
}
#[must_use]
pub fn hybrid() -> Self {
let mut cfg: Self = Self::default();
cfg.set_mode(RenderMode::Hybrid);
cfg
}
#[must_use]
pub fn adaptive() -> Self {
let mut cfg: Self = Self::default();
cfg.set_mode(RenderMode::Auto);
cfg.set_direct_gpu_present(true);
cfg.set_adaptive_switch_mode(AdaptiveSwitchMode::RecommendOnly);
cfg
}
#[must_use]
pub fn adaptive_auto_switch() -> Self {
let mut cfg: Self = Self::adaptive();
cfg.set_adaptive_switch_mode(AdaptiveSwitchMode::AutoSwitch);
cfg
}
#[must_use]
pub fn with_adaptive_switch_mode(mut self, mode: AdaptiveSwitchMode) -> Self {
self.set_adaptive_switch_mode(mode);
self
}
#[must_use]
pub fn resolve_direct_gpu_present(&self, candidate: RenderBackendCandidate) -> bool {
let _: AdaptiveSwitchMode = self.get_adaptive_switch_mode();
candidate.is_direct_gpu()
}
#[must_use]
pub fn preferred_backend_value(&self) -> Option<GraphicsBackend> {
let Self {
preferred_backend, ..
} = *self;
preferred_backend
}
}
impl FrameStats {
#[must_use]
pub fn present_outcome(&self) -> PresentOutcome {
let submit: FrameSubmitOutcome = self.get_submit_outcome();
if self.get_wait_in_flight() && submit == FrameSubmitOutcome::SkippedNoDamage {
PresentOutcome::WaitInFlight
} else {
PresentOutcome::from_submit_outcome(submit)
}
}
pub fn record_present_outcome(&mut self, outcome: PresentOutcome) {
self.set_wait_in_flight(outcome == PresentOutcome::WaitInFlight);
self.set_submit_outcome(outcome.to_submit_outcome());
}
}