|
| 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 "ImGuiImplSDL.hpp" |
| 28 | + |
| 29 | +#include "Errors.hpp" |
| 30 | +#include "RenderDevice.h" |
| 31 | +#include "backends/imgui_impl_sdl.h" |
| 32 | + |
| 33 | +namespace Diligent |
| 34 | +{ |
| 35 | + |
| 36 | +std::unique_ptr<ImGuiImplSDL> |
| 37 | +ImGuiImplSDL::Create(const ImGuiDiligentCreateInfo& CI, SDL_Window* pWindow) |
| 38 | +{ |
| 39 | + return std::make_unique<ImGuiImplSDL>(CI, pWindow); |
| 40 | +} |
| 41 | + |
| 42 | +ImGuiImplSDL::ImGuiImplSDL(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_ImplSDL2_InitForD3D(pWindow); |
| 54 | + break; |
| 55 | + case RENDER_DEVICE_TYPE_GL: |
| 56 | + case RENDER_DEVICE_TYPE_GLES: |
| 57 | + ImGui_ImplSDL2_InitForOpenGL(pWindow, nullptr); |
| 58 | + break; |
| 59 | + case RENDER_DEVICE_TYPE_VULKAN: |
| 60 | + ImGui_ImplSDL2_InitForVulkan(pWindow); |
| 61 | + break; |
| 62 | + case RENDER_DEVICE_TYPE_METAL: |
| 63 | + ImGui_ImplSDL2_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 | +ImGuiImplSDL::~ImGuiImplSDL() { ImGui_ImplSDL2_Shutdown(); } |
| 75 | + |
| 76 | +void ImGuiImplSDL::NewFrame(Uint32 RenderSurfaceWidth, |
| 77 | + Uint32 RenderSurfaceHeight, |
| 78 | + SURFACE_TRANSFORM SurfacePreTransform) |
| 79 | +{ |
| 80 | + ImGui_ImplSDL2_NewFrame(); |
| 81 | + ImGuiImplDiligent::NewFrame(RenderSurfaceWidth, RenderSurfaceHeight, |
| 82 | + SurfacePreTransform); |
| 83 | +} |
| 84 | + |
| 85 | +void ImGuiImplSDL::Render(IDeviceContext* pCtx) |
| 86 | +{ |
| 87 | + ImGuiImplDiligent::Render(pCtx); |
| 88 | +} |
| 89 | + |
| 90 | +bool ImGuiImplSDL::HandleSDLEvent(const SDL_Event* ev) |
| 91 | +{ |
| 92 | + return ImGui_ImplSDL2_ProcessEvent(ev); |
| 93 | +} |
| 94 | + |
| 95 | +} // namespace Diligent |
0 commit comments