summaryrefslogtreecommitdiff
path: root/platform/javascript
diff options
context:
space:
mode:
authorL. Krause <eska@eska.me>2017-04-27 15:34:46 +0200
committerL. Krause <eska@eska.me>2017-04-28 21:54:44 +0200
commit847bd33fdf3e188e82696382bf41394dbf5c76f6 (patch)
tree4bfeeaf1590a0b2938b57884d747745587f54d88 /platform/javascript
parent5993a5fac9a108297fc7909d1a38abac471d037d (diff)
Remove GLUT usage in HTML5 platform
Diffstat (limited to 'platform/javascript')
-rw-r--r--platform/javascript/javascript_main.cpp76
-rw-r--r--platform/javascript/os_javascript.cpp18
-rw-r--r--platform/javascript/os_javascript.h8
3 files changed, 27 insertions, 75 deletions
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index e122bb2e4d..6b1d574496 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -31,94 +31,50 @@
#include "io/resource_loader.h"
#include "main/main.h"
#include "os_javascript.h"
-#include <GL/glut.h>
-#include <string.h>
OS_JavaScript *os = NULL;
-static void _gfx_init(void *ud, bool gl2, int w, int h, bool fs) {
+static void main_loop() {
- glutInitWindowSize(w, h);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutCreateWindow("godot");
+ os->main_loop_iterate();
}
-static void _gfx_idle() {
+extern "C" void main_after_fs_sync() {
- glutPostRedisplay();
-}
-
-int start_step = 0;
-
-static void _godot_draw(void) {
-
- if (start_step == 1) {
- start_step = 2;
- Main::start();
- os->main_loop_begin();
- }
-
- if (start_step == 2) {
- os->main_loop_iterate();
- }
-
- glutSwapBuffers();
-}
-
-extern "C" {
-
-void main_after_fs_sync() {
-
- start_step = 1;
-}
+ // Ease up compatibility
+ ResourceLoader::set_abort_on_missing_resources(false);
+ Main::start();
+ os->main_loop_begin();
+ emscripten_set_main_loop(main_loop, 0, false);
}
int main(int argc, char *argv[]) {
- /* Initialize the window */
printf("let it go dude!\n");
- glutInit(&argc, argv);
- os = new OS_JavaScript(argv[0], _gfx_init, NULL, NULL);
-
- Error err = Main::setup(argv[0], argc - 1, &argv[1]);
-
- ResourceLoader::set_abort_on_missing_resources(false); //ease up compatibility
-
- /* Set up glut callback functions */
- glutIdleFunc(_gfx_idle);
- // glutReshapeFunc(gears_reshape);
- glutDisplayFunc(_godot_draw);
- //glutSpecialFunc(gears_special);
- //mount persistent file system
+ // sync from persistent state into memory and then
+ // run the 'main_after_fs_sync' function
/* clang-format off */
EM_ASM(
+ Module.noExitRuntime = true;
FS.mkdir('/userfs');
FS.mount(IDBFS, {}, '/userfs');
-
- // sync from persistent state into memory and then
- // run the 'main_after_fs_sync' function
FS.syncfs(true, function(err) {
-
if (err) {
Module.setStatus('Failed to load persistent data\nPlease allow (third-party) cookies');
Module.printErr('Failed to populate IDB file system: ' + err.message);
- Module.exit();
+ Module.noExitRuntime = false;
} else {
Module.print('Successfully populated IDB file system');
- ccall('main_after_fs_sync', 'void', []);
+ ccall('main_after_fs_sync', null);
}
});
);
/* clang-format on */
- glutMainLoop();
+ os = new OS_JavaScript(argv[0], NULL);
+ Error err = Main::setup(argv[0], argc - 1, &argv[1]);
return 0;
+ // continued async in main_after_fs_sync() from syncfs() callback
}
-
-/*
- *
- *09] <azakai|2__> reduz: yes, define TOTAL_MEMORY on Module. for example var Module = { TOTAL_MEMORY: 12345.. }; before the main
- *
- */
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 7d073654ce..f42376e104 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -390,14 +390,18 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
print_line("Init OS");
- if (gfx_init_func)
- gfx_init_func(gfx_init_ud, use_gl2, p_desired.width, p_desired.height, p_desired.fullscreen);
+ EmscriptenWebGLContextAttributes attributes;
+ emscripten_webgl_init_context_attributes(&attributes);
+ attributes.alpha = false;
+ attributes.antialias = false;
+ attributes.majorVersion = 2;
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(NULL, &attributes);
+ ERR_FAIL_COND(emscripten_webgl_make_context_current(ctx) != EMSCRIPTEN_RESULT_SUCCESS);
- // nothing to do here, can't fulfil fullscreen request due to
- // browser security, window size is already set from HTML
video_mode = p_desired;
+ // can't fulfil fullscreen request due to browser security
video_mode.fullscreen = false;
- _windowed_size = get_window_size();
+ set_window_size(Size2(p_desired.width, p_desired.height));
// find locale, emscripten only sets "C"
char locale_ptr[16];
@@ -835,10 +839,8 @@ int OS_JavaScript::get_power_percent_left() {
return power_manager->get_power_percent_left();
}
-OS_JavaScript::OS_JavaScript(const char *p_execpath, GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func) {
+OS_JavaScript::OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_dir_func) {
set_cmdline(p_execpath, get_cmdline_args());
- gfx_init_func = p_gfx_init_func;
- gfx_init_ud = p_gfx_init_ud;
main_loop = NULL;
gl_extensions = NULL;
window_maximized = false;
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 0c956ecba6..dfc1a43226 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -45,16 +45,10 @@
#include <emscripten/html5.h>
-typedef void (*GFXInitFunc)(void *ud, bool gl2, int w, int h, bool fs);
typedef String (*GetDataDirFunc)();
class OS_JavaScript : public OS_Unix {
- GFXInitFunc gfx_init_func;
- void *gfx_init_ud;
-
- bool use_gl2;
-
int64_t time_to_save_sync;
int64_t last_sync_time;
@@ -167,7 +161,7 @@ public:
virtual int get_power_seconds_left();
virtual int get_power_percent_left();
- OS_JavaScript(const char *p_execpath, GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func);
+ OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_dir_func);
~OS_JavaScript();
};