Skip to content

Commit 44d2ec0

Browse files
committed
update web build to include gpu information
1 parent 894e296 commit 44d2ec0

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fn main() {
4141
title: "Lightborne".into(),
4242
name: Some("lightborne".into()),
4343
present_mode: PresentMode::AutoNoVsync,
44+
canvas: Some("#bevy-container".into()),
4445
fit_canvas_to_parent: true,
4546
prevent_default_event_handling: false,
4647
..default()

wasm/index.css

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@font-face {
2+
font-family: 'Munro';
3+
src: url('./assets/fonts/Munro.ttf') format('truetype');
4+
font-weight: normal;
5+
font-style: normal;
6+
}
7+
8+
.container {
9+
width: auto;
10+
height: auto;
11+
aspect-ratio: 16 / 9;
12+
max-width: 100dvw;
13+
max-height: 100dvh;
14+
}
15+
16+
.wrapper {
17+
position: relative;
18+
display: flex;
19+
flex-direction: column;
20+
align-items: center;
21+
justify-content: center;
22+
background-color: black;
23+
width: 100dvw;
24+
height: 100dvh;
25+
overflow: hidden;
26+
}
27+
28+
.canvas {
29+
outline: none;
30+
}
31+
32+
#info-panel-left, #info-panel-right {
33+
margin: 0px;
34+
font-size: 1.5rem;
35+
padding: 0.5rem;
36+
}
37+
38+
.info-panel {
39+
width: 100%;
40+
position: absolute;
41+
left: 0px;
42+
bottom: 0px;
43+
color: white;
44+
font-family: "Munro";
45+
opacity: 50%;
46+
display: flex;
47+
justify-content: space-between;
48+
}

wasm/index.html

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<!doctype html>
22
<html lang="en">
3+
<head>
4+
<link rel="stylesheet" href="index.css"/>
5+
</head>
36

4-
<body style="margin: 0px; width: auto; height: auto; aspect-ratio: 16 / 9; background-color: black; max-width: 100dvw; max-height: 100dvh">
5-
<script type="module">
6-
import './restart-audio-context.js'
7-
import init from './bevy_game.js'
8-
9-
init().catch((error) => {
10-
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
11-
throw error;
12-
}
13-
});
14-
</script>
7+
<body style="margin: 0px;">
8+
<script type="module" src="index.js"></script>
9+
<div class="wrapper">
10+
<div class="container">
11+
<canvas id="bevy-container" class="canvas" tabindex=0 />
12+
</div>
13+
<div class="info-panel">
14+
<p id="info-panel-left"/>
15+
<p id="info-panel-right"/>
16+
</div>
17+
</div>
1518
</body>
1619

1720
</html>

wasm/index.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import './restart-audio-context.js'
2+
import init from './bevy_game.js'
3+
4+
init().catch((error) => {
5+
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
6+
throw error;
7+
}
8+
});
9+
10+
const canvas = document.getElementById("bevy-container");
11+
const infoLeft = document.getElementById("info-panel-left");
12+
const infoRight = document.getElementById("info-panel-right");
13+
const gl = canvas.getContext("webgl2");
14+
if (gl) {
15+
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
16+
if (debugInfo) {
17+
const vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
18+
const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
19+
20+
infoLeft.textContent += `Vendor: ${vendor}, Renderer: ${renderer}`
21+
22+
if (/intel/i.test(vendor)) {
23+
infoRight.textContent += 'Likely using an integrated GPU. Running slow? Make sure hardware acceleration is on.';
24+
} else if (/nvidia|amd/i.test(vendor)) {
25+
infoRight.textContent += 'Likely using a dedicated GPU.';
26+
} else {
27+
infoRight.textContent += 'Could not determine GPU type. Running slow? Make sure hardware acceleration is on.';
28+
}
29+
} else {
30+
infoRight.textContent += 'WebGL debug renderer info is not available.';
31+
}
32+
} else {
33+
infoRight.textContent += 'WebGL is not supported on your browser.';
34+
}

0 commit comments

Comments
 (0)