Skip to content

Commit

Permalink
Rename runners sdl and glfw
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 19, 2023
1 parent af508f2 commit b582261
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 48 deletions.
10 changes: 5 additions & 5 deletions src/hello_imgui/internal/backend_impls/runner_factory.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "hello_imgui/internal/backend_impls/runner_factory.h"

#include "hello_imgui/hello_imgui_error.h"
#include "hello_imgui/internal/backend_impls/runner_emscripten.h"
#include "hello_imgui/internal/backend_impls/runner_glfw_opengl3.h"
#include "hello_imgui/internal/backend_impls/runner_glfw3.h"
#include "hello_imgui/internal/backend_impls/runner_qt.h"
#include "hello_imgui/internal/backend_impls/runner_sdl_opengl3.h"
#include "hello_imgui/hello_imgui_error.h"
#include "hello_imgui/internal/backend_impls/runner_sdl2.h"

#include <stdexcept>

Expand All @@ -14,14 +14,14 @@ namespace HelloImGui
#ifdef HELLOIMGUI_USE_GLFW_OPENGL3
std::unique_ptr<AbstractRunner> FactorRunnerGlfwOpenGl3(RunnerParams& params)
{
return std::make_unique<RunnerGlfwOpenGl3>(params);
return std::make_unique<RunnerGlfw3>(params);
}
#endif

#ifdef HELLOIMGUI_USE_SDL_OPENGL3
std::unique_ptr<AbstractRunner> FactorRunnerSdlOpenGl3(RunnerParams& params)
{
return std::make_unique<RunnerSdlOpenGl3>(params);
return std::make_unique<RunnerSdl2>(params);
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
#include "hello_imgui/internal/stb_image.h"
#include "hello_imgui/hello_imgui_assets.h"

#include "backend_window_helper/glfw_window_helper.h"
#include "hello_imgui/hello_imgui_error.h"
#include "runner_glfw3.h"
#include <GLFW/glfw3.h>
#include <backends/imgui_impl_glfw.h>
#include <imgui.h>
#include <stdexcept>
#include "hello_imgui/hello_imgui_error.h"
#include "runner_glfw_opengl3.h"
#include "backend_window_helper/glfw_window_helper.h"


namespace HelloImGui
{
Expand All @@ -30,13 +29,13 @@ namespace HelloImGui
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}

RunnerGlfwOpenGl3::RunnerGlfwOpenGl3(RunnerParams & runnerParams)
RunnerGlfw3::RunnerGlfw3(RunnerParams & runnerParams)
: AbstractRunner(runnerParams)
{
mBackendWindowHelper = std::make_unique<BackendApi::GlfwWindowHelper>();
}

void RunnerGlfwOpenGl3::Impl_InitBackend()
void RunnerGlfw3::Impl_InitBackend()
{
glfwSetErrorCallback(glfw_error_callback);
#ifdef __APPLE__
Expand All @@ -50,15 +49,15 @@ namespace HelloImGui
}


void RunnerGlfwOpenGl3::Impl_CreateWindow()
void RunnerGlfw3::Impl_CreateWindow()
{
BackendApi::BackendOptions backendOptions;

mWindow = mBackendWindowHelper->CreateWindow(params.appWindowParams, backendOptions);
params.backendPointers.glfwWindow = mWindow;
}

void RunnerGlfwOpenGl3::Impl_PollEvents()
void RunnerGlfw3::Impl_PollEvents()
{
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants
Expand All @@ -73,17 +72,17 @@ namespace HelloImGui
params.appShallExit = true;
}

void RunnerGlfwOpenGl3::Impl_NewFrame_Backend() { ImGui_ImplGlfw_NewFrame(); }
void RunnerGlfw3::Impl_NewFrame_Backend() { ImGui_ImplGlfw_NewFrame(); }

void RunnerGlfwOpenGl3::Impl_UpdateAndRenderAdditionalPlatformWindows()
void RunnerGlfw3::Impl_UpdateAndRenderAdditionalPlatformWindows()
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}

void RunnerGlfwOpenGl3::Impl_Cleanup()
void RunnerGlfw3::Impl_Cleanup()
{
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
Expand All @@ -92,9 +91,9 @@ namespace HelloImGui
glfwTerminate();
}

void RunnerGlfwOpenGl3::Impl_SwapBuffers() { glfwSwapBuffers((GLFWwindow *)mWindow); }
void RunnerGlfw3::Impl_SwapBuffers() { glfwSwapBuffers((GLFWwindow *)mWindow); }

void RunnerGlfwOpenGl3::Impl_SetWindowIcon()
void RunnerGlfw3::Impl_SetWindowIcon()
{
std::string iconFile = "app_settings/icon.png";
if (!HelloImGui::AssetExists(iconFile))
Expand Down Expand Up @@ -128,28 +127,28 @@ namespace HelloImGui
//
///////////////////////////////////////////////////////////////////////////////////////////////
#ifdef HELLOIMGUI_HAS_OPENGL
void RunnerGlfwOpenGl3::Impl_LinkWindowingToRenderingBackend()
void RunnerGlfw3::Impl_LinkWindowingToRenderingBackend()
{
ImGui_ImplGlfw_InitForOpenGL((GLFWwindow *)mWindow, true);
ImGui_ImplOpenGL3_Init(Impl_GlslVersion().c_str());
}

void RunnerGlfwOpenGl3::Impl_InitRenderBackendCallbacks()
void RunnerGlfw3::Impl_InitRenderBackendCallbacks()
{
mRenderingBackendCallbacks = CreateOpenGl3RenderingBackendCallbacks();
}

void RunnerGlfwOpenGl3::Impl_CreateGlContext()
void RunnerGlfw3::Impl_CreateGlContext()
{
glfwMakeContextCurrent((GLFWwindow *) mWindow); // OpenGl!
glfwSwapInterval(1); // Enable vsync (openGL only, not vulkan)
}

void RunnerGlfwOpenGl3::Impl_Select_Gl_Version() { gOpenGlHelper.SelectOpenGlVersion(); }
void RunnerGlfw3::Impl_Select_Gl_Version() { gOpenGlHelper.SelectOpenGlVersion(); }

std::string RunnerGlfwOpenGl3::Impl_GlslVersion() { return gOpenGlHelper.GlslVersion(); }
std::string RunnerGlfw3::Impl_GlslVersion() { return gOpenGlHelper.GlslVersion(); }

void RunnerGlfwOpenGl3::Impl_InitGlLoader() { gOpenGlHelper.InitGlLoader(); }
void RunnerGlfw3::Impl_InitGlLoader() { gOpenGlHelper.InitGlLoader(); }
#endif // #ifdef HELLOIMGUI_HAS_OPENGL


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace HelloImGui
{
class RunnerGlfwOpenGl3 : public AbstractRunner
class RunnerGlfw3 : public AbstractRunner
{
public:
RunnerGlfwOpenGl3(RunnerParams & runnerParams);
virtual ~RunnerGlfwOpenGl3() = default;
RunnerGlfw3(RunnerParams & runnerParams);
virtual ~RunnerGlfw3() = default;

protected:
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifdef HELLOIMGUI_USE_SDL

#ifdef HELLOIMGUI_HAS_OPENGL
#include "runner_sdl_opengl3.h"
#include "runner_sdl2.h"
#include <backends/imgui_impl_opengl3.h>
#endif

Expand All @@ -26,20 +26,20 @@ namespace HelloImGui

int HandleAppEvents(void *runnerSdlOpenGl3_void, SDL_Event *event)
{
RunnerSdlOpenGl3 * runnerSdlOpenGl3 = (RunnerSdlOpenGl3 *)(runnerSdlOpenGl3_void);
RunnerSdl2 * runnerSdlOpenGl3 = (RunnerSdl2 *)(runnerSdlOpenGl3_void);
if (runnerSdlOpenGl3->priv_HandleMobileDeviceEvent(event->type))
return 0;
else
return 1;
}

RunnerSdlOpenGl3::RunnerSdlOpenGl3(RunnerParams & runnerParams) : AbstractRunner(runnerParams)
RunnerSdl2::RunnerSdl2(RunnerParams & runnerParams) : AbstractRunner(runnerParams)
{
mBackendWindowHelper = std::make_unique<BackendApi::SdlWindowHelper>();
}


void RunnerSdlOpenGl3::Impl_InitBackend()
void RunnerSdl2::Impl_InitBackend()
{
auto flags = SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER;
#ifdef __EMSCRIPTEN__
Expand All @@ -54,15 +54,15 @@ namespace HelloImGui
SDL_SetEventFilter(HandleAppEvents, this);
}

void RunnerSdlOpenGl3::Impl_CreateWindow()
void RunnerSdl2::Impl_CreateWindow()
{
BackendApi::BackendOptions backendOptions;

mWindow = mBackendWindowHelper->CreateWindow(params.appWindowParams, backendOptions);
params.backendPointers.sdlWindow = mWindow;
}

void RunnerSdlOpenGl3::Impl_PollEvents()
void RunnerSdl2::Impl_PollEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
Expand All @@ -83,7 +83,7 @@ namespace HelloImGui
}
}

void RunnerSdlOpenGl3::Impl_UpdateAndRenderAdditionalPlatformWindows()
void RunnerSdl2::Impl_UpdateAndRenderAdditionalPlatformWindows()
{
SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
Expand All @@ -92,7 +92,7 @@ namespace HelloImGui
SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
}

void RunnerSdlOpenGl3::Impl_Cleanup()
void RunnerSdl2::Impl_Cleanup()
{
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
Expand All @@ -102,11 +102,11 @@ namespace HelloImGui
SDL_Quit();
}

void RunnerSdlOpenGl3::Impl_SwapBuffers() { SDL_GL_SwapWindow((SDL_Window *)mWindow); }
void RunnerSdl2::Impl_SwapBuffers() { SDL_GL_SwapWindow((SDL_Window *)mWindow); }



bool RunnerSdlOpenGl3::priv_HandleMobileDeviceEvent(unsigned int sdl_EventType)
bool RunnerSdl2::priv_HandleMobileDeviceEvent(unsigned int sdl_EventType)
{
#ifdef HELLOIMGUI_MOBILEDEVICE
switch(sdl_EventType)
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace HelloImGui
#endif
}

void RunnerSdlOpenGl3::Impl_SetWindowIcon()
void RunnerSdl2::Impl_SetWindowIcon()
{
std::string iconFile = "app_settings/icon.png";
if (!HelloImGui::AssetExists(iconFile))
Expand Down Expand Up @@ -190,26 +190,26 @@ namespace HelloImGui
HelloImGui::FreeAssetFileData(&imageAsset);
}

void RunnerSdlOpenGl3::Impl_NewFrame_Backend() { ImGui_ImplSDL2_NewFrame(); }
void RunnerSdl2::Impl_NewFrame_Backend() { ImGui_ImplSDL2_NewFrame(); }

///////////////////////////////////////////////////////////////////////////////////////////////
//
// Rendering Backends (OpenGL, Vulkan, ...)
//
///////////////////////////////////////////////////////////////////////////////////////////////
#ifdef HELLOIMGUI_HAS_OPENGL
void RunnerSdlOpenGl3::Impl_InitRenderBackendCallbacks()
void RunnerSdl2::Impl_InitRenderBackendCallbacks()
{
mRenderingBackendCallbacks = CreateOpenGl3RenderingBackendCallbacks();
}

void RunnerSdlOpenGl3::Impl_LinkWindowingToRenderingBackend()
void RunnerSdl2::Impl_LinkWindowingToRenderingBackend()
{
ImGui_ImplSDL2_InitForOpenGL((SDL_Window *)mWindow, mGlContext);
ImGui_ImplOpenGL3_Init(Impl_GlslVersion().c_str());
}

void RunnerSdlOpenGl3::Impl_CreateGlContext()
void RunnerSdl2::Impl_CreateGlContext()
{
mGlContext = SDL_GL_CreateContext((SDL_Window *)mWindow);
IM_ASSERT(mGlContext != nullptr);
Expand All @@ -218,9 +218,9 @@ namespace HelloImGui
SDL_GL_SetSwapInterval(1); // Enable vsync
params.backendPointers.sdlGlContext = mGlContext;
}
void RunnerSdlOpenGl3::Impl_InitGlLoader() { gOpenGlSetupSdl.InitGlLoader(); }
void RunnerSdlOpenGl3::Impl_Select_Gl_Version() { gOpenGlSetupSdl.SelectOpenGlVersion(); }
std::string RunnerSdlOpenGl3::Impl_GlslVersion() { return gOpenGlSetupSdl.GlslVersion(); }
void RunnerSdl2::Impl_InitGlLoader() { gOpenGlSetupSdl.InitGlLoader(); }
void RunnerSdl2::Impl_Select_Gl_Version() { gOpenGlSetupSdl.SelectOpenGlVersion(); }
std::string RunnerSdl2::Impl_GlslVersion() { return gOpenGlSetupSdl.GlslVersion(); }
#endif // HELLOIMGUI_HAS_OPENGL


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace HelloImGui
{
class RunnerSdlOpenGl3 : public AbstractRunner
class RunnerSdl2 : public AbstractRunner
{
public:
RunnerSdlOpenGl3(RunnerParams & runnerParams);
virtual ~RunnerSdlOpenGl3() = default;
RunnerSdl2(RunnerParams & runnerParams);
virtual ~RunnerSdl2() = default;

protected:
//
Expand Down

0 comments on commit b582261

Please sign in to comment.