| @@ -758,12 +758,11 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("BtPhysTest", ivec2(1280, 960), 60.0f); | |||
| app app("BtPhysTest", ivec2(1280, 960), 60.0f); | |||
| new BtPhysTest(argc > 1); | |||
| app.ShowPointer(false); | |||
| app.Run(); | |||
| app.show_pointer(false); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -77,12 +77,11 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f); | |||
| app app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f); | |||
| new DebugFps(5, 5); | |||
| new Triangle(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -181,13 +181,12 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 2: Cube", ivec2(640, 480), 60.0f); | |||
| app app("Tutorial 2: Cube", ivec2(640, 480), 60.0f); | |||
| new DebugFps(5, 5); | |||
| new Cube(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -85,11 +85,10 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f); | |||
| app app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f); | |||
| new NoiseDemo(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -119,11 +119,10 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 4: Texture", ivec2(1280, 720), 60.0f); | |||
| app app("Tutorial 4: Texture", ivec2(1280, 720), 60.0f); | |||
| new TextureDemo(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -169,10 +169,9 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f); | |||
| app app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f); | |||
| new EasyMeshTutorial(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -102,10 +102,9 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 6: Sprite", ivec2(640, 480), 60.0f); | |||
| app app("Tutorial 6: Sprite", ivec2(640, 480), 60.0f); | |||
| new SpriteTutorial(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -207,13 +207,12 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 7: Input", ivec2(640, 480), 60.0f); | |||
| app app("Tutorial 7: Input", ivec2(640, 480), 60.0f); | |||
| new DebugFps(5, 5); | |||
| new InputTutorial(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -137,10 +137,9 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 08: Framebuffer Object", ivec2(512, 512), 60.0f); | |||
| app app("Tutorial 08: Framebuffer Object", ivec2(512, 512), 60.0f); | |||
| new FBO(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -107,10 +107,9 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 9: Sound", ivec2(640, 480), 60.0f); | |||
| app app("Tutorial 9: Sound", ivec2(640, 480), 60.0f); | |||
| new sound_demo(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -572,14 +572,13 @@ int main(int argc, char **argv) | |||
| ivec2 window_size(640, 480); | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 11: Fractal", window_size, 60.0f); | |||
| app app("Tutorial 11: Fractal", window_size, 60.0f); | |||
| new DebugFps(5, 5); | |||
| new Fractal(window_size); | |||
| //new DebugRecord("fractalol.ogm", 60.0f); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -402,11 +402,10 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 12: Jump Flooding Algorithm & Voronoi", ivec2(512, 512), 60.0f); | |||
| app app("Tutorial 12: Jump Flooding Algorithm & Voronoi", ivec2(512, 512), 60.0f); | |||
| new Voronoi(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine — Shader builder tutorial | |||
| // | |||
| // Copyright © 2002—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2002—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -121,11 +121,10 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 13: Shader Builder", ivec2(1280, 720), 60.0f); | |||
| app app("Tutorial 13: Shader Builder", ivec2(1280, 720), 60.0f); | |||
| new ShaderBuilderDemo(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -223,11 +223,11 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 14: Lolua Demo", ivec2(800, 600), 60.0f); | |||
| app app("Tutorial 14: Lolua Demo", ivec2(800, 600), 60.0f); | |||
| new LoluaDemo(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -98,11 +98,11 @@ int main(int argc, char **argv) | |||
| { | |||
| sys::init(argc, argv); | |||
| Application app("Tutorial 15: ImGui", ivec2(800, 600), 60.0f); | |||
| app app("Tutorial 15: ImGui", ivec2(800, 600), 60.0f); | |||
| new LolImGuiDemo(); | |||
| app.Run(); | |||
| app.run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -55,9 +55,9 @@ int main(int argc, char **argv) | |||
| { | |||
| lol::sys::init(argc, argv); | |||
| lol::Application app("Tutorial 17: HTTP", lol::ivec2(800, 600), 60.0f); | |||
| lol::app app("Tutorial 17: HTTP", lol::ivec2(800, 600), 60.0f); | |||
| new demo(); | |||
| app.Run(); | |||
| app.run(); | |||
| return 0; | |||
| } | |||
| @@ -79,7 +79,7 @@ liblol_core_sources = \ | |||
| easymesh/shinydebuglighting.lolfx easymesh/shinydebugnormal.lolfx \ | |||
| easymesh/shinydebugUV.lolfx easymesh/shiny_SK.lolfx \ | |||
| \ | |||
| base/assert.cpp base/log.cpp \ | |||
| base/assert.cpp base/engine.cpp base/log.cpp \ | |||
| \ | |||
| math/geometry.cpp \ | |||
| \ | |||
| @@ -34,168 +34,70 @@ | |||
| namespace lol | |||
| { | |||
| class null_display | |||
| { | |||
| friend class ApplicationDisplayData; | |||
| friend class ApplicationDisplay; | |||
| public: | |||
| null_display(char const *, ivec2) {} | |||
| virtual ~null_display() {} | |||
| protected: | |||
| ivec2 resolution() const { return ivec2(0); } | |||
| void set_resolution(ivec2) {} | |||
| void SetPosition(ivec2) {} | |||
| }; | |||
| class null_app | |||
| { | |||
| public: | |||
| null_app(char const *, ivec2, float) | |||
| { | |||
| msg::error("no display library (SDL, EGL…) available"); | |||
| assert(false); | |||
| } | |||
| virtual ~null_app() {} | |||
| void ShowPointer(bool) {} | |||
| void Tick() {} | |||
| }; | |||
| class ApplicationDisplayData | |||
| { | |||
| friend class ApplicationDisplay; | |||
| ApplicationDisplayData(char const *name, ivec2 res) | |||
| : display(name, res) | |||
| { } | |||
| protected: | |||
| #if __ANDROID__ | |||
| // TODO: implement this | |||
| null_display display; | |||
| #elif __NX__ | |||
| nx::app_display display; | |||
| #elif LOL_USE_SDL | |||
| sdl::app_display display; | |||
| #elif HAVE_GLES_2X | |||
| // FIXME: this macro is only deactivated if we include "lolgl.h" | |||
| //NOT HANDLED YET | |||
| #else | |||
| null_display display; | |||
| #if __EMSCRIPTEN__ | |||
| static app *g_app; | |||
| static void AppCallback() { g_app->Tick(); } | |||
| #endif | |||
| }; | |||
| ApplicationDisplay::ApplicationDisplay(char const *name, ivec2 res) | |||
| { | |||
| data = new ApplicationDisplayData(name, res); | |||
| } | |||
| ApplicationDisplay::~ApplicationDisplay() | |||
| { | |||
| delete data; | |||
| } | |||
| ivec2 ApplicationDisplay::resolution() const | |||
| { | |||
| return data->display.resolution(); | |||
| } | |||
| void ApplicationDisplay::set_resolution(ivec2 res) | |||
| { | |||
| data->display.set_resolution(res); | |||
| } | |||
| void ApplicationDisplay::SetPosition(ivec2 position) | |||
| { | |||
| data->display.SetPosition(position); | |||
| } | |||
| void ApplicationDisplay::start_frame() | |||
| { | |||
| data->display.start_frame(); | |||
| } | |||
| void ApplicationDisplay::end_frame() | |||
| { | |||
| data->display.end_frame(); | |||
| } | |||
| // | |||
| // Public app class | |||
| // | |||
| class ApplicationData | |||
| app::app(char const *name, ivec2 res, float framerate) | |||
| { | |||
| friend class Application; | |||
| ticker::setup(framerate); | |||
| ApplicationData(char const *name, ivec2 res, float framerate) | |||
| : app(name, res, framerate) | |||
| { } | |||
| // FIXME: this should probably be a call to e.g. nx::app::init() which | |||
| // creates the proper shared pointers. | |||
| #if __ANDROID__ | |||
| AndroidApp app; | |||
| // TODO: implement m_display | |||
| m_data = std::make_shared<AndroidAppData>(name, res, framerate); | |||
| #elif __NX__ | |||
| nx::app app; | |||
| m_display = std::make_shared<nx::app_display>(name, res); | |||
| m_data = std::make_shared<nx::app_data>(name, m_display->resolution(), framerate); | |||
| #elif LOL_USE_SDL | |||
| sdl::app app; | |||
| m_display = std::make_shared<sdl::app_display>(name, res); | |||
| m_data = std::make_shared<sdl::app_data>(name, m_display->resolution(), framerate); | |||
| #elif HAVE_GLES_2X | |||
| // FIXME: this macro is only deactivated if we include "lolgl.h" | |||
| EglApp app; | |||
| #else | |||
| null_app app; | |||
| //NOT HANDLED YET | |||
| m_data = std::make_shared<EglAppData>(name, res, framerate); | |||
| #endif | |||
| }; | |||
| #if __EMSCRIPTEN__ | |||
| static Application *g_app; | |||
| static void AppCallback() | |||
| { | |||
| g_app->Tick(); | |||
| Scene::add_display(m_display); | |||
| } | |||
| #endif | |||
| // | |||
| // Public Application class | |||
| // | |||
| Application::Application(char const *name, ivec2 res, float framerate) | |||
| app::~app() | |||
| { | |||
| ticker::setup(framerate); | |||
| auto app_display = new ApplicationDisplay(name, res); | |||
| Scene::add_display(app_display); | |||
| data = new ApplicationData(name, app_display->resolution(), framerate); | |||
| ticker::teardown(); | |||
| } | |||
| bool Application::MustTick() | |||
| bool app::must_tick() | |||
| { | |||
| return !Ticker::Finished(); | |||
| return !ticker::Finished(); | |||
| } | |||
| void Application::Tick() | |||
| void app::tick() | |||
| { | |||
| data->app.Tick(); | |||
| if (m_data) | |||
| m_data->tick(); | |||
| } | |||
| void Application::Run() | |||
| void app::run() | |||
| { | |||
| #if __EMSCRIPTEN__ | |||
| g_app = this; | |||
| emscripten_set_main_loop(AppCallback, 0, 1); | |||
| #else | |||
| while (MustTick()) | |||
| Tick(); | |||
| while (must_tick()) | |||
| tick(); | |||
| #endif | |||
| } | |||
| void Application::ShowPointer(bool show) | |||
| void app::show_pointer(bool show) | |||
| { | |||
| data->app.ShowPointer(show); | |||
| } | |||
| Application::~Application() | |||
| { | |||
| ticker::teardown(); | |||
| delete data; | |||
| if (m_data) | |||
| m_data->show_pointer(show); | |||
| } | |||
| } // namespace lol | |||
| @@ -1,64 +1,70 @@ | |||
| // | |||
| // Lol Engine | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #pragma once | |||
| #include <memory> // std::shared_ptr | |||
| // | |||
| // The Application class | |||
| // --------------------- | |||
| // The app class | |||
| // ————————————— | |||
| // | |||
| namespace lol | |||
| { | |||
| class ApplicationDisplayData; | |||
| class ApplicationDisplay | |||
| class app | |||
| { | |||
| friend class Scene; | |||
| public: | |||
| ApplicationDisplay(char const *name, ivec2 resolution); | |||
| virtual ~ApplicationDisplay(); | |||
| virtual void start_frame(); | |||
| virtual void end_frame(); | |||
| app(char const *name, ivec2 resolution, float framerate); | |||
| ~app(); | |||
| // pos/size/... methods | |||
| virtual void set_resolution(ivec2 resolution); | |||
| virtual ivec2 resolution() const; | |||
| bool must_tick(); | |||
| void tick(); | |||
| void run(); | |||
| virtual void SetPosition(ivec2 position); | |||
| // UI interface | |||
| void show_pointer(bool show); | |||
| private: | |||
| ApplicationDisplayData *data; | |||
| }; | |||
| // Display interface | |||
| class display | |||
| { | |||
| public: | |||
| virtual ~display() {} | |||
| virtual void start_frame() {} | |||
| virtual void end_frame() {} | |||
| class ApplicationData; | |||
| // pos/size/... methods | |||
| virtual void set_resolution(ivec2 resolution) {} | |||
| virtual ivec2 resolution() const { return ivec2(0); } | |||
| class Application | |||
| { | |||
| public: | |||
| Application(char const *name, ivec2 resolution, float framerate); | |||
| ~Application(); | |||
| virtual void set_position(ivec2 position) {} | |||
| }; | |||
| bool MustTick(); | |||
| void Tick(); | |||
| void Run(); | |||
| // Internal data | |||
| class data | |||
| { | |||
| public: | |||
| data() {} | |||
| virtual ~data() {} | |||
| void ShowPointer(bool show); | |||
| virtual void show_pointer(bool show) {} | |||
| virtual void tick() {} | |||
| }; | |||
| private: | |||
| ApplicationData *data; | |||
| std::shared_ptr<display> m_display; | |||
| std::shared_ptr<data> m_data; | |||
| }; | |||
| } // namespace lol | |||
| @@ -43,7 +43,7 @@ namespace lol | |||
| class EglAppData | |||
| { | |||
| friend class EglApp; | |||
| friend class app_data; | |||
| private: | |||
| #if defined LOL_USE_EGL && !defined __ANDROID__ | |||
| @@ -61,11 +61,10 @@ private: | |||
| }; | |||
| /* | |||
| * Public EglApp class | |||
| * Public app_data class | |||
| */ | |||
| EglApp::EglApp(char const *title, ivec2 res, float fps) : | |||
| data(new EglAppData()) | |||
| egl::app_data::app_data(char const *title, ivec2 res, float fps) | |||
| { | |||
| #if defined LOL_USE_EGL && !defined __ANDROID__ | |||
| # if defined HAVE_BCM_HOST_H | |||
| @@ -258,13 +257,13 @@ EglApp::EglApp(char const *title, ivec2 res, float fps) : | |||
| (void)fps; | |||
| } | |||
| void EglApp::ShowPointer(bool show) | |||
| void egl::app_data::show_pointer(bool show) | |||
| { | |||
| /* FIXME: unimplemented (do we have a mouse pointer anyway? */ | |||
| (void)show; | |||
| } | |||
| void EglApp::Tick() | |||
| void egl::app_data::tick() | |||
| { | |||
| /* Tick the renderer, show the frame and clamp to desired framerate. */ | |||
| ticker::tick_draw(); | |||
| @@ -273,7 +272,7 @@ void EglApp::Tick() | |||
| #endif | |||
| } | |||
| EglApp::~EglApp() | |||
| egl::app_data::~app_data() | |||
| { | |||
| #if defined LOL_USE_EGL && !defined __ANDROID__ | |||
| eglDestroyContext(data->egl_dpy, data->egl_ctx); | |||
| @@ -286,7 +285,6 @@ EglApp::~EglApp() | |||
| XCloseDisplay(data->dpy); | |||
| # endif | |||
| #endif | |||
| delete data; | |||
| } | |||
| } /* namespace lol */ | |||
| @@ -19,23 +19,19 @@ | |||
| #include <lol/vector> | |||
| namespace lol | |||
| { | |||
| #include "application/application.h" | |||
| class EglAppData; | |||
| namespace lol::egl | |||
| { | |||
| class EglApp | |||
| class app_data : public app::data | |||
| { | |||
| public: | |||
| EglApp(char const *title, ivec2 res, float fps); | |||
| virtual ~EglApp(); | |||
| app_data(char const *title, ivec2 res, float fps); | |||
| virtual ~app_data(); | |||
| void ShowPointer(bool show); | |||
| void Tick(); | |||
| private: | |||
| EglAppData *data; | |||
| void show_pointer(bool show); | |||
| void tick(); | |||
| }; | |||
| } /* namespace lol */ | |||
| } // namespace lol | |||
| @@ -54,23 +54,29 @@ sdl::app_display::app_display(char const *title, ivec2 res) | |||
| for (int i = 0; i < SDL_GetNumVideoDisplays(); ++i) | |||
| msg::debug("%d: %s\n", i, SDL_GetDisplayName(i)); | |||
| // 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); | |||
| int flags = SDL_WINDOW_RESIZABLE; | |||
| if (engine::has_opengl()) | |||
| { | |||
| flags |= SDL_WINDOW_OPENGL; | |||
| // 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); | |||
| #if !defined __EMSCRIPTEN__ && !defined HAVE_GLES_2X | |||
| // Ask for GL 3.2 at least | |||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | |||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); | |||
| // Ask for GL 3.2 at least | |||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | |||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); | |||
| #if __APPLE__ | |||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); | |||
| SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); | |||
| #endif | |||
| #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 | |||
| } | |||
| int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | |||
| if (window_size == ivec2(0)) | |||
| flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | |||
| msg::debug("initialising main window\n"); | |||
| @@ -88,12 +94,15 @@ sdl::app_display::app_display(char const *title, ivec2 res) | |||
| // Enable drag-and-drop | |||
| SDL_EventState(SDL_DROPFILE, SDL_ENABLE); | |||
| m_glcontext = SDL_GL_CreateContext(m_window); | |||
| SDL_GL_MakeCurrent(m_window, m_glcontext); | |||
| msg::info("created GL context: %s\n", glGetString(GL_VERSION)); | |||
| if (engine::has_opengl()) | |||
| { | |||
| m_glcontext = SDL_GL_CreateContext(m_window); | |||
| SDL_GL_MakeCurrent(m_window, m_glcontext); | |||
| msg::info("created GL context: %s\n", glGetString(GL_VERSION)); | |||
| /* Initialise everything */ | |||
| Video::Setup(res); //TODO ?? Should it be here ? | |||
| // Initialise everything | |||
| Video::Setup(res); //TODO ?? Should it be here ? | |||
| } | |||
| #endif | |||
| } | |||
| @@ -102,7 +111,9 @@ sdl::app_display::~app_display() | |||
| #if LOL_USE_SDL | |||
| if (m_window) | |||
| { | |||
| SDL_GL_DeleteContext(m_glcontext); | |||
| if (engine::has_opengl()) | |||
| SDL_GL_DeleteContext(m_glcontext); | |||
| SDL_DestroyWindow(m_window); | |||
| } | |||
| #endif | |||
| @@ -124,7 +135,7 @@ void sdl::app_display::set_resolution(ivec2 resolution) | |||
| #endif | |||
| } | |||
| void sdl::app_display::SetPosition(ivec2 position) | |||
| void sdl::app_display::set_position(ivec2 position) | |||
| { | |||
| #if LOL_USE_SDL | |||
| SDL_SetWindowPosition(m_window, position.x, position.y); | |||
| @@ -135,14 +146,16 @@ void sdl::app_display::start_frame() | |||
| { | |||
| #if LOL_USE_SDL | |||
| //TODO: Should we do that: ? | |||
| SDL_GL_MakeCurrent(m_window, m_glcontext); | |||
| if (engine::has_opengl()) | |||
| SDL_GL_MakeCurrent(m_window, m_glcontext); | |||
| #endif | |||
| } | |||
| void sdl::app_display::end_frame() | |||
| { | |||
| #if LOL_USE_SDL | |||
| SDL_GL_SwapWindow(m_window); | |||
| if (engine::has_opengl()) | |||
| SDL_GL_SwapWindow(m_window); | |||
| #endif | |||
| } | |||
| @@ -150,7 +163,7 @@ void sdl::app_display::end_frame() | |||
| // Public sdl::app class | |||
| // | |||
| sdl::app::app(char const *title, ivec2 res, float fps) | |||
| sdl::app_data::app_data(char const *title, ivec2 res, float fps) | |||
| { | |||
| (void)title; | |||
| #if LOL_USE_SDL | |||
| @@ -170,25 +183,24 @@ sdl::app::app(char const *title, ivec2 res, float fps) | |||
| #endif | |||
| } | |||
| void sdl::app::ShowPointer(bool show) | |||
| sdl::app_data::~app_data() | |||
| { | |||
| #if LOL_USE_SDL | |||
| SDL_ShowCursor(show ? 1 : 0); | |||
| SDL_Quit(); | |||
| #endif | |||
| } | |||
| void sdl::app::Tick() | |||
| { | |||
| /* Tick the renderer, show the frame and clamp to desired framerate. */ | |||
| Ticker::tick_draw(); | |||
| } | |||
| sdl::app::~app() | |||
| void sdl::app_data::show_pointer(bool show) | |||
| { | |||
| #if LOL_USE_SDL | |||
| SDL_Quit(); | |||
| SDL_ShowCursor(show ? 1 : 0); | |||
| #endif | |||
| } | |||
| } /* namespace lol */ | |||
| void sdl::app_data::tick() | |||
| { | |||
| // Tick the renderer, show the frame and clamp to desired framerate. | |||
| ticker::tick_draw(); | |||
| } | |||
| } // namespace lol | |||
| @@ -19,6 +19,8 @@ | |||
| #include <lol/vector> | |||
| #include "application/application.h" | |||
| #if LOL_USE_SDL | |||
| # if HAVE_SDL2_SDL_H | |||
| # include <SDL2/SDL.h> | |||
| @@ -30,32 +32,30 @@ | |||
| namespace lol::sdl | |||
| { | |||
| class app | |||
| class app_data : public lol::app::data | |||
| { | |||
| public: | |||
| app(char const *title, ivec2 res, float fps); | |||
| virtual ~app(); | |||
| app_data(char const *title, ivec2 res, float fps); | |||
| virtual ~app_data(); | |||
| void ShowPointer(bool show); | |||
| void Tick(); | |||
| virtual void show_pointer(bool show); | |||
| virtual void tick(); | |||
| }; | |||
| class app_display | |||
| class app_display : public lol::app::display | |||
| { | |||
| friend class lol::ApplicationDisplay; | |||
| public: | |||
| app_display(char const *title, ivec2 resolution); | |||
| virtual ~app_display(); | |||
| protected: | |||
| void start_frame(); | |||
| void end_frame(); | |||
| virtual void set_resolution(ivec2 resolution); | |||
| virtual ivec2 resolution() const; | |||
| void SetPosition(ivec2 position); | |||
| void start_frame(); | |||
| void end_frame(); | |||
| void set_position(ivec2 position); | |||
| private: | |||
| #if LOL_USE_SDL | |||
| @@ -0,0 +1,30 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #include <lol/engine-internal.h> | |||
| #include "lolgl.h" | |||
| namespace lol::engine | |||
| { | |||
| bool has_opengl() | |||
| { | |||
| #if defined LOL_USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLES_2X | |||
| return true; | |||
| #else | |||
| return false; | |||
| #endif | |||
| } | |||
| } // namespace lol::engine | |||
| @@ -108,6 +108,7 @@ | |||
| <ClCompile Include="audio\sample.cpp" /> | |||
| <ClCompile Include="camera.cpp" /> | |||
| <ClCompile Include="base\assert.cpp" /> | |||
| <ClCompile Include="base\engine.cpp" /> | |||
| <ClCompile Include="base\log.cpp" /> | |||
| <ClCompile Include="debug\fps.cpp" /> | |||
| <ClCompile Include="debug\lines.cpp" /> | |||
| @@ -14,6 +14,9 @@ | |||
| <ClCompile Include="base\assert.cpp"> | |||
| <Filter>base</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="base\engine.cpp"> | |||
| <Filter>base</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="base\log.cpp"> | |||
| <Filter>base</Filter> | |||
| </ClCompile> | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -17,26 +17,10 @@ | |||
| // ---------------------------------------------- | |||
| // | |||
| /* Include this as early as possible */ | |||
| // Include this as early as possible | |||
| #if HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| /* If using Android, override main() with our version */ | |||
| #if __ANDROID__ | |||
| # define main lol_android_main | |||
| #endif | |||
| /* If using SDL on Windows or OS X, let it override main() */ | |||
| #if LOL_USE_SDL && (_WIN32 || __APPLE__) | |||
| # include <SDL_main.h> | |||
| #endif | |||
| #include <lol/public.h> | |||
| #include <lol/extras.h> | |||
| #if defined _WIN32 | |||
| # undef near | |||
| # undef far | |||
| #endif | |||
| #include "engine.h" | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -17,7 +17,7 @@ | |||
| // -------------------------------------- | |||
| // | |||
| /* If using Android, override main() with our version */ | |||
| // If using Android, override main() with our version | |||
| #if __ANDROID__ | |||
| # define main lol_android_main | |||
| #endif | |||
| @@ -27,11 +27,18 @@ | |||
| # define main lol_nx_main | |||
| #endif | |||
| /* If using SDL on Windows or OS X, let it override main() */ | |||
| // If using SDL on Windows or OS X, let it override main() | |||
| #if LOL_USE_SDL && (_WIN32 || __APPLE__) | |||
| # include <SDL_main.h> | |||
| #endif | |||
| namespace lol::engine | |||
| { | |||
| bool has_opengl(); | |||
| } | |||
| #include <lol/public.h> | |||
| #include <lol/extras.h> | |||
| @@ -44,7 +44,7 @@ namespace lol | |||
| std::vector<Scene*> Scene::g_scenes; | |||
| static std::vector<ApplicationDisplay*> g_scene_displays; | |||
| static std::vector<std::shared_ptr<app::display>> g_scene_displays; | |||
| static inline void gpu_marker(char const *message) | |||
| { | |||
| @@ -137,12 +137,12 @@ Scene::~Scene() | |||
| Reset(); | |||
| } | |||
| void Scene::add_display(ApplicationDisplay* display) | |||
| void Scene::add_display(std::shared_ptr<app::display> display) | |||
| { | |||
| g_scene_displays.push_back(display); | |||
| } | |||
| ApplicationDisplay *Scene::get_display(int index) | |||
| std::shared_ptr<app::display> Scene::get_display(int index) | |||
| { | |||
| return g_scene_displays[index]; | |||
| } | |||
| @@ -79,8 +79,8 @@ private: | |||
| public: | |||
| static size_t GetCount(); | |||
| static void add_display(ApplicationDisplay* display); | |||
| static ApplicationDisplay* get_display(int index = 0); | |||
| static void add_display(std::shared_ptr<app::display> display); | |||
| static std::shared_ptr<app::display> get_display(int index = 0); | |||
| static bool IsReady(int index = 0); | |||
| static Scene& GetScene(int index = 0); | |||