Skip to content

Commit

Permalink
web: Add 'Automatic' option to 'preferredRenderer'.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwannabethedev committed Apr 26, 2023
1 parent e5caf0f commit f4609d4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion web/packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WindowMode,
Letterbox,
LogLevel,
RenderBackend,
} from "./load-options";

export const DEFAULT_CONFIG: Required<BaseLoadOptions> = {
Expand Down Expand Up @@ -35,5 +36,5 @@ export const DEFAULT_CONFIG: Required<BaseLoadOptions> = {
publicPath: null,
polyfills: true,
playerVersion: null,
preferredRenderer: null,
preferredRenderer: RenderBackend.Automatic,
};
7 changes: 6 additions & 1 deletion web/packages/core/src/load-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ export const enum WindowMode {
* The available backends may change in future releases.
*/
export const enum RenderBackend {
/**
* Lets Ruffle select which renderer to use.
*/
Automatic = "",

/**
* An [in-development API](https://caniuse.com/webgpu) that will be preferred if available in the future.
* Should behave the same as wgpu-webgl, except with lower overhead and thus better performance.
Expand Down Expand Up @@ -384,7 +389,7 @@ export interface BaseLoadOptions {
* The available values in order of default preference are:
* "webgpu", "wgpu-webgl", "webgl", "canvas".
*
* @default null
* @default RenderBackend.Automatic
*/
preferredRenderer?: RenderBackend | null;

Expand Down
1 change: 1 addition & 0 deletions web/packages/extension/assets/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</div>
<div class="option select">
<select id="preferred_renderer">
<option value="">Automatic</option>
<option value="webgpu">WebGPU</option>
<option value="wgpu-webgl">Wgpu (via WebGL)</option>
<option value="webgl">WebGL</option>
Expand Down
8 changes: 5 additions & 3 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,9 +1428,11 @@ async fn create_renderer(

let mut renderer_list = vec!["webgpu", "wgpu-webgl", "webgl", "canvas"];
if let Some(preferred_renderer) = &config.preferred_renderer {
if let Some(pos) = renderer_list.iter().position(|&r| r == preferred_renderer) {
renderer_list.remove(pos);
renderer_list.insert(0, preferred_renderer.as_str());
if !preferred_renderer.is_empty() {
if let Some(pos) = renderer_list.iter().position(|&r| r == preferred_renderer) {
renderer_list.remove(pos);
renderer_list.insert(0, preferred_renderer.as_str());
}
}
}

Expand Down

0 comments on commit f4609d4

Please sign in to comment.