Merge pull request #8574 from eska014/html5-noglut

Remove GLUT usage in HTML5 platform
This commit is contained in:
Rémi Verschelde 2017-05-02 11:30:01 +02:00 committed by GitHub
commit 9bdc498f90
3 changed files with 27 additions and 75 deletions

View File

@ -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
*
*/

View File

@ -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];
@ -877,10 +881,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;

View File

@ -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;
@ -169,7 +163,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();
};