awi/render/
mod.rs

1// Copyright Jeron A. Lau 2017 - 2018.
2// Dual-licensed under either the MIT License or the Boost Software License,
3// Version 1.0.  (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6//! Interface with the GPU to render graphics or do fast calculations.
7
8mod base;
9
10pub use self::base::*;
11
12#[cfg(any(
13	target_os="macos", target_os="android", target_os="linux",
14	target_os="windows", target_os="nintendo_switch"
15))] mod vulkan;
16
17#[cfg(any(
18	target_os="android", target_os="linux", target_os="windows",
19	target_os="web"
20))] mod opengl;
21
22/// Create a new Vulkan / OpenGL Display.
23pub fn new_display() -> Result<Box<Display>, String> {
24	let mut err = "".to_string();
25
26	// Try Vulkan first.
27	#[cfg(any(
28		target_os="macos", target_os="android", target_os="linux",
29		target_os="windows", target_os="nintendo_switch"
30	))]
31	{
32		match vulkan::new() {
33			Ok(vulkan) => return Ok(vulkan),
34			Err(vulkan) => err.push_str(&vulkan),
35		}
36		err.push('\n');
37	}
38
39	// Fallback on OpenGL/OpenGLES
40	#[cfg(any(
41		target_os="android", target_os="linux", target_os="windows",
42	))]
43	{
44		match opengl::new() {
45			Ok(opengl) => return Ok(opengl),
46			Err(opengl) => err.push_str(opengl),
47		}
48		err.push('\n');
49	}
50
51	// Give up
52	err.push_str("No more backend options");
53	Err(err)
54}