Skip to content

Commit a390035

Browse files
author
James Johnson
committed
Split ImGuiImplSDL class into two for the SDL2 and SDL3 backends.
1 parent fe07949 commit a390035

File tree

4 files changed

+174
-20
lines changed

4 files changed

+174
-20
lines changed

Imgui/interface/ImGuiImplSDL.hpp renamed to Imgui/interface/ImGuiImplSDL2.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ extern "C" union SDL_Event;
3434

3535
namespace Diligent
3636
{
37-
class ImGuiImplSDL final : public ImGuiImplDiligent
37+
class ImGuiImplSDL2 final : public ImGuiImplDiligent
3838
{
3939
public:
40-
static std::unique_ptr<ImGuiImplSDL>
40+
static std::unique_ptr<ImGuiImplSDL2>
4141
Create(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow);
4242

43-
ImGuiImplSDL(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow);
44-
~ImGuiImplSDL();
43+
ImGuiImplSDL2(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow);
44+
~ImGuiImplSDL2();
4545

4646
// clang-format off
47-
ImGuiImplSDL (const ImGuiImplSDL&) = delete;
48-
ImGuiImplSDL ( ImGuiImplSDL&&) = delete;
49-
ImGuiImplSDL& operator = (const ImGuiImplSDL&) = delete;
50-
ImGuiImplSDL& operator = ( ImGuiImplSDL&&) = delete;
47+
ImGuiImplSDL2 (const ImGuiImplSDL2&) = delete;
48+
ImGuiImplSDL2 ( ImGuiImplSDL2&&) = delete;
49+
ImGuiImplSDL2& operator = (const ImGuiImplSDL2&) = delete;
50+
ImGuiImplSDL2& operator = ( ImGuiImplSDL2&&) = delete;
5151
// clang-format on
5252

5353
virtual void NewFrame(Uint32 RenderSurfaceWidth,

Imgui/interface/ImGuiImplSDL3.hpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2025 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#pragma once
28+
29+
#include <memory>
30+
#include "ImGuiImplDiligent.hpp"
31+
32+
extern "C" struct SDL_Window;
33+
extern "C" union SDL_Event;
34+
35+
namespace Diligent
36+
{
37+
class ImGuiImplSDL3 final : public ImGuiImplDiligent
38+
{
39+
public:
40+
static std::unique_ptr<ImGuiImplSDL3>
41+
Create(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow);
42+
43+
ImGuiImplSDL3(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow);
44+
~ImGuiImplSDL3();
45+
46+
// clang-format off
47+
ImGuiImplSDL3 (const ImGuiImplSDL3&) = delete;
48+
ImGuiImplSDL3 ( ImGuiImplSDL3&&) = delete;
49+
ImGuiImplSDL3& operator = (const ImGuiImplSDL3&) = delete;
50+
ImGuiImplSDL3& operator = ( ImGuiImplSDL3&&) = delete;
51+
// clang-format on
52+
53+
virtual void NewFrame(Uint32 RenderSurfaceWidth,
54+
Uint32 RenderSurfaceHeight,
55+
SURFACE_TRANSFORM SurfacePreTransform) override final;
56+
virtual void Render(IDeviceContext* pCtx) override final;
57+
bool HandleSDLEvent(const SDL_Event* ev);
58+
};
59+
} // namespace Diligent

Imgui/src/ImGuiImplSDL.cpp renamed to Imgui/src/ImGuiImplSDL2.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* of the possibility of such damages.
2525
*/
2626

27-
#include "ImGuiImplSDL.hpp"
27+
#include "ImGuiImplSDL2.hpp"
2828

2929
#include "Errors.hpp"
3030
#include "RenderDevice.h"
@@ -33,14 +33,14 @@
3333
namespace Diligent
3434
{
3535

36-
std::unique_ptr<ImGuiImplSDL>
37-
ImGuiImplSDL::Create(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow)
36+
std::unique_ptr<ImGuiImplSDL2>
37+
ImGuiImplSDL2::Create(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow)
3838
{
39-
return std::make_unique<ImGuiImplSDL>(CI, pWindow);
39+
return std::make_unique<ImGuiImplSDL2>(CI, pWindow);
4040
}
4141

42-
ImGuiImplSDL::ImGuiImplSDL(const ImGuiDiligentCreateInfo& CI,
43-
SDL_Window* pWindow) :
42+
ImGuiImplSDL2::ImGuiImplSDL2(const ImGuiDiligentCreateInfo& CI,
43+
SDL_Window* pWindow) :
4444
ImGuiImplDiligent(CI)
4545
{
4646
switch (CI.pDevice->GetDeviceInfo().Type)
@@ -71,23 +71,23 @@ ImGuiImplSDL::ImGuiImplSDL(const ImGuiDiligentCreateInfo& CI,
7171
}
7272
}
7373

74-
ImGuiImplSDL::~ImGuiImplSDL() { ImGui_ImplSDL2_Shutdown(); }
74+
ImGuiImplSDL2::~ImGuiImplSDL2() { ImGui_ImplSDL2_Shutdown(); }
7575

76-
void ImGuiImplSDL::NewFrame(Uint32 RenderSurfaceWidth,
77-
Uint32 RenderSurfaceHeight,
78-
SURFACE_TRANSFORM SurfacePreTransform)
76+
void ImGuiImplSDL2::NewFrame(Uint32 RenderSurfaceWidth,
77+
Uint32 RenderSurfaceHeight,
78+
SURFACE_TRANSFORM SurfacePreTransform)
7979
{
8080
ImGui_ImplSDL2_NewFrame();
8181
ImGuiImplDiligent::NewFrame(RenderSurfaceWidth, RenderSurfaceHeight,
8282
SurfacePreTransform);
8383
}
8484

85-
void ImGuiImplSDL::Render(IDeviceContext* pCtx)
85+
void ImGuiImplSDL2::Render(IDeviceContext* pCtx)
8686
{
8787
ImGuiImplDiligent::Render(pCtx);
8888
}
8989

90-
bool ImGuiImplSDL::HandleSDLEvent(const SDL_Event* ev)
90+
bool ImGuiImplSDL2::HandleSDLEvent(const SDL_Event* ev)
9191
{
9292
return ImGui_ImplSDL2_ProcessEvent(ev);
9393
}

Imgui/src/ImGuiImplSDL3.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2025 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#include "ImGuiImplSDL3.hpp"
28+
29+
#include "Errors.hpp"
30+
#include "RenderDevice.h"
31+
#include "backends/imgui_impl_sdl3.h"
32+
33+
namespace Diligent
34+
{
35+
36+
std::unique_ptr<ImGuiImplSDL3>
37+
ImGuiImplSDL3::Create(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow)
38+
{
39+
return std::make_unique<ImGuiImplSDL3>(CI, pWindow);
40+
}
41+
42+
ImGuiImplSDL3::ImGuiImplSDL3(const ImGuiDiligentCreateInfo& CI,
43+
SDL_Window* pWindow) :
44+
ImGuiImplDiligent(CI)
45+
{
46+
switch (CI.pDevice->GetDeviceInfo().Type)
47+
{
48+
case RENDER_DEVICE_TYPE_UNDEFINED:
49+
LOG_ERROR_AND_THROW("Undefined device type");
50+
break;
51+
case RENDER_DEVICE_TYPE_D3D11:
52+
case RENDER_DEVICE_TYPE_D3D12:
53+
ImGui_ImplSDL3_InitForD3D(pWindow);
54+
break;
55+
case RENDER_DEVICE_TYPE_GL:
56+
case RENDER_DEVICE_TYPE_GLES:
57+
ImGui_ImplSDL3_InitForOpenGL(pWindow, nullptr);
58+
break;
59+
case RENDER_DEVICE_TYPE_VULKAN:
60+
ImGui_ImplSDL3_InitForVulkan(pWindow);
61+
break;
62+
case RENDER_DEVICE_TYPE_METAL:
63+
ImGui_ImplSDL3_InitForMetal(pWindow);
64+
break;
65+
case RENDER_DEVICE_TYPE_WEBGPU:
66+
LOG_ERROR_AND_THROW("WebGPU not supported");
67+
break;
68+
case RENDER_DEVICE_TYPE_COUNT:
69+
LOG_ERROR_AND_THROW("Unsupported device type");
70+
break;
71+
}
72+
}
73+
74+
ImGuiImplSDL3::~ImGuiImplSDL3() { ImGui_ImplSDL3_Shutdown(); }
75+
76+
void ImGuiImplSDL3::NewFrame(Uint32 RenderSurfaceWidth,
77+
Uint32 RenderSurfaceHeight,
78+
SURFACE_TRANSFORM SurfacePreTransform)
79+
{
80+
ImGui_ImplSDL3_NewFrame();
81+
ImGuiImplDiligent::NewFrame(RenderSurfaceWidth, RenderSurfaceHeight,
82+
SurfacePreTransform);
83+
}
84+
85+
void ImGuiImplSDL3::Render(IDeviceContext* pCtx)
86+
{
87+
ImGuiImplDiligent::Render(pCtx);
88+
}
89+
90+
bool ImGuiImplSDL3::HandleSDLEvent(const SDL_Event* ev)
91+
{
92+
return ImGui_ImplSDL3_ProcessEvent(ev);
93+
}
94+
95+
} // namespace Diligent

0 commit comments

Comments
 (0)