backspace 0.1.0

Game engine.
Documentation
// Copyright 2024-2025 Gabriel Bjørnager Jensen.
//
// This file is part of Backspace.
//
// Backspace is free software: you can redistribute
// it and/or modify it under the terms of the GNU
// Affero General Public License as published by
// the Free Software Foundation, either version 3
// of the License, or (at your option) any later
// version.
//
// Backspace is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; with-
// out even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Af-
// fero General Public License along with Back-
// space. If not, see
// <https://www.gnu.org/licenses/>.

use crate::engine::InitGraphics;
use crate::error::Result;

use winit::event_loop::ActiveEventLoop;

/// A graphics context.
#[derive(Debug)]
pub(super) enum Graphics {
	/// An uninitialised graphics context.
	Uninit,

	/// An initialised graphics context.
	Init(InitGraphics),
}

impl Graphics {
	/// Constructs a new, uninitialised graphics context.
	#[inline]
	#[must_use]
	pub const fn new() -> Self {
		Self::Uninit
	}

	/// Initialises the graphics context.
	#[inline]
	pub fn init(&mut self, event_loop: &ActiveEventLoop, app_name: &str) -> Result<()> {
		let init = InitGraphics::new(event_loop, app_name)?;
		*self = Self::Init(init);

		Ok(())
	}
}

impl Default for Graphics {
	/// Equivalent to <code>[Graphics]::[new](Graphics::new)</code>.
	#[inline]
	fn default() -> Self {
		Self::new()
	}
}