| @@ -1,7 +1,7 @@ | |||||
| // | // | ||||
| // Lol Engine | // Lol Engine | ||||
| // | // | ||||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // | // | ||||
| // Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
| // the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
| @@ -41,6 +41,7 @@ sdl::app_display::app_display(char const *title, ivec2 res) | |||||
| /* Initialise SDL */ | /* Initialise SDL */ | ||||
| if (!SDL_WasInit(0)) | if (!SDL_WasInit(0)) | ||||
| { | { | ||||
| msg::debug("initialising SDL\n"); | |||||
| if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) < 0) | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) < 0) | ||||
| { | { | ||||
| msg::error("cannot initialise SDL: %s\n", SDL_GetError()); | msg::error("cannot initialise SDL: %s\n", SDL_GetError()); | ||||
| @@ -51,18 +52,20 @@ sdl::app_display::app_display(char const *title, ivec2 res) | |||||
| // This seems to fix a bug we used to have at context swap. Maybe remove one day. | // This seems to fix a bug we used to have at context swap. Maybe remove one day. | ||||
| SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); | SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); | ||||
| #if 0 | |||||
| #if !defined __EMSCRIPTEN__ | |||||
| // Ask for GL 3.2 at least | // Ask for GL 3.2 at least | ||||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | ||||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); | ||||
| #endif | |||||
| #if LOL_BUILD_DEBUG | #if LOL_BUILD_DEBUG | ||||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); | SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); | ||||
| #endif | |||||
| #endif | #endif | ||||
| int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | ||||
| if (window_size == ivec2(0)) | if (window_size == ivec2(0)) | ||||
| flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | ||||
| msg::debug("initialising main window\n"); | |||||
| m_window = SDL_CreateWindow(title, | m_window = SDL_CreateWindow(title, | ||||
| SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, | SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, | ||||
| window_size.x, window_size.y, flags); | window_size.x, window_size.y, flags); | ||||
| @@ -75,6 +78,7 @@ sdl::app_display::app_display(char const *title, ivec2 res) | |||||
| SDL_GetWindowSize(m_window, &res.x, &res.y); | SDL_GetWindowSize(m_window, &res.x, &res.y); | ||||
| m_glcontext = SDL_GL_CreateContext(m_window); | m_glcontext = SDL_GL_CreateContext(m_window); | ||||
| SDL_GL_MakeCurrent(m_window, m_glcontext); | |||||
| msg::info("created GL context: %s\n", glGetString(GL_VERSION)); | msg::info("created GL context: %s\n", glGetString(GL_VERSION)); | ||||
| /* Initialise everything */ | /* Initialise everything */ | ||||
| @@ -1,7 +1,7 @@ | |||||
| // | // | ||||
| // Lol Engine | // Lol Engine | ||||
| // | // | ||||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // | // | ||||
| // Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
| // the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
| @@ -19,6 +19,11 @@ bool has_threads() | |||||
| { | { | ||||
| static char const *var = getenv("LOL_NOTHREADS"); | static char const *var = getenv("LOL_NOTHREADS"); | ||||
| static bool const disable_threads = var && var[0]; | static bool const disable_threads = var && var[0]; | ||||
| #if defined __EMSCRIPTEN__ && !defined __EMSCRIPTEN_PTHREADS__ | |||||
| // For some reason hardware_concurrency() will return the actual number | |||||
| // of threads/cores even though the system cannot spawn threads. | |||||
| return false; | |||||
| #endif | |||||
| return !disable_threads && std::thread::hardware_concurrency() > 1; | return !disable_threads && std::thread::hardware_concurrency() > 1; | ||||
| } | } | ||||
| @@ -1,7 +1,7 @@ | |||||
| // | // | ||||
| // Lol Engine | // Lol Engine | ||||
| // | // | ||||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // | // | ||||
| // Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
| // the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
| @@ -30,6 +30,7 @@ class ticker_data | |||||
| public: | public: | ||||
| ticker_data() | ticker_data() | ||||
| { | { | ||||
| msg::debug("platform %s threads\n", has_threads() ? "has" : "has no"); | |||||
| if (has_threads()) | if (has_threads()) | ||||
| { | { | ||||
| gamethread = std::make_unique<thread>(std::bind(&ticker_data::GameThreadMain, this)); | gamethread = std::make_unique<thread>(std::bind(&ticker_data::GameThreadMain, this)); | ||||
| @@ -557,6 +558,7 @@ void Ticker::SetStateWhenMatch(entity * /* entity */, uint32_t /* state */, | |||||
| void ticker::setup(float fps) | void ticker::setup(float fps) | ||||
| { | { | ||||
| msg::debug("creating ticker\n"); | |||||
| data = std::make_unique<ticker_data>(); | data = std::make_unique<ticker_data>(); | ||||
| data->fps = fps; | data->fps = fps; | ||||
| } | } | ||||
| @@ -1,7 +1,7 @@ | |||||
| // | // | ||||
| // Lol Engine | // Lol Engine | ||||
| // | // | ||||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // | // | ||||
| // Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
| // the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
| @@ -17,7 +17,7 @@ | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| #if LOL_BUILD_DEBUG | |||||
| #if LOL_BUILD_DEBUG && !defined __EMSCRIPTEN__ | |||||
| static std::map<GLenum, char const *> gl_dbg_source_to_str | static std::map<GLenum, char const *> gl_dbg_source_to_str | ||||
| { | { | ||||
| { GL_DEBUG_SOURCE_API, "API" }, | { GL_DEBUG_SOURCE_API, "API" }, | ||||
| @@ -88,7 +88,7 @@ static void LOL_ATTR_STDCALL | |||||
| void gpu::setup_debug() | void gpu::setup_debug() | ||||
| { | { | ||||
| #if LOL_BUILD_DEBUG | |||||
| #if LOL_BUILD_DEBUG && !defined __EMSCRIPTEN__ | |||||
| GLint glflags; | GLint glflags; | ||||
| glGetIntegerv(GL_CONTEXT_FLAGS, &glflags); | glGetIntegerv(GL_CONTEXT_FLAGS, &glflags); | ||||
| @@ -14,6 +14,13 @@ | |||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| // FIXME: can we make this more generic? | |||||
| #if defined __EMSCRIPTEN__ | |||||
| #define glGenVertexArrays glGenVertexArraysOES | |||||
| #define glBindVertexArray glBindVertexArrayOES | |||||
| #define glDeleteVertexArrays glDeleteVertexArraysOES | |||||
| #endif | |||||
| // FIXME: fine-tune this define | // FIXME: fine-tune this define | ||||
| #if defined LOL_USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLES_2X | #if defined LOL_USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLES_2X | ||||