| 1 | // dear imgui: Renderer Backend for SDL_Renderer for SDL2 |
| 2 | // (Requires: SDL 2.0.17+) |
| 3 | |
| 4 | // Note that SDL_Renderer is an _optional_ component of SDL2, which IMHO is now largely obsolete. |
| 5 | // For a multi-platform app consider using other technologies: |
| 6 | // - SDL3+SDL_GPU: SDL_GPU is SDL3 new graphics abstraction API. You will need to update to SDL3. |
| 7 | // - SDL2+DirectX, SDL2+OpenGL, SDL2+Vulkan: combine SDL with dedicated renderers. |
| 8 | // If your application wants to render any non trivial amount of graphics other than UI, |
| 9 | // please be aware that SDL_Renderer currently offers a limited graphic API to the end-user |
| 10 | // and it might be difficult to step out of those boundaries. |
| 11 | |
| 12 | // Implemented features: |
| 13 | // [X] Renderer: User texture binding. Use 'SDL_Texture*' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef! |
| 14 | // [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset). |
| 15 | // [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures). |
| 16 | // [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'. |
| 17 | // Missing features or Issues: |
| 18 | // [ ] Renderer: Multi-viewport support (multiple windows). |
| 19 | // [ ] Renderer: Missing support for DrawCallback_SetSamplerLinear, DrawCallback_SetSamplerNearest callbacks: SDLRenderer2 does not support changing SDL_SCALE_MODE while rendering. |
| 20 | |
| 21 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. |
| 22 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. |
| 23 | // Learn about Dear ImGui: |
| 24 | // - FAQ https://dearimgui.com/faq |
| 25 | // - Getting Started https://dearimgui.com/getting-started |
| 26 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). |
| 27 | // - Introduction, links and more at the top of imgui.cpp |
| 28 | |
| 29 | #pragma once |
| 30 | #ifndef IMGUI_DISABLE |
| 31 | #include "imgui.h" // IMGUI_IMPL_API |
| 32 | |
| 33 | struct SDL_Renderer; |
| 34 | |
| 35 | // Follow "Getting Started" link and check examples/ folder to learn about using backends! |
| 36 | IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer); |
| 37 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_Shutdown(); |
| 38 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_NewFrame(); |
| 39 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer); |
| 40 | |
| 41 | // Called by Init/NewFrame/Shutdown |
| 42 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_CreateDeviceObjects(); |
| 43 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyDeviceObjects(); |
| 44 | |
| 45 | // (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually. |
| 46 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_UpdateTexture(ImTextureData* tex); |
| 47 | |
| 48 | // [BETA] Selected render state data shared with callbacks. |
| 49 | // This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplSDLRenderer2_RenderDrawData() call. |
| 50 | // (Please open an issue if you feel you need access to more data) |
| 51 | struct ImGui_ImplSDLRenderer2_RenderState |
| 52 | { |
| 53 | SDL_Renderer* Renderer; |
| 54 | }; |
| 55 | |
| 56 | #endif // #ifndef IMGUI_DISABLE |