Skip to content

Commit

Permalink
Strip out unused parts of imgui_impl_sdl2
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Sep 15, 2024
1 parent 1a94cf3 commit ccc54b2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 592 deletions.
3 changes: 0 additions & 3 deletions src/oscar/Graphics/GraphicsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ namespace osc

void clear_screen(const Color&);

// HACK: this is needed by ImGui's SDL backend, because it uses OpenGL "in the raw"
void* upd_raw_opengl_context_handle_HACK();

// returns a future that asynchronously yields a complete screenshot of the next complete frame
std::future<Texture2D> request_screenshot();

Expand Down
10 changes: 0 additions & 10 deletions src/oscar/Graphics/GraphicsImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6170,11 +6170,6 @@ class osc::GraphicsContext::Impl final {
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

void* upd_raw_opengl_context_handle_HACK()
{
return opengl_context_.get();
}

std::future<Texture2D> request_screenshot()
{
return screenshot_request_queue_.emplace_back().get_future();
Expand Down Expand Up @@ -6333,11 +6328,6 @@ void osc::GraphicsContext::clear_screen(const Color& color)
g_graphics_context_impl->clear_screen(color);
}

void* osc::GraphicsContext::upd_raw_opengl_context_handle_HACK()
{
return g_graphics_context_impl->upd_raw_opengl_context_handle_HACK();
}

void osc::GraphicsContext::swap_buffers(SDL_Window& window)
{
g_graphics_context_impl->swap_buffers(window);
Expand Down
10 changes: 0 additions & 10 deletions src/oscar/Platform/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,6 @@ class osc::App::Impl final {

GraphicsContext& upd_graphics_context() { return graphics_context_; }

void* upd_raw_opengl_context_handle_HACK()
{
return graphics_context_.upd_raw_opengl_context_handle_HACK();
}

private:
bool is_window_focused() const
{
Expand Down Expand Up @@ -1094,8 +1089,3 @@ SDL_Window* osc::App::upd_underlying_window()
{
return impl_->upd_window().get();
}

void* osc::App::upd_underlying_opengl_context()
{
return impl_->upd_graphics_context().upd_raw_opengl_context_handle_HACK();
}
3 changes: 1 addition & 2 deletions src/oscar/Platform/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ namespace osc
// try and retrieve a singleton that has the same lifetime as the app
std::shared_ptr<void> upd_singleton(const std::type_info&, const std::function<std::shared_ptr<void>()>&);

// HACK: the 2D ui currently needs access to these
// HACK: the 2D ui currently needs to access this
friend void ui::context::init();
SDL_Window* upd_underlying_window();
void* upd_underlying_opengl_context();

class Impl;
std::unique_ptr<Impl> impl_;
Expand Down
528 changes: 6 additions & 522 deletions src/oscar/UI/imgui_impl_sdl2.cpp

Large diffs are not rendered by default.

47 changes: 5 additions & 42 deletions src/oscar/UI/imgui_impl_sdl2.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
// dear imgui: Platform Backend for SDL2
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)

// Implemented features:
// [X] Platform: Clipboard support.
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
// Missing features:
// [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows).
// [x] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.

// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp
// this was refactored from https://github.com/ocornut/imgui/blob/v1.91.1-docking/backends/imgui_impl_sdl2.h

#pragma once
#include "imgui.h" // IMGUI_IMPL_API
#ifndef IMGUI_DISABLE

struct SDL_Window;
struct SDL_Renderer;
struct _SDL_GameController;
typedef union SDL_Event SDL_Event;

IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOther(SDL_Window* window);
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);

// Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this.
// When using manual mode, caller is responsible for opening/closing gamepad.
enum ImGui_ImplSDL2_GamepadMode { ImGui_ImplSDL2_GamepadMode_AutoFirst, ImGui_ImplSDL2_GamepadMode_AutoAll, ImGui_ImplSDL2_GamepadMode_Manual };
IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = NULL, int manual_gamepads_count = -1);

#endif // #ifndef IMGUI_DISABLE
bool ImGui_ImplSDL2_Init(SDL_Window*);
void ImGui_ImplSDL2_Shutdown();
void ImGui_ImplSDL2_NewFrame();
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
5 changes: 2 additions & 3 deletions src/oscar/UI/ui_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ void osc::ui::context::init()
#endif

// init ImGui for SDL2 /w OpenGL
ImGui_ImplSDL2_InitForOpenGL(
App::upd().upd_underlying_window(),
App::upd().upd_underlying_opengl_context()
ImGui_ImplSDL2_Init(
App::upd().upd_underlying_window()
);

// init ImGui for OpenGL
Expand Down

0 comments on commit ccc54b2

Please sign in to comment.