diff --git a/demo/main.cpp b/demo/main.cpp index 0fc4475731a419efc5c4305dc7ab709917bc1378..962435002529102aa2b5e7ffbebe585e3cb9d572 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -6,6 +6,8 @@ #include <fggl/gfx/window.hpp> #include <fggl/gfx/camera.hpp> + +#include <fggl/gfx/compat.hpp> #include <fggl/gfx/ogl/compat.hpp> #include <fggl/data/procedural.hpp> @@ -170,16 +172,16 @@ void process_freecam(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, fggl::gfx:: } int main(int argc, char* argv[]) { - fggl::gfx::Context ctx; + // setup ECS + fggl::ecs::ECS ecs; // build our main window + auto glfwModule = fggl::gfx::ecsInitGlfw(ecs); + fggl::gfx::Window win( fggl::gfx::Input::instance() ); win.title("FGGL Demo"); win.fullscreen( true ); - // setup ECS - fggl::ecs::ECS ecs; - // storage API fggl::data::Storage storage; discover( storage.resolvePath(fggl::data::Data, "res") ); @@ -260,7 +262,7 @@ int main(int argc, char* argv[]) { while( !win.closeRequested() ) { input.frame(); - ctx.pollEvents(); + glfwModule->context.pollEvents(); debug.frameStart(); // update step diff --git a/fggl/gfx/compat.hpp b/fggl/gfx/compat.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bc40713b576c27796915ac4c20e20884cc997a94 --- /dev/null +++ b/fggl/gfx/compat.hpp @@ -0,0 +1,43 @@ +#ifndef FGGL_GFX_GLFW_COMPAT_H +#define FGGL_GFX_GLFW_COMPAT_H +/** + * Window management Calls. + * + * This shouldn't be exposed to the demo app, but the ECS we're using isn't smart enouph to allow us to + * abstract this yet. It's next thing on the list, but this branch is about cleaning up OpenGL not about + * extending our ECS. + * + * Should be removed when the engine has suitable abstractions in place. + */ + +#include <memory> + +#include <fggl/gfx/window.hpp> +#include <fggl/ecs/ecs.hpp> + +namespace fggl::gfx { + + // + // fake module support - allows us to still RAII + // + struct ecsGlfwModule { + GlfwContext context; + + inline ecsGlfwModule() : context() { + } + + }; + using GlfwModule = std::shared_ptr<ecsGlfwModule>; + + // + // fake module/callbacks - our ECS doesn't have module/callback support yet. + // + inline GlfwModule ecsInitGlfw(ecs::ECS& ecs) { + auto mod = std::make_shared<ecsGlfwModule>(); + return mod; + } + +} + + +#endif diff --git a/fggl/gfx/window.cpp b/fggl/gfx/window.cpp index f1aa1b581ac9a063ed1ac3a475962ca65d43a878..b97e2095acfb8369b24de83383cad4ceb33d6b12 100644 --- a/fggl/gfx/window.cpp +++ b/fggl/gfx/window.cpp @@ -91,7 +91,7 @@ static void fggl_joystick(int jid, int state) { } } -Context::Context() { +GlfwContext::GlfwContext() { glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); int state = glfwInit(); @@ -106,11 +106,11 @@ Context::Context() { glfwSetJoystickCallback(fggl_joystick); } -Context::~Context() { +GlfwContext::~GlfwContext() { glfwTerminate(); } -void Context::pollEvents() { +void GlfwContext::pollEvents() { glfwPollEvents(); fggl_joystick_poll(); } diff --git a/fggl/gfx/window.hpp b/fggl/gfx/window.hpp index eaa80386f58b30273ec0d024f7e67c4efe802b4a..ebc5db23be8a16d0a911c03ae05fc1a59e7a1b60 100644 --- a/fggl/gfx/window.hpp +++ b/fggl/gfx/window.hpp @@ -10,10 +10,10 @@ namespace fggl::gfx { - class Context { + class GlfwContext { public: - Context(); - ~Context(); + GlfwContext(); + ~GlfwContext(); void pollEvents(); };