Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] [HTML5] Editor video driver option. Replace canvas on exit. #53991

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions misc/dist/html/editor.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<html xmlns="https://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
Expand Down Expand Up @@ -269,11 +269,6 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
<div id="tabs">
<div id="tab-loader">
<div style="color: #e0e0e0;" id="persistence">
<label for="videoMode" style="display: none;">Select video driver:</label><br />
<select id="videoMode" style="display: none;">
<option value="GLES2" selected="selected">WebGL</option>
<option value="GLES3">WebGL 2</option>
</select>
<br />
<img src="logo.svg" alt="Godot Engine logo" width="1024" height="414" style="width: auto; height: auto; max-width: 85%; max-height: 250px" />
<br />
Expand All @@ -283,6 +278,14 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
<br />
<br />
<br />
<label for="videoMode" style="margin-right: 1rem">Video driver:</label>
<select id="videoMode">
<option value="" selected="selected">Auto</option>
<option value="GLES2">WebGL</option>
<option value="GLES3">WebGL 2</option>
</select>
<br />
<br />
<label for="zip-file" style="margin-right: 1rem">Preload project ZIP:</label> <input id="zip-file" type="file" name="files" style="margin-bottom: 1rem"/>
<br />
<a href="demo.zip">(Try this for example)</a>
Expand Down Expand Up @@ -348,7 +351,7 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
var game = null;
var setStatusMode;
var setStatusNotice;
var video_driver = "GLES2";
var video_driver = "";

function clearPersistence() {
function deleteDB(path) {
Expand Down Expand Up @@ -479,6 +482,15 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
animationCallbacks.push(adjustCanvasDimensions);
adjustCanvasDimensions();

function replaceCanvas(from) {
const out = document.createElement("canvas");
out.id = from.id;
out.tabIndex = from.tabIndex;
from.parentNode.replaceChild(out, from);
lastScale = 0;
return out;
}

setStatusMode = function setStatusMode(mode) {
if (statusMode === mode || !initializing)
return;
Expand Down Expand Up @@ -534,6 +546,7 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
'canvas': gameCanvas,
'canvasResizePolicy': 1,
'onExit': function () {
gameCanvas = replaceCanvas(gameCanvas);
setGameTabEnabled(false);
showTab('editor');
game = null;
Expand All @@ -548,7 +561,7 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
const is_editor = args.filter(function(v) { return v == '--editor' || v == '-e' }).length != 0;
const is_project_manager = args.filter(function(v) { return v == '--project-manager' }).length != 0;
const is_game = !is_editor && !is_project_manager;
if (is_project_manager) {
if (video_driver) {
args.push('--video-driver', video_driver);
}
if (is_game) {
Expand All @@ -561,7 +574,7 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
showTab('game');
game.init().then(function() {
requestAnimationFrame(function() {
game.start({'args': args}).then(function() {
game.start({'args': args, 'canvas': gameCanvas}).then(function() {
gameCanvas.focus();
});
});
Expand All @@ -576,7 +589,7 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
showTab('loader');
setLoaderEnabled(true);
};
editor.start({'args': args, 'persistentDrops': is_project_manager});
editor.start({'args': args, 'persistentDrops': is_project_manager, 'canvas': editorCanvas});
});
}, 0);
OnEditorExit = null;
Expand All @@ -603,6 +616,7 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
'canvas': editorCanvas,
'canvasResizePolicy': 0,
'onExit': function() {
editorCanvas = replaceCanvas(editorCanvas);
if (OnEditorExit) {
OnEditorExit();
}
Expand Down Expand Up @@ -634,10 +648,14 @@ <h2 id="welcome-modal-title">Important - Please read before continuing</h2>
} catch(e) {
// File exists
}
//selectVideoMode();
selectVideoMode();
showTab('editor');
setLoaderEnabled(false);
editor.start({'args': ['--project-manager', '--video-driver', video_driver], 'persistentDrops': true}).then(function() {
const args = ['--project-manager'];
if (video_driver) {
args.push('--video-driver', video_driver);
}
editor.start({'args': args, 'persistentDrops': true}).then(function() {
setStatusMode('hidden');
initializing = false;
});
Expand Down
4 changes: 0 additions & 4 deletions platform/javascript/os_javascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,10 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
set_window_per_pixel_transparency_enabled(true);
}

#ifdef TOOLS_ENABLED
bool gles3 = false;
#else
bool gles3 = true;
if (p_video_driver == VIDEO_DRIVER_GLES2) {
gles3 = false;
}
#endif

bool gl_initialization_error = false;

Expand Down