forked from Green-Sky/tomato
Green Sky
a148d9accf
277ae93c413 Version 1.90.4 f5be90523d6 Nav: Fixed SetKeyboardFocusHere() or programmatic tabbing API from not working on windows with the ImGuiWindowFlags_NoNavInputs flag. 13d91ff9188 Nav: Fixed SetKeyboardFocusHere() or programmatic tabbing API from not working on windows with the ImGuiWindowFlags_NoNavInputs flag. 34965cf23a7 Modals: Temporary changes of ImGuiCol_ModalWindowDimBg are properly handled by BeginPopupModal(). (#7340) 659fb41d0a2 Debug Tools: moved DebugStartItemPicker() to public API. Added to Demo->Tools menu. (#2673) 198c38f0b11 Demo: Custom Rendering: better demonstrate PathArcTo(), PathBezierQuadraticCurveTo(), PathBezierCubicCurveTo(), PathStroke(), PathFillConvex() functions. 3b6d924acd0 ProgressBar: Fixed a minor tesselation issue when rendering rounded progress bars. d3f1a7165cb Popups: allow Child Popups to be resizable if not explicitly disabling. e78ce72eb6d Popups: Fixed resizable popup minimum size being too small. Standardized CalcWindowMinSize() logic a bit more. (#73290 014e0ac8c92 Menus, Popups: Fixed an issue where hovering a parent-menu upward would erroneously close the window. (#7325, #7287, #7063) c16043c1d58 Tables: Angled headers: improve clipping of text since multi-line labels makes clipping issues visible. (#6917) 405e54ebd50 Tables: Angled Headers: fixed support for multi-line labels. various padding/layout fixes. (#6917) 6655ab2e43f Tables: Angled Headers: fixed TableAngledHeadersRow() incorrect background fill drawn too low. Fixed row geometry with non-small values of CellPadding. (#6917) 9159cd7b4ac Updated invalid documentation link (#7331) ccc5347e451 Fix typos (#7332) 8a14b71f228 Version 1.90.4 WIP b19a4c5f2b3 Backends: OSX: remove legacy clearing of io.NavInputs in ImGui_ImplOSX_UpdateGamepads(). (#7320) 5b6f03213dd Version 1.90.3 f80e65a4068 Backends:,Examples: Vulkan: moved RenderPass parameter from ImGui_ImplVulkan_Init() function to ImGui_ImplVulkan_InitInfo structure. (#7308) 829f45df994 Backends: SDL2: removed obsolete ImGui_ImplSDL2_NewFrame(SDL_Window*) signature which was obsoleted in 1.84.. 3cc37170ca7 Examples: GLFW+Metal: Add -I and -L paths for MacPorts. 891b81fc5d7 Backends: SDL3: Fixed gamepad. Added support for disconnection. Added support for multiple gamepads. Added ImGui_ImplSDL3_SetGamepadMode(). (#7180, #3884, #6559, #6890) 262e30e3001 Backends: SDL2: rework new API as ImGui_ImplSDL2_SetGamepadMode(). (#3884, #6559, #6890, #7180) 9dfa2397deb Internals: Fixed ImFileOpen not working before context is created. (#7314, #7315) d15e4100b83 Backends: SDL2: Amend new API, all support for multiple gamepads. (#3884, #6559, #6890) f966da1f8fb Backends: SDL2: Gamepad handlng: amend bf1c96d. (#3884, #6559, #6890) bf1c96d4fa2 Backends: SDL2: Handle gamepad disconnection + fixed increasing refcount. Added ImGui_ImplSDL2_SelectGamepadAuto()/ImGui_ImplSDL2_SelectGamepadExplicit(). (#3884, #6559, #6890) fd8d6dc5d19 Backends: SDL2,SDL3: tidying up. e0ba0d0433a Backends: Vulkan: Fixes for building with pre Vulkan 1.3. Amend 8901931. (#7166) 11d73f03ee5 Backends: Vulkan: Fix/amend 8901931 89019319ddb Backends: Vulkan: use PipelineRenderingCreateInfo for dynamic rendering (#7166, #6855, #5446, #5037) 1d6f0cea0e6 Backends: DX9: use RGBA texture to avoid conversion if supported 3af739a2d17 Menus, Popups: fixed menus and popups with child window flag erroneously not displaying a scrollbar when contents is over parent viewport size. (#7287, #7063) 2af01baffd1 Backends: SDLRenderer3: query newly added SDL_RenderViewportSet() to not restore a wrong viewport if none was initially set. 915c6393ad7 Version 1.90.3 WIP 536090303a8 Version 1.90.2 7b5357d817e Debug Tools: Metrics: Improved Monitors and Viewports minimap display. Highlight on hover. 70aa717a8e1 Combo: Fixed not reusing windows optimally when used inside a popup stack. 5cdc4a2a413 Demo: use ImGui::MemAlloc/MemFree for consistency. (#7300) 76e09c4b0fa ClosePopupsOverWindow(): amend to remove _ChildWindow test. 3a078466a7a Nav: ImGuiWindowFlags_NoNavInputs is tested during scoring so NavFlattened windows can use it. 7d67623d15b InputText: Internal: ReloadUserBufXXX functions don't override revert value. (#2890) fix accidental comment. a5e0e90c16a Nav: tweak RenderNavHighlight() syntax. ImGuiNavHighlightFlags_TypeThin -> ImGuiNavHighlightFlags_Compact. 1e8fc01ddd7 InputText: Internal: ReloadUserBufXXX functions don't override revert value. (#2890) + rename a06dd7a27b6 OpenPopup(): Added ImGuiPopupFlags_NoReopen. Nav, Menus: Fixed click on a BeginMenu() followed by right-arrow. (#1497, #1533) f104967c68f Comments 06ce312745e InputText: Internal: added reload from user-buf feature. (#2890) f50ddc431e3 Fixed some typos. (#7282) 6172c22c5dc CI: Update to `actions/checkout` `v4` from `v3`. (#7281) 96839b445e3 Nav: Improve handling of Alt key to toggle menu so that key ownership may be claimed on indiviudal left/right alt key without intefering with the other. 71947563709 Shortcut: fixed single mod-key Shortcut from working e.g. Shortcut(ImGuiKey_LeftCtrl) f1960b60c1a Added "nop" to IM_DEBUG_BREAK macro on GCC to work around GDB bug (#7266) 8491cf36adb Inputs: g.ActiveIdUsingManyKeys[] prevent routes from being claimed. 9176eedf240 Internals: SetShortcutRouting() move code so next commit is easier to read. Should be no-op. 1509842107d Backends: OpenGL3: Shallow tweak of compile-time extensions detection. 1ce41f6218d Backends: OpenGL3: Backup and restore GL_PIXEL_UNPACK_BUFFER. (#7253) 81e0be856a6 Fixed strict-aliasing violation in FormatTextureIDForDebugDisplay(). (#7090, #7256) a201af73544 Added SetNextItemShortcut() wip function. (#456) 4c2c09450a6 Nav: keyboard/gamepad activation feedback properly timed instead of frame buffer. (#456) 5b5e9bd0cb3 Internals: Tweak shallow compaction as Clang complains about MS ABI signage of enums. 7c3fa7d049a Refactor: moved section in imgui_internal.h 9266c0d2d13 Backends: WebGPU: Avoid leaking pipeline layout. (#7245) 595eb86624d Changelog, comment, minor data compaction 6850194f60a CI: Fixes WGPU example build. 5fc0a361b24 Backends: WebGPU: added ImGui_ImplWGPU_InitInfo::PipelineMultisampleState. (#7240) 831d42c1ab3 Backends: WebGPU: ImGui_ImplWGPU_Init() now takes a ImGui_ImplWGPU_InitInfo structure instead of variety of parameters, allowing for easier further changes. (#7240) e3c7ff944d5 Examples: Emscripten+WebGPU: slightly refactor like other Emscripten compatible Desktop examples, as aiming to make this suppot desktop eventually. 15908502ed6 Backends: Vulkan: Define NOMINMAX when VK_USE_PLATFORM_WIN32_KHR is defined. (#7250) 788747f8635 Examples: Emscripten+WebGPU: Remove use of deprecated ObjectBase<...>::Release in favor of ::MoveToCHandle (#7251) 763100b3858 Nav: Fixed pressing Escape while in a child window with _NavFlattened flag. (#7237) c7edb446caa Shortcut(): always test ownership. 1844f903d55 Nav: space/enter poll check ownership. InputText: declare ownership of Enter key as it doesn't go through Shortcut 5ddfbb80d86 Backends: Vulkan: Fixed vkAcquireNextImageKHR() validation errors in VulkanSDK 1.3.275 by allocating one extra semaphore than in-flight frames. (#7236) 2f483373355 Examples: Vulkan: Rename compile-time defies for the examples to remove misleading IMGUI_ prefixes. d7c2a0e38f4 Shortcut(): fixed 8323a06 adding _Repeat to all Shortcut() calls. 3b828d3701e Refactor: moving ItemAdd() into a section abote ItemSize(). No logic change (part 2) ff5f3aa38b5 Refactor: moving ItemAdd() into a section abote ItemSize(). No logic change (part 1) 1a48a634466 Enclosed a few more remaining sections in ifndef IMGUI_DISABLE_DEBUG_TOOLS for completeness. 33fabdf392d Scrollbar() doesn't forcefully mark itself as hovered when held. d431d85839b Internals: removed obsolete ImPool::GetSize() (last used by implot 0.10, changed in implot 0.11) f0d1f61fa51 Internals: commented out long-time obsoleted FocusableItemRegister()/FocusableItemUnregister() documentaton-only leftovers. + 095665977f6 Nav: marking NavId as hovered in ButtonBehavior() doesn't check for ActiveId. d10641b04a3 Nav: keyboard/gamepad activation mark widgets as held to give better visual feedback. 03417cc77d1 Backends: WebGPU: Filling all WGPUDepthStencilState fields explicitly as a recent Dawn update stopped setting default values. (#7232) 5fdcdf7080a Shortcut: ImGuiInputFlags_RouteFocused policy can filter Shortcuts conflicting with character input when an item is active. (#456) 80d5cb1ab1f Comments around ImGuiInputFlags. 1cc0eb4d322 Internals: Rename NavFocusScopePath to NavFocusRoute + fixed a static analyzer warning. 46e5f44ec8c Shortcut()/SetShortcutRouting(): use mixed current window focus scope + ParentWindowForFocusRoute. (#6798, #2637, #456) e0c8c80adaa Shortcut()/SetShortcutRouting(): focus route testing now use ParentWindowForFocusRoute. Automatically set on child-window, manually configurable otherwise. (#6798, #2637, #456) 4b20a0217eb Internals: add window to FocusScopeStack. (#6798) 2156db7a075 Debug Log: added InputRouting logging. Made GetKeyChordName() use its own buffer. Fixed debug break in SetShortcutRouting(). (#6798, #2637, #456) dd0efdc6371 Fixed SetKeyboardFocusHere() not working when current nav focus is in different scope. (#7226) 8a3dfda8d08 Commented out obsolete ImGuiIO::ImeWindowHandle marked obsolete in 1.87, favor of writing to 'void* ImGuiViewport::PlatformHandleRaw'. 6228c2e1ec7 Backends: Vulkan: moved ImGui_ImplVulkanH_DestroyFrameRenderBuffers/ImGui_ImplVulkanH_DestroyWindowRenderBuffers as they are always used in a state where backend data is available. 70bb6d1e790 Backends: Vulkan: Fixed vkMapMemory() calls unnecessarily using full buffer size. (#3957) 82df7c8bf41 Backends: Vulkan: Fixed handling of ImGui_ImplVulkan_InitInfo::MinAllocationSize field. (#7189, #4238) 29809d72202 Version 1.90.2 WIP db049db8608 Docs: tweak, fixed misplaced changelog entry. (#7084) git-subtree-dir: external/imgui/imgui git-subtree-split: 277ae93c41314ba5f4c7444f37c4319cdf07e8cf
261 lines
11 KiB
C++
261 lines
11 KiB
C++
// dear imgui: Renderer Backend for SDL_Renderer for SDL3
|
|
// (Requires: SDL 3.0.0+)
|
|
|
|
// Note how SDL_Renderer is an _optional_ component of SDL3.
|
|
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX.
|
|
// If your application will want to render any non trivial amount of graphics other than UI,
|
|
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and
|
|
// it might be difficult to step out of those boundaries.
|
|
|
|
// Implemented features:
|
|
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
|
|
|
// You can copy and 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
|
|
|
|
// CHANGELOG
|
|
// 2024-02-12: Amend to query SDL_RenderViewportSet() and restore viewport accordingly.
|
|
// 2023-05-30: Initial version.
|
|
|
|
#include "imgui.h"
|
|
#ifndef IMGUI_DISABLE
|
|
#include "imgui_impl_sdlrenderer3.h"
|
|
#include <stdint.h> // intptr_t
|
|
|
|
// Clang warnings with -Weverything
|
|
#if defined(__clang__)
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
|
#endif
|
|
|
|
// SDL
|
|
#include <SDL3/SDL.h>
|
|
#if !SDL_VERSION_ATLEAST(3,0,0)
|
|
#error This backend requires SDL 3.0.0+
|
|
#endif
|
|
|
|
// SDL_Renderer data
|
|
struct ImGui_ImplSDLRenderer3_Data
|
|
{
|
|
SDL_Renderer* SDLRenderer;
|
|
SDL_Texture* FontTexture;
|
|
ImGui_ImplSDLRenderer3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
|
};
|
|
|
|
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
static ImGui_ImplSDLRenderer3_Data* ImGui_ImplSDLRenderer3_GetBackendData()
|
|
{
|
|
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
}
|
|
|
|
// Functions
|
|
bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer)
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
IM_ASSERT(renderer != nullptr && "SDL_Renderer not initialized!");
|
|
|
|
// Setup backend capabilities flags
|
|
ImGui_ImplSDLRenderer3_Data* bd = IM_NEW(ImGui_ImplSDLRenderer3_Data)();
|
|
io.BackendRendererUserData = (void*)bd;
|
|
io.BackendRendererName = "imgui_impl_sdlrenderer3";
|
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
|
|
bd->SDLRenderer = renderer;
|
|
|
|
return true;
|
|
}
|
|
|
|
void ImGui_ImplSDLRenderer3_Shutdown()
|
|
{
|
|
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
ImGui_ImplSDLRenderer3_DestroyDeviceObjects();
|
|
|
|
io.BackendRendererName = nullptr;
|
|
io.BackendRendererUserData = nullptr;
|
|
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
|
IM_DELETE(bd);
|
|
}
|
|
|
|
static void ImGui_ImplSDLRenderer3_SetupRenderState()
|
|
{
|
|
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
|
|
// Clear out any viewports and cliprect set by the user
|
|
// FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process.
|
|
SDL_SetRenderViewport(bd->SDLRenderer, nullptr);
|
|
SDL_SetRenderClipRect(bd->SDLRenderer, nullptr);
|
|
}
|
|
|
|
void ImGui_ImplSDLRenderer3_NewFrame()
|
|
{
|
|
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDLRenderer3_Init()?");
|
|
|
|
if (!bd->FontTexture)
|
|
ImGui_ImplSDLRenderer3_CreateDeviceObjects();
|
|
}
|
|
|
|
void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data)
|
|
{
|
|
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
|
|
// If there's a scale factor set by the user, use that instead
|
|
// If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass
|
|
// to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here.
|
|
float rsx = 1.0f;
|
|
float rsy = 1.0f;
|
|
SDL_GetRenderScale(bd->SDLRenderer, &rsx, &rsy);
|
|
ImVec2 render_scale;
|
|
render_scale.x = (rsx == 1.0f) ? draw_data->FramebufferScale.x : 1.0f;
|
|
render_scale.y = (rsy == 1.0f) ? draw_data->FramebufferScale.y : 1.0f;
|
|
|
|
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
|
int fb_width = (int)(draw_data->DisplaySize.x * render_scale.x);
|
|
int fb_height = (int)(draw_data->DisplaySize.y * render_scale.y);
|
|
if (fb_width == 0 || fb_height == 0)
|
|
return;
|
|
|
|
// Backup SDL_Renderer state that will be modified to restore it afterwards
|
|
struct BackupSDLRendererState
|
|
{
|
|
SDL_Rect Viewport;
|
|
bool ViewportEnabled;
|
|
bool ClipEnabled;
|
|
SDL_Rect ClipRect;
|
|
};
|
|
BackupSDLRendererState old = {};
|
|
old.ViewportEnabled = SDL_RenderViewportSet(bd->SDLRenderer) == SDL_TRUE;
|
|
old.ClipEnabled = SDL_RenderClipEnabled(bd->SDLRenderer) == SDL_TRUE;
|
|
SDL_GetRenderViewport(bd->SDLRenderer, &old.Viewport);
|
|
SDL_GetRenderClipRect(bd->SDLRenderer, &old.ClipRect);
|
|
|
|
// Will project scissor/clipping rectangles into framebuffer space
|
|
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
|
ImVec2 clip_scale = render_scale;
|
|
|
|
// Render command lists
|
|
ImGui_ImplSDLRenderer3_SetupRenderState();
|
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
{
|
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
|
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
|
|
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
{
|
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
if (pcmd->UserCallback)
|
|
{
|
|
// User callback, registered via ImDrawList::AddCallback()
|
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
|
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
ImGui_ImplSDLRenderer3_SetupRenderState();
|
|
else
|
|
pcmd->UserCallback(cmd_list, pcmd);
|
|
}
|
|
else
|
|
{
|
|
// Project scissor/clipping rectangles into framebuffer space
|
|
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
|
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
|
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
|
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
|
|
if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; }
|
|
if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; }
|
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
continue;
|
|
|
|
SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) };
|
|
SDL_SetRenderClipRect(bd->SDLRenderer, &r);
|
|
|
|
const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, pos));
|
|
const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, uv));
|
|
const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, col)); // SDL 2.0.19+
|
|
|
|
// Bind texture, Draw
|
|
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
|
SDL_RenderGeometryRaw(bd->SDLRenderer, tex,
|
|
xy, (int)sizeof(ImDrawVert),
|
|
color, (int)sizeof(ImDrawVert),
|
|
uv, (int)sizeof(ImDrawVert),
|
|
cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
|
|
idx_buffer + pcmd->IdxOffset, pcmd->ElemCount, sizeof(ImDrawIdx));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Restore modified SDL_Renderer state
|
|
SDL_SetRenderViewport(bd->SDLRenderer, old.ViewportEnabled ? &old.Viewport : nullptr);
|
|
SDL_SetRenderClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : nullptr);
|
|
}
|
|
|
|
// Called by Init/NewFrame/Shutdown
|
|
bool ImGui_ImplSDLRenderer3_CreateFontsTexture()
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
|
|
// Build texture atlas
|
|
unsigned char* pixels;
|
|
int width, height;
|
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
|
|
|
// Upload texture to graphics system
|
|
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
|
bd->FontTexture = SDL_CreateTexture(bd->SDLRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height);
|
|
if (bd->FontTexture == nullptr)
|
|
{
|
|
SDL_Log("error creating texture");
|
|
return false;
|
|
}
|
|
SDL_UpdateTexture(bd->FontTexture, nullptr, pixels, 4 * width);
|
|
SDL_SetTextureBlendMode(bd->FontTexture, SDL_BLENDMODE_BLEND);
|
|
SDL_SetTextureScaleMode(bd->FontTexture, SDL_SCALEMODE_LINEAR);
|
|
|
|
// Store our identifier
|
|
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
|
|
|
|
return true;
|
|
}
|
|
|
|
void ImGui_ImplSDLRenderer3_DestroyFontsTexture()
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGui_ImplSDLRenderer3_Data* bd = ImGui_ImplSDLRenderer3_GetBackendData();
|
|
if (bd->FontTexture)
|
|
{
|
|
io.Fonts->SetTexID(0);
|
|
SDL_DestroyTexture(bd->FontTexture);
|
|
bd->FontTexture = nullptr;
|
|
}
|
|
}
|
|
|
|
bool ImGui_ImplSDLRenderer3_CreateDeviceObjects()
|
|
{
|
|
return ImGui_ImplSDLRenderer3_CreateFontsTexture();
|
|
}
|
|
|
|
void ImGui_ImplSDLRenderer3_DestroyDeviceObjects()
|
|
{
|
|
ImGui_ImplSDLRenderer3_DestroyFontsTexture();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#if defined(__clang__)
|
|
#pragma clang diagnostic pop
|
|
#endif
|
|
|
|
#endif // #ifndef IMGUI_DISABLE
|