From 0c83a7a3e99961db8758f9bd55d894a997ce8937 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 17 Jul 2020 07:50:40 +0200 Subject: [PATCH] scene: add a few safeguards for non-GL platforms. --- src/application/application.cpp | 4 +++- src/application/sdl-app.cpp | 13 ++++++++----- src/application/sdl-app.h | 3 ++- src/engine/ticker.cpp | 13 +++++++------ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/application/application.cpp b/src/application/application.cpp index 5446b2a7..86172490 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -59,7 +59,9 @@ std::shared_ptr app::init(char const *name, ivec2 res, float framerate) auto ret = std::make_shared(name, res); #endif - Scene::add_display(ret->get_display()); + if (engine::has_opengl()) + Scene::add_display(ret->get_display()); + return ret; } diff --git a/src/application/sdl-app.cpp b/src/application/sdl-app.cpp index c7117f92..1911ef21 100644 --- a/src/application/sdl-app.cpp +++ b/src/application/sdl-app.cpp @@ -37,8 +37,6 @@ namespace lol sdl::app::app(char const *title, ivec2 res) { #if LOL_USE_SDL - ivec2 window_size = res; - // Initialise SDL if (!SDL_WasInit(0)) { @@ -56,6 +54,9 @@ sdl::app::app(char const *title, ivec2 res) int flags = SDL_WINDOW_RESIZABLE; + if (res == ivec2(0)) + flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + if (engine::has_opengl()) { flags |= SDL_WINDOW_OPENGL; @@ -77,12 +78,10 @@ sdl::app::app(char const *title, ivec2 res) #endif } - if (window_size == ivec2(0)) - flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; msg::debug("initialising main window\n"); m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - window_size.x, window_size.y, flags); + res.x, res.y, flags); if (!m_window) { msg::error("cannot create rendering window: %s\n", SDL_GetError()); @@ -103,6 +102,10 @@ sdl::app::app(char const *title, ivec2 res) // Initialise everything video::init(res); //TODO ?? Should it be here ? } + else + { + m_renderer = SDL_CreateSoftwareRenderer(SDL_GetWindowSurface(m_window)); + } #if defined LOL_USE_XINPUT /* Prefer D3d9 for joysticks on Windows, because the X360 pads are not diff --git a/src/application/sdl-app.h b/src/application/sdl-app.h index aea0b891..1bf41f25 100644 --- a/src/application/sdl-app.h +++ b/src/application/sdl-app.h @@ -58,7 +58,8 @@ protected: private: #if LOL_USE_SDL - SDL_Window *m_window; + SDL_Window *m_window = nullptr; + SDL_Renderer *m_renderer = nullptr; SDL_GLContext m_glcontext; #endif }; diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index 2ab20a42..5eaf7e94 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -285,15 +285,16 @@ void ticker_data::GameThreadTick() { entity *e = data->DEPRECATED_m_todolist.back(); - //If the entity has no mask, default it - if (e->m_scene_mask == 0) + // If the entity has no mask, default it + // FIXME: what is this? + if (engine::has_opengl() && e->m_scene_mask == 0) { Scene::GetScene().Link(e); } data->DEPRECATED_m_todolist.pop_back(); data->DEPRECATED_m_list[(int)e->m_gamegroup].push_back(e); - if (e->m_drawgroup != tickable::group::draw::none) + if (engine::has_opengl() && e->m_drawgroup != tickable::group::draw::none) { if (data->DEPRECATED_m_scenes[(int)e->m_drawgroup].size() < Scene::GetCount()) data->DEPRECATED_m_scenes[(int)e->m_drawgroup].resize(Scene::GetCount()); @@ -393,8 +394,8 @@ void ticker_data::DrawThreadTick() } } - /* Render each scene one after the other */ - for (size_t idx = 0; idx < Scene::GetCount() && !data->m_quit /* Stop as soon as required */; ++idx) + // Render each scene one after the other + for (size_t idx = 0; engine::has_opengl() && idx < Scene::GetCount() && !data->m_quit /* Stop as soon as required */; ++idx) { Scene& scene = Scene::GetScene(idx); @@ -514,7 +515,7 @@ void ticker_data::collect_garbage() remove_at(DEPRECATED_m_list[g], i); // Draw group specific logic - if (g >= (int)tickable::group::game::end) + if (engine::has_opengl() && g >= (int)tickable::group::game::end) { int removal_count = 0; for (size_t j = 0; j < Scene::GetCount(); j++)