diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 46ff6891..9bc81bf8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: VS_PATH: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\ MSBUILD_PATH: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\ steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: path: ${{ github.workspace }}/imgui @@ -274,7 +274,7 @@ jobs: working-directory: ${{ github.workspace }}/imgui steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: path: ${{ github.workspace }}/imgui @@ -514,7 +514,7 @@ jobs: working-directory: ${{ github.workspace }}/imgui steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: path: ${{ github.workspace }}/imgui @@ -596,7 +596,7 @@ jobs: name: Build - iOS steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: Build example_apple_metal run: | @@ -608,7 +608,7 @@ jobs: name: Build - Emscripten steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: Install Dependencies run: | @@ -651,7 +651,7 @@ jobs: name: Build - Android steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: Build example_android_opengl3 run: | @@ -670,11 +670,11 @@ jobs: MSBUILD_PATH: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\ steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: path: ${{ github.workspace }}/imgui - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 continue-on-error: true with: fetch-depth: 1 @@ -725,11 +725,11 @@ jobs: working-directory: ${{ github.workspace }}/imgui steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: path: ${{ github.workspace }}/imgui - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: fetch-depth: 1 repository: ocornut/imgui_test_engine @@ -763,11 +763,11 @@ jobs: # working-directory: ${{ github.workspace }}/imgui # # steps: -# - uses: actions/checkout@v5 +# - uses: actions/checkout@v6 # with: # path: ${{ github.workspace }}/imgui # -# - uses: actions/checkout@v5 +# - uses: actions/checkout@v6 # with: # fetch-depth: 1 # repository: ocornut/imgui_test_engine diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 53db0476..29562836 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,7 +12,7 @@ jobs: PVS-Studio: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 1 diff --git a/backends/imgui_impl_dx10.cpp b/backends/imgui_impl_dx10.cpp index 5650a3c8..11879832 100644 --- a/backends/imgui_impl_dx10.cpp +++ b/backends/imgui_impl_dx10.cpp @@ -16,6 +16,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-01-19: DirectX11: Added 'SamplerNearest' in ImGui_ImplDX11_RenderState. Renamed 'SamplerDefault' to 'SamplerLinear'. // 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown. // 2025-06-11: DirectX10: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. // 2025-05-07: DirectX10: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows). @@ -75,6 +76,7 @@ struct ImGui_ImplDX10_Data ID3D10Buffer* pVertexConstantBuffer; ID3D10PixelShader* pPixelShader; ID3D10SamplerState* pTexSamplerLinear; + ID3D10SamplerState* pTexSamplerNearest; ID3D10RasterizerState* pRasterizerState; ID3D10BlendState* pBlendState; ID3D10DepthStencilState* pDepthStencilState; @@ -258,7 +260,8 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data) ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); ImGui_ImplDX10_RenderState render_state; render_state.Device = bd->pd3dDevice; - render_state.SamplerDefault = bd->pTexSamplerLinear; + render_state.SamplerLinear = bd->pTexSamplerLinear; + render_state.SamplerNearest = bd->pTexSamplerNearest; render_state.VertexConstantBuffer = bd->pVertexConstantBuffer; platform_io.Renderer_RenderState = &render_state; @@ -565,6 +568,8 @@ bool ImGui_ImplDX10_CreateDeviceObjects() desc.MinLOD = 0.f; desc.MaxLOD = 0.f; bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerLinear); + desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT; + bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerNearest); } return true; @@ -581,6 +586,7 @@ void ImGui_ImplDX10_InvalidateDeviceObjects() if (tex->RefCount == 1) ImGui_ImplDX10_DestroyTexture(tex); if (bd->pTexSamplerLinear) { bd->pTexSamplerLinear->Release(); bd->pTexSamplerLinear = nullptr; } + if (bd->pTexSamplerNearest) { bd->pTexSamplerNearest->Release(); bd->pTexSamplerNearest = nullptr; } if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; } diff --git a/backends/imgui_impl_dx10.h b/backends/imgui_impl_dx10.h index 9d7fb68a..87945d64 100644 --- a/backends/imgui_impl_dx10.h +++ b/backends/imgui_impl_dx10.h @@ -41,7 +41,8 @@ IMGUI_IMPL_API void ImGui_ImplDX10_UpdateTexture(ImTextureData* tex); struct ImGui_ImplDX10_RenderState { ID3D10Device* Device; - ID3D10SamplerState* SamplerDefault; + ID3D10SamplerState* SamplerLinear; + ID3D10SamplerState* SamplerNearest; ID3D10Buffer* VertexConstantBuffer; }; diff --git a/backends/imgui_impl_dx11.cpp b/backends/imgui_impl_dx11.cpp index 87893040..193127b4 100644 --- a/backends/imgui_impl_dx11.cpp +++ b/backends/imgui_impl_dx11.cpp @@ -17,6 +17,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-01-19: DirectX11: Added 'SamplerNearest' in ImGui_ImplDX11_RenderState. Renamed 'SamplerDefault' to 'SamplerLinear'. // 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown. // 2025-06-11: DirectX11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. // 2025-05-07: DirectX11: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows). @@ -78,6 +79,7 @@ struct ImGui_ImplDX11_Data ID3D11Buffer* pVertexConstantBuffer; ID3D11PixelShader* pPixelShader; ID3D11SamplerState* pTexSamplerLinear; + ID3D11SamplerState* pTexSamplerNearest; ID3D11RasterizerState* pRasterizerState; ID3D11BlendState* pBlendState; ID3D11DepthStencilState* pDepthStencilState; @@ -272,7 +274,8 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) ImGui_ImplDX11_RenderState render_state; render_state.Device = bd->pd3dDevice; render_state.DeviceContext = bd->pd3dDeviceContext; - render_state.SamplerDefault = bd->pTexSamplerLinear; + render_state.SamplerLinear = bd->pTexSamplerLinear; + render_state.SamplerNearest = bd->pTexSamplerNearest; render_state.VertexConstantBuffer = bd->pVertexConstantBuffer; platform_io.Renderer_RenderState = &render_state; @@ -580,6 +583,8 @@ bool ImGui_ImplDX11_CreateDeviceObjects() desc.MinLOD = 0.f; desc.MaxLOD = 0.f; bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerLinear); + desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + bd->pd3dDevice->CreateSamplerState(&desc, &bd->pTexSamplerNearest); } return true; @@ -597,6 +602,7 @@ void ImGui_ImplDX11_InvalidateDeviceObjects() ImGui_ImplDX11_DestroyTexture(tex); if (bd->pTexSamplerLinear) { bd->pTexSamplerLinear->Release(); bd->pTexSamplerLinear = nullptr; } + if (bd->pTexSamplerNearest) { bd->pTexSamplerNearest->Release(); bd->pTexSamplerNearest = nullptr; } if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; } diff --git a/backends/imgui_impl_dx11.h b/backends/imgui_impl_dx11.h index 1df4f369..338e0093 100644 --- a/backends/imgui_impl_dx11.h +++ b/backends/imgui_impl_dx11.h @@ -44,7 +44,8 @@ struct ImGui_ImplDX11_RenderState { ID3D11Device* Device; ID3D11DeviceContext* DeviceContext; - ID3D11SamplerState* SamplerDefault; + ID3D11SamplerState* SamplerLinear; + ID3D11SamplerState* SamplerNearest; ID3D11Buffer* VertexConstantBuffer; }; diff --git a/backends/imgui_impl_dx12.cpp b/backends/imgui_impl_dx12.cpp index 056d23a6..a5420782 100644 --- a/backends/imgui_impl_dx12.cpp +++ b/backends/imgui_impl_dx12.cpp @@ -93,8 +93,10 @@ struct ImGui_ImplDX12_Data ImGui_ImplDX12_InitInfo InitInfo; IDXGIFactory5* pdxgiFactory; ID3D12Device* pd3dDevice; - ID3D12RootSignature* pRootSignature; - ID3D12PipelineState* pPipelineState; + ID3D12RootSignature* pRootSignatureLinear; + ID3D12RootSignature* pRootSignatureNearest; + ID3D12PipelineState* pPipelineStateLinear; + ID3D12PipelineState* pPipelineStateNearest; ID3D12CommandQueue* pCommandQueue; bool commandQueueOwned; DXGI_FORMAT RTVFormat; @@ -140,11 +142,27 @@ struct VERTEX_CONSTANT_BUFFER_DX12 float mvp[4][4]; }; +// FIXME-WIP: Allow user to forward declare those two, for until we come up with a backend agnostic API to do this. (#9173) +void ImGui_ImplDX12_SetupSamplerLinear(ID3D12GraphicsCommandList* command_list); +void ImGui_ImplDX12_SetupSamplerNearest(ID3D12GraphicsCommandList* command_list); + // Functions -static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12GraphicsCommandList* command_list, ImGui_ImplDX12_RenderBuffers* fr) +void ImGui_ImplDX12_SetupSamplerLinear(ID3D12GraphicsCommandList* command_list) { ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); + command_list->SetPipelineState(bd->pPipelineStateLinear); + command_list->SetGraphicsRootSignature(bd->pRootSignatureLinear); +} +void ImGui_ImplDX12_SetupSamplerNearest(ID3D12GraphicsCommandList* command_list) +{ + ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); + command_list->SetPipelineState(bd->pPipelineStateNearest); + command_list->SetGraphicsRootSignature(bd->pRootSignatureNearest); +} + +static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12GraphicsCommandList* command_list, ImGui_ImplDX12_RenderBuffers* fr) +{ // Setup orthographic projection matrix into our constant buffer // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). VERTEX_CONSTANT_BUFFER_DX12 vertex_constant_buffer; @@ -186,8 +204,7 @@ static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12Graphic ibv.Format = sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; command_list->IASetIndexBuffer(&ibv); command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - command_list->SetPipelineState(bd->pPipelineState); - command_list->SetGraphicsRootSignature(bd->pRootSignature); + ImGui_ImplDX12_SetupSamplerLinear(command_list); command_list->SetGraphicsRoot32BitConstants(0, 16, &vertex_constant_buffer, 0); // Setup blend factor @@ -555,7 +572,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects() ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); if (!bd || !bd->pd3dDevice) return false; - if (bd->pPipelineState) + if (bd->pPipelineStateLinear) ImGui_ImplDX12_InvalidateDeviceObjects(); HRESULT hr = ::CreateDXGIFactory1(IID_PPV_ARGS(&bd->pdxgiFactory)); @@ -644,7 +661,15 @@ bool ImGui_ImplDX12_CreateDeviceObjects() if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr) != S_OK) return false; - bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignature)); + bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignatureLinear)); + blob->Release(); + + // Root Signature for ImDrawCallback_SetSamplerNearest + staticSampler[0].Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; + if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr) != S_OK) + return false; + + bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignatureNearest)); blob->Release(); } @@ -657,7 +682,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects() D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.NodeMask = 1; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; - psoDesc.pRootSignature = bd->pRootSignature; + psoDesc.pRootSignature = bd->pRootSignatureLinear; psoDesc.SampleMask = UINT_MAX; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = bd->RTVFormat; @@ -780,7 +805,18 @@ bool ImGui_ImplDX12_CreateDeviceObjects() desc.BackFace = desc.FrontFace; } - HRESULT result_pipeline_state = bd->pd3dDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&bd->pPipelineState)); + HRESULT result_pipeline_state = bd->pd3dDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&bd->pPipelineStateLinear)); + if (result_pipeline_state != S_OK) + { + vertexShaderBlob->Release(); + pixelShaderBlob->Release(); + return false; + } + + // Pipeline State for ImDrawCallback_SetSamplerNearest + psoDesc.pRootSignature = bd->pRootSignatureNearest; + + result_pipeline_state = bd->pd3dDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&bd->pPipelineStateNearest)); vertexShaderBlob->Release(); pixelShaderBlob->Release(); if (result_pipeline_state != S_OK) @@ -813,8 +849,11 @@ void ImGui_ImplDX12_InvalidateDeviceObjects() if (bd->commandQueueOwned) SafeRelease(bd->pCommandQueue); bd->commandQueueOwned = false; - SafeRelease(bd->pRootSignature); - SafeRelease(bd->pPipelineState); + SafeRelease(bd->pRootSignatureLinear); + SafeRelease(bd->pRootSignatureNearest); + SafeRelease(bd->pPipelineStateLinear); + SafeRelease(bd->pPipelineStateNearest); + if (bd->pTexUploadBufferMapped) { D3D12_RANGE range = { 0, bd->pTexUploadBufferSize }; @@ -961,7 +1000,7 @@ void ImGui_ImplDX12_NewFrame() ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData(); IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplDX12_Init()?"); - if (!bd->pPipelineState) + if (!bd->pPipelineStateLinear) if (!ImGui_ImplDX12_CreateDeviceObjects()) IM_ASSERT(0 && "ImGui_ImplDX12_CreateDeviceObjects() failed!"); } diff --git a/backends/imgui_impl_dx12.h b/backends/imgui_impl_dx12.h index 8d61dae7..b8be8db2 100644 --- a/backends/imgui_impl_dx12.h +++ b/backends/imgui_impl_dx12.h @@ -24,6 +24,12 @@ #include // DXGI_FORMAT #include // D3D12_CPU_DESCRIPTOR_HANDLE +// Clang/GCC warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast +#endif + // Initialization data, for ImGui_ImplDX12_Init() struct ImGui_ImplDX12_InitInfo { @@ -44,7 +50,7 @@ struct ImGui_ImplDX12_InitInfo D3D12_GPU_DESCRIPTOR_HANDLE LegacySingleSrvGpuDescriptor; #endif - ImGui_ImplDX12_InitInfo() { memset(this, 0, sizeof(*this)); } + ImGui_ImplDX12_InitInfo() { memset((void*)this, 0, sizeof(*this)); } }; // Follow "Getting Started" link and check examples/ folder to learn about using backends! @@ -76,4 +82,8 @@ struct ImGui_ImplDX12_RenderState ID3D12GraphicsCommandList* CommandList; }; +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index f166b45d..da54589f 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -29,6 +29,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-02-10: Try to set IMGUI_IMPL_GLFW_DISABLE_X11 / IMGUI_IMPL_GLFW_DISABLE_WAYLAND automatically if corresponding headers are not accessible. (#9225) // 2025-12-12: Added IMGUI_IMPL_GLFW_DISABLE_X11 / IMGUI_IMPL_GLFW_DISABLE_WAYLAND to forcefully disable either. // 2025-12-10: Avoid repeated glfwSetCursor()/glfwSetInputMode() calls when unnecessary. Lowers overhead for very high framerates (e.g. 10k+ FPS). // 2025-11-06: Lower minimum requirement to GLFW 3.0. Though a recent version e.g GLFW 3.4 is highly recommended. @@ -109,6 +110,15 @@ #pragma clang diagnostic ignored "-Wglobal-constructors" // warning: declaration requires a global destructor // similar to above, not sure what the exact difference is. #endif +#if defined(__has_include) +#if !__has_include() || !__has_include() +#define IMGUI_IMPL_GLFW_DISABLE_X11 +#endif +#if !__has_include() +#define IMGUI_IMPL_GLFW_DISABLE_WAYLAND +#endif +#endif + // GLFW #if !defined(IMGUI_IMPL_GLFW_DISABLE_X11) && (defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)) #define GLFW_HAS_X11 1 diff --git a/backends/imgui_impl_glfw.h b/backends/imgui_impl_glfw.h index c01600d0..7dc8cb5e 100644 --- a/backends/imgui_impl_glfw.h +++ b/backends/imgui_impl_glfw.h @@ -48,7 +48,7 @@ IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* wi IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); -// GFLW callbacks options: +// GLFW callbacks options: // - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user) IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows); diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index 4fb9c4d9..f578977c 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -21,6 +21,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-02-13: Inputs: systems other than X11 are back to starting mouse capture on mouse down (reverts 2025-02-26 change). Only X11 requires waiting for a drag by default (not ideal, but a better default for X11 users). Added ImGui_ImplSDL2_SetMouseCaptureMode() for X11 debugger users. (#3650, #6410, #9235) // 2026-01-15: Changed GetClipboardText() handler to return nullptr on error aka clipboard contents is not text. Consistent with other backends. (#9168) // 2025-09-24: Skip using the SDL_GetGlobalMouseState() state when one of our window is hovered, as the SDL_MOUSEMOTION data is reliable. Fix macOS notch mouse coordinates issue in fullscreen mode + better perf on X11. (#7919, #7786) // 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown. @@ -30,7 +31,7 @@ // 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561) // 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set. // 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468) -// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g.Linux debuggers not claiming capture back. (#6410, #3650) +// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g. Linux debuggers not claiming capture back. (#6410, #3650) // 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode. // 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support. // 2025-02-10: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler. @@ -154,7 +155,7 @@ struct ImGui_ImplSDL2_Data SDL_Cursor* MouseLastCursor; int MouseLastLeaveFrame; bool MouseCanUseGlobalState; - bool MouseCanUseCapture; + ImGui_ImplSDL2_MouseCaptureMode MouseCaptureMode; // Gamepad handling ImVector Gamepads; @@ -514,13 +515,16 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void // Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse() // ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list) bd->MouseCanUseGlobalState = false; - bd->MouseCanUseCapture = false; + bd->MouseCaptureMode = ImGui_ImplSDL2_MouseCaptureMode_Disabled; #if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE const char* sdl_backend = SDL_GetCurrentVideoDriver(); const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" }; for (const char* item : capture_and_global_state_whitelist) if (strncmp(sdl_backend, item, strlen(item)) == 0) - bd->MouseCanUseGlobalState = bd->MouseCanUseCapture = true; + { + bd->MouseCanUseGlobalState = true; + bd->MouseCaptureMode = (strcmp(item, "x11") == 0) ? ImGui_ImplSDL2_MouseCaptureMode_EnabledAfterDrag : ImGui_ImplSDL2_MouseCaptureMode_Enabled; + } #endif ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); @@ -650,6 +654,14 @@ void ImGui_ImplSDL2_Shutdown() IM_DELETE(bd); } +void ImGui_ImplSDL2_SetMouseCaptureMode(ImGui_ImplSDL2_MouseCaptureMode mode) +{ + ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData(); + if (mode == ImGui_ImplSDL2_MouseCaptureMode_Disabled && bd->MouseCaptureMode != ImGui_ImplSDL2_MouseCaptureMode_Disabled) + SDL_CaptureMouse(SDL_FALSE); + bd->MouseCaptureMode = mode; +} + static void ImGui_ImplSDL2_UpdateMouseData() { ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData(); @@ -658,8 +670,12 @@ static void ImGui_ImplSDL2_UpdateMouseData() // We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below) #if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE // - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside. - // - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue we wait until mouse has moved to begin capture. - if (bd->MouseCanUseCapture) + // - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue on X11 we we wait until mouse has moved to begin capture. + if (bd->MouseCaptureMode == ImGui_ImplSDL2_MouseCaptureMode_Enabled) + { + SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE); + } + else if (bd->MouseCaptureMode == ImGui_ImplSDL2_MouseCaptureMode_EnabledAfterDrag) { bool want_capture = false; for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++) diff --git a/backends/imgui_impl_sdl2.h b/backends/imgui_impl_sdl2.h index 3c0a4a7e..63ef7071 100644 --- a/backends/imgui_impl_sdl2.h +++ b/backends/imgui_impl_sdl2.h @@ -47,4 +47,11 @@ IMGUI_IMPL_API float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_ind 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 = nullptr, int manual_gamepads_count = -1); +// (Advanced, for X11 users) Override Mouse Capture mode. Mouse capture allows receiving updated mouse position after clicking inside our window and dragging outside it. +// Having this 'Enabled' is in theory always better. But, on X11 if you crash/break to debugger while capture is active you may temporarily lose access to your mouse. +// The best solution is to setup your debugger to automatically release capture, e.g. 'setxkbmap -option grab:break_actions && xdotool key XF86Ungrab' or via a GDB script. See #3650. +// But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL2_MouseCaptureMode_Disabled. +enum ImGui_ImplSDL2_MouseCaptureMode { ImGui_ImplSDL2_MouseCaptureMode_Enabled, ImGui_ImplSDL2_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL2_MouseCaptureMode_Disabled }; +IMGUI_IMPL_API void ImGui_ImplSDL2_SetMouseCaptureMode(ImGui_ImplSDL2_MouseCaptureMode mode); + #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index f8bacc51..a2bd606a 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -20,6 +20,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-02-13: Inputs: systems other than X11 are back to starting mouse capture on mouse down (reverts 2025-02-26 change). Only X11 requires waiting for a drag by default (not ideal, but a better default for X11 users). Added ImGui_ImplSDL3_SetMouseCaptureMode() for X11 debugger users. (#3650, #6410, #9235) // 2026-01-15: Changed GetClipboardText() handler to return nullptr on error aka clipboard contents is not text. Consistent with other backends. (#9168) // 2025-11-05: Fixed an issue with missing characters events when an already active text field changes viewports. (#9054) // 2025-10-22: Fixed Platform_OpenInShellFn() return value (unused in core). @@ -32,7 +33,7 @@ // 2025-03-30: Update for SDL3 api changes: Revert SDL_GetClipboardText() memory ownership change. (#8530, #7801) // 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set. // 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468) -// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g.Linux debuggers not claiming capture back. (#6410, #3650) +// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g. Linux debuggers not claiming capture back. (#6410, #3650) // 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode. // 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support. // 2025-02-10: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler. @@ -124,7 +125,7 @@ struct ImGui_ImplSDL3_Data SDL_Cursor* MouseLastCursor; int MousePendingLeaveFrame; bool MouseCanUseGlobalState; - bool MouseCanUseCapture; + ImGui_ImplSDL3_MouseCaptureMode MouseCaptureMode; // Gamepad handling ImVector Gamepads; @@ -518,13 +519,16 @@ static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void // Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse() // ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list) bd->MouseCanUseGlobalState = false; - bd->MouseCanUseCapture = false; + bd->MouseCaptureMode = ImGui_ImplSDL3_MouseCaptureMode_Disabled; #if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE const char* sdl_backend = SDL_GetCurrentVideoDriver(); const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" }; for (const char* item : capture_and_global_state_whitelist) if (strncmp(sdl_backend, item, strlen(item)) == 0) - bd->MouseCanUseGlobalState = bd->MouseCanUseCapture = true; + { + bd->MouseCanUseGlobalState = true; + bd->MouseCaptureMode = (strcmp(item, "x11") == 0) ? ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag : ImGui_ImplSDL3_MouseCaptureMode_Enabled; + } #endif ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); @@ -629,6 +633,14 @@ void ImGui_ImplSDL3_Shutdown() IM_DELETE(bd); } +void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode) +{ + ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); + if (mode == ImGui_ImplSDL3_MouseCaptureMode_Disabled && bd->MouseCaptureMode != ImGui_ImplSDL3_MouseCaptureMode_Disabled) + SDL_CaptureMouse(false); + bd->MouseCaptureMode = mode; +} + static void ImGui_ImplSDL3_UpdateMouseData() { ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData(); @@ -637,8 +649,12 @@ static void ImGui_ImplSDL3_UpdateMouseData() // We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below) #if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE // - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside. - // - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue we wait until mouse has moved to begin capture. - if (bd->MouseCanUseCapture) + // - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue on X11 we we wait until mouse has moved to begin capture. + if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_Enabled) + { + SDL_CaptureMouse(bd->MouseButtonsDown != 0); + } + else if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag) { bool want_capture = false; for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++) diff --git a/backends/imgui_impl_sdl3.h b/backends/imgui_impl_sdl3.h index a822a259..0720283c 100644 --- a/backends/imgui_impl_sdl3.h +++ b/backends/imgui_impl_sdl3.h @@ -44,4 +44,11 @@ IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event); enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual }; IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1); +// (Advanced, for X11 users) Override Mouse Capture mode. Mouse capture allows receiving updated mouse position after clicking inside our window and dragging outside it. +// Having this 'Enabled' is in theory always better. But, on X11 if you crash/break to debugger while capture is active you may temporarily lose access to your mouse. +// The best solution is to setup your debugger to automatically release capture, e.g. 'setxkbmap -option grab:break_actions && xdotool key XF86Ungrab' or via a GDB script. See #3650. +// But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL3_MouseCaptureMode_Disabled. +enum ImGui_ImplSDL3_MouseCaptureMode { ImGui_ImplSDL3_MouseCaptureMode_Enabled, ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL3_MouseCaptureMode_Disabled }; +IMGUI_IMPL_API void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode); + #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_sdlgpu3.cpp b/backends/imgui_impl_sdlgpu3.cpp index e5934c30..78392305 100644 --- a/backends/imgui_impl_sdlgpu3.cpp +++ b/backends/imgui_impl_sdlgpu3.cpp @@ -22,6 +22,7 @@ // Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info. // CHANGELOG +// 2026-02-25: Removed unnecessary call to SDL_WaitForGPUIdle when releasing vertex/index buffers. (#9262) // 2025-11-26: macOS version can use MSL shaders in order to support macOS 10.14+ (vs Metallib shaders requiring macOS 14+). Requires calling SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL. // 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown. // 2025-08-20: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and ImGui_ImplSDLGPU3_InitInfo::PresentMode to configure how secondary viewports are created. @@ -62,6 +63,7 @@ struct ImGui_ImplSDLGPU3_Data SDL_GPUShader* FragmentShader = nullptr; SDL_GPUGraphicsPipeline* Pipeline = nullptr; SDL_GPUSampler* TexSamplerLinear = nullptr; + SDL_GPUSampler* TexSamplerNearest = nullptr; SDL_GPUTransferBuffer* TexTransferBuffer = nullptr; uint32_t TexTransferBufferSize = 0; @@ -130,8 +132,7 @@ static void CreateOrResizeBuffers(SDL_GPUBuffer** buffer, SDL_GPUTransferBuffer* ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; - // FIXME-OPT: Not optimal, but this is fairly rarely called. - SDL_WaitForGPUIdle(v->Device); + // There is no need for calling SDL_WaitForGPUIdle here, as SDL3 will handle deferred buffer deletion automatically. SDL_ReleaseGPUBuffer(v->Device, *buffer); SDL_ReleaseGPUTransferBuffer(v->Device, *transferbuffer); @@ -236,7 +237,8 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); ImGui_ImplSDLGPU3_RenderState render_state; render_state.Device = bd->InitInfo.Device; - render_state.SamplerDefault = render_state.SamplerCurrent = bd->TexSamplerLinear; + render_state.SamplerLinear = render_state.SamplerCurrent = bd->TexSamplerLinear; + render_state.SamplerNearest = bd->TexSamplerNearest; platform_io.Renderer_RenderState = &render_state; ImGui_ImplSDLGPU3_SetupRenderState(draw_data, &render_state, pipeline, command_buffer, render_pass, fd, fb_width, fb_height); @@ -592,9 +594,14 @@ void ImGui_ImplSDLGPU3_CreateDeviceObjects() sampler_info.enable_anisotropy = false; sampler_info.max_anisotropy = 1.0f; sampler_info.enable_compare = false; - bd->TexSamplerLinear = SDL_CreateGPUSampler(v->Device, &sampler_info); IM_ASSERT(bd->TexSamplerLinear != nullptr && "Failed to create sampler, call SDL_GetError() for more information"); + + sampler_info.min_filter = SDL_GPU_FILTER_NEAREST; + sampler_info.mag_filter = SDL_GPU_FILTER_NEAREST; + sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST; + bd->TexSamplerNearest = SDL_CreateGPUSampler(v->Device, &sampler_info); + IM_ASSERT(bd->TexSamplerNearest != nullptr && "Failed to create sampler, call SDL_GetError() for more information"); } ImGui_ImplSDLGPU3_CreateGraphicsPipeline(); @@ -630,6 +637,7 @@ void ImGui_ImplSDLGPU3_DestroyDeviceObjects() if (bd->VertexShader) { SDL_ReleaseGPUShader(v->Device, bd->VertexShader); bd->VertexShader = nullptr; } if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->Device, bd->FragmentShader); bd->FragmentShader = nullptr; } if (bd->TexSamplerLinear) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerLinear); bd->TexSamplerLinear = nullptr; } + if (bd->TexSamplerNearest) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerNearest); bd->TexSamplerNearest = nullptr; } if (bd->Pipeline) { SDL_ReleaseGPUGraphicsPipeline(v->Device, bd->Pipeline); bd->Pipeline = nullptr; } } diff --git a/backends/imgui_impl_sdlgpu3.h b/backends/imgui_impl_sdlgpu3.h index 12b6528f..1c73dfd7 100644 --- a/backends/imgui_impl_sdlgpu3.h +++ b/backends/imgui_impl_sdlgpu3.h @@ -57,7 +57,8 @@ IMGUI_IMPL_API void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex); struct ImGui_ImplSDLGPU3_RenderState { SDL_GPUDevice* Device; - SDL_GPUSampler* SamplerDefault; // Default sampler (bilinear filtering) + SDL_GPUSampler* SamplerLinear; // Bilinear filtering sampler + SDL_GPUSampler* SamplerNearest; // Nearest/point filtering sampler SDL_GPUSampler* SamplerCurrent; // Current sampler (may be changed by callback) }; diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index 8f4bd5a6..7bfd48a3 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -27,6 +27,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-03-11: Vulkan: Added ImGui_ImplVulkan_PipelineInfo::ExtraDynamicStates[] to allow specifying extra dynamic states to add when creating the VkPipeline. (#9211) // 2025-09-26: [Helpers] *BREAKING CHANGE*: Vulkan: Helper ImGui_ImplVulkanH_DestroyWindow() does not call vkDestroySurfaceKHR(): as surface is created by caller of ImGui_ImplVulkanH_CreateOrResizeWindow(), it is more consistent that we don't destroy it. (#9163) // 2026-01-05: [Helpers] *BREAKING CHANGE*: Vulkan: Helper for creating render pass uses ImGui_ImplVulkanH_Window::AttachmentDesc to create render pass. Removed ClearEnabled. (#9152) // 2025-11-24: [Helpers] Vulkan: Helper for creating a swap-chain (used by examples and multi-viewports) selects VkSwapchainCreateInfoKHR's compositeAlpha based on cap.supportedCompositeAlpha. (#8784) @@ -116,6 +117,14 @@ #pragma warning (disable: 4127) // condition expression is constant #endif +// Clang/GCC warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast +#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness +#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision +#pragma clang diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader) +#endif + // Forward Declarations struct ImGui_ImplVulkan_FrameRenderBuffers; struct ImGui_ImplVulkan_WindowRenderBuffers; @@ -1001,11 +1010,13 @@ static VkPipeline ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAlloc blend_info.attachmentCount = 1; blend_info.pAttachments = color_attachment; - VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; + ImVector dynamic_states = info->ExtraDynamicStates; + dynamic_states.push_back(VK_DYNAMIC_STATE_VIEWPORT); + dynamic_states.push_back(VK_DYNAMIC_STATE_SCISSOR); VkPipelineDynamicStateCreateInfo dynamic_state = {}; dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamic_state.dynamicStateCount = (uint32_t)IM_COUNTOF(dynamic_states); - dynamic_state.pDynamicStates = dynamic_states; + dynamic_state.dynamicStateCount = dynamic_states.Size; + dynamic_state.pDynamicStates = dynamic_states.Data; VkGraphicsPipelineCreateInfo create_info = {}; create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; diff --git a/backends/imgui_impl_vulkan.h b/backends/imgui_impl_vulkan.h index 4ad33b8f..c3fef510 100644 --- a/backends/imgui_impl_vulkan.h +++ b/backends/imgui_impl_vulkan.h @@ -50,6 +50,12 @@ //#define IMGUI_IMPL_VULKAN_VOLK_FILENAME // Default // Reminder: make those changes in your imconfig.h file, not here! +// Clang/GCC warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast +#endif + #if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) #define VK_NO_PROTOTYPES #endif @@ -80,6 +86,7 @@ struct ImGui_ImplVulkan_PipelineInfo VkRenderPass RenderPass; // Ignored if using dynamic rendering uint32_t Subpass; // VkSampleCountFlagBits MSAASamples = {}; // 0 defaults to VK_SAMPLE_COUNT_1_BIT + ImVector ExtraDynamicStates; // Optional, allows to insert more dynamic states into our VkPipeline #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR #endif @@ -261,4 +268,8 @@ struct ImGui_ImplVulkanH_Window } }; +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_wgpu.cpp b/backends/imgui_impl_wgpu.cpp index e98e9f3c..2b7edb0b 100644 --- a/backends/imgui_impl_wgpu.cpp +++ b/backends/imgui_impl_wgpu.cpp @@ -20,6 +20,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-03-09: Removed support for Emscripten < 4.0.10. (#9281) // 2025-10-16: Update to compile with Dawn and Emscripten's 4.0.10+ '--use-port=emdawnwebgpu' ports. (#8381, #8898) // 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown. // 2025-06-12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. (#8465) @@ -58,11 +59,8 @@ #if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) #error Exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be defined! #endif - -// This condition is true when it's built with EMSCRIPTEN using -sUSE_WEBGPU=1 flag (deprecated from 4.0.10) -// This condition is false for all other 3 cases: WGPU-Native, DAWN-Native or DAWN-EMSCRIPTEN (using --use-port=emdawnwebgpu flag) #if defined(__EMSCRIPTEN__) && defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN +#error Emscripten <4.0.10 with '-sUSE_WEBGPU=1' is not supported anymore. #endif #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN @@ -261,15 +259,9 @@ static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const c { ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData(); -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) WGPUShaderSourceWGSL wgsl_desc = {}; wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL; wgsl_desc.code = { wgsl_source, WGPU_STRLEN }; -#else - WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; - wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; - wgsl_desc.code = wgsl_source; -#endif WGPUShaderModuleDescriptor desc = {}; desc.nextInChain = (WGPUChainedStruct*)&wgsl_desc; @@ -277,11 +269,7 @@ static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const c WGPUProgrammableStageDescriptor stage_desc = {}; stage_desc.module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc); -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) stage_desc.entryPoint = { "main", WGPU_STRLEN }; -#else - stage_desc.entryPoint = "main"; -#endif return stage_desc; } @@ -400,11 +388,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder WGPUBufferDescriptor vb_desc = { nullptr, -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) { "Dear ImGui Vertex buffer", WGPU_STRLEN, }, -#else - "Dear ImGui Vertex buffer", -#endif WGPUBufferUsage_CopyDst | WGPUBufferUsage_Vertex, MEMALIGN(fr->VertexBufferSize * sizeof(ImDrawVert), 4), false @@ -428,11 +412,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder WGPUBufferDescriptor ib_desc = { nullptr, -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) { "Dear ImGui Index buffer", WGPU_STRLEN, }, -#else - "Dear ImGui Index buffer", -#endif WGPUBufferUsage_CopyDst | WGPUBufferUsage_Index, MEMALIGN(fr->IndexBufferSize * sizeof(ImDrawIdx), 4), false @@ -564,11 +544,7 @@ void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex) // Create texture WGPUTextureDescriptor tex_desc = {}; -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) tex_desc.label = { "Dear ImGui Texture", WGPU_STRLEN }; -#else - tex_desc.label = "Dear ImGui Texture"; -#endif tex_desc.dimension = WGPUTextureDimension_2D; tex_desc.size.width = tex->Width; tex_desc.size.height = tex->Height; @@ -609,20 +585,12 @@ void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex) // Update full texture or selected blocks. We only ever write to textures regions which have never been used before! // This backend choose to use tex->UpdateRect but you can use tex->Updates[] to upload individual regions. -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) WGPUTexelCopyTextureInfo dst_view = {}; -#else - WGPUImageCopyTexture dst_view = {}; -#endif dst_view.texture = backend_tex->Texture; dst_view.mipLevel = 0; dst_view.origin = { (uint32_t)upload_x, (uint32_t)upload_y, 0 }; dst_view.aspect = WGPUTextureAspect_All; -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) WGPUTexelCopyBufferLayout layout = {}; -#else - WGPUTextureDataLayout layout = {}; -#endif layout.offset = 0; layout.bytesPerRow = tex->Width * tex->BytesPerPixel; layout.rowsPerImage = upload_h; @@ -640,11 +608,7 @@ static void ImGui_ImplWGPU_CreateUniformBuffer() WGPUBufferDescriptor ub_desc = { nullptr, -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) { "Dear ImGui Uniform buffer", WGPU_STRLEN, }, -#else - "Dear ImGui Uniform buffer", -#endif WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform, MEMALIGN(sizeof(Uniforms), 16), false @@ -756,11 +720,7 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() // Create depth-stencil State WGPUDepthStencilState depth_stencil_state = {}; depth_stencil_state.format = bd->depthStencilFormat; -#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN) depth_stencil_state.depthWriteEnabled = WGPUOptionalBool_False; -#else - depth_stencil_state.depthWriteEnabled = false; -#endif depth_stencil_state.depthCompare = WGPUCompareFunction_Always; depth_stencil_state.stencilFront.compare = WGPUCompareFunction_Always; depth_stencil_state.stencilFront.failOp = WGPUStencilOperation_Keep; @@ -845,11 +805,7 @@ bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info) io.BackendRendererName = "imgui_impl_wgpu (Dawn, Native)"; #endif #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#if defined(__EMSCRIPTEN__) - io.BackendRendererName = "imgui_impl_wgpu (WGPU, Emscripten)"; // linked using EMSCRIPTEN with "-sUSE_WEBGPU=1" flag, deprecated from EMSCRIPTEN 4.0.10 -#else io.BackendRendererName = "imgui_impl_wgpu (WGPU, Native)"; -#endif #endif io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render. diff --git a/backends/imgui_impl_wgpu.h b/backends/imgui_impl_wgpu.h index 7ab3dd31..346538a4 100644 --- a/backends/imgui_impl_wgpu.h +++ b/backends/imgui_impl_wgpu.h @@ -5,7 +5,8 @@ // When targeting native platforms: // - One of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU *must* be provided. // When targeting Emscripten: -// - We now defaults to IMGUI_IMPL_WEBGPU_BACKEND_DAWN is Emscripten version is 4.0.10+, which correspond to using Emscripten '--use-port=emdawnwebgpu'. +// - We now defaults to IMGUI_IMPL_WEBGPU_BACKEND_DAWN and requires Emscripten 4.0.10+, which correspond to using Emscripten '--use-port=emdawnwebgpu'. +// - Emscripten < 4.0.10 is not supported anymore (old '-sUSE_WEBGPU=1' option). // - We can still define IMGUI_IMPL_WEBGPU_BACKEND_WGPU to use Emscripten '-s USE_WEBGPU=1' which is marked as obsolete by Emscripten. // Add #define to your imconfig.h file, or as a compilation flag in your build system. // This requirement may be removed once WebGPU stabilizes and backends converge on a unified interface. @@ -33,11 +34,7 @@ // Setup Emscripten default if not specified. #if defined(__EMSCRIPTEN__) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) #include -#if (__EMSCRIPTEN_major__ >= 4) && (__EMSCRIPTEN_minor__ >= 0) && (__EMSCRIPTEN_tiny__ >= 10) #define IMGUI_IMPL_WEBGPU_BACKEND_DAWN -#else -#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU -#endif #endif #include @@ -100,7 +97,7 @@ const char* ImGui_ImplWGPU_GetAdapterTypeName(WGPUAdapterType type); #if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) const char* ImGui_ImplWGPU_GetDeviceLostReasonName(WGPUDeviceLostReason type); const char* ImGui_ImplWGPU_GetErrorTypeName(WGPUErrorType type); -#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__) +#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) const char* ImGui_ImplWGPU_GetLogLevelName(WGPULogLevel level); #endif diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index de3c6fbd..de92040a 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -21,6 +21,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-01-28: Inputs: Minor optimization not submitting gamepad input if packet number has not changed (reworked from 2025-09-23 attempt). (#9202, #8556) // 2025-12-03: Inputs: handle WM_IME_CHAR/WM_IME_COMPOSITION messages to support Unicode inputs on MBCS (non-Unicode) Windows. (#9099, #3653, #5961) // 2025-10-19: Inputs: Revert previous change to allow for io.ClearInputKeys() on focus-out not losing gamepad state. // 2025-09-23: Inputs: Minor optimization not submitting gamepad input if packet number has not changed. @@ -127,6 +128,7 @@ struct ImGui_ImplWin32_Data HMODULE XInputDLL; PFN_XInputGetCapabilities XInputGetCapabilities; PFN_XInputGetState XInputGetState; + DWORD XInputPacketNumber; #endif ImGui_ImplWin32_Data() { memset((void*)this, 0, sizeof(*this)); } @@ -358,6 +360,9 @@ static void ImGui_ImplWin32_UpdateGamepads(ImGuiIO& io) if (!bd->HasGamepad || bd->XInputGetState == nullptr || bd->XInputGetState(0, &xinput_state) != ERROR_SUCCESS) return; io.BackendFlags |= ImGuiBackendFlags_HasGamepad; + if (bd->XInputPacketNumber != 0 && bd->XInputPacketNumber == xinput_state.dwPacketNumber) + return; + bd->XInputPacketNumber = xinput_state.dwPacketNumber; #define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V) #define MAP_BUTTON(KEY_NO, BUTTON_ENUM) { io.AddKeyEvent(KEY_NO, (gamepad.wButtons & BUTTON_ENUM) != 0); } @@ -771,6 +776,9 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA case WM_SETFOCUS: case WM_KILLFOCUS: io.AddFocusEvent(msg == WM_SETFOCUS); +#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD + bd->XInputPacketNumber = 0; // FIXME: Technically, calling io.ClearInputKeys() directly would require this as well. +#endif return 0; case WM_INPUTLANGCHANGE: ImGui_ImplWin32_UpdateKeyboardCodePage(io); @@ -830,7 +838,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, -// neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. +// neither of which we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. //--------------------------------------------------------------------------------------------------------- // This is the scheme successfully used by GLFW (from which we borrowed some of the code) and other apps aiming to be highly portable. // ImGui_ImplWin32_EnableDpiAwareness() is just a helper called by main.cpp, we don't call it automatically. diff --git a/backends/imgui_impl_win32.h b/backends/imgui_impl_win32.h index 5ae399e0..d2a96005 100644 --- a/backends/imgui_impl_win32.h +++ b/backends/imgui_impl_win32.h @@ -26,7 +26,7 @@ IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); -// Win32 message handler your application need to call. +// Win32 message handler your application needs to call. // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. @@ -40,7 +40,7 @@ extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, -// neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. +// neither of which we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor diff --git a/docs/BACKENDS.md b/docs/BACKENDS.md index 62acb1e2..7839764c 100644 --- a/docs/BACKENDS.md +++ b/docs/BACKENDS.md @@ -337,7 +337,7 @@ void MyImGuiBackend_UpdateTexture(ImTextureData* tex) { // Create texture based on tex->Width, tex->Height. // - Most backends only support tex->Format == ImTextureFormat_RGBA32. - // - Backends for particularly memory constrainted platforms may support tex->Format == ImTextureFormat_Alpha8. + // - Backends for particularly memory constrained platforms may support tex->Format == ImTextureFormat_Alpha8. // Upload all texture pixels // - Read from our CPU-side copy of the texture and copy to your graphics API. diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 61798aa8..ff03643c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -36,67 +36,128 @@ HOW TO UPDATE? - Please report any issue! ----------------------------------------------------------------------- - VERSION 1.92.6 WIP (In Progress) + VERSION 1.92.7 WIP (In Progress) ----------------------------------------------------------------------- Breaking Changes: -- Commented out legacy names obsoleted in 1.90 (Sept 2023): - - BeginChildFrame() --> BeginChild() with ImGuiChildFlags_FrameStyle flag. - - EndChildFrame() --> EndChild(). - - ShowStackToolWindow() --> ShowIDStackToolWindow(). - - IM_OFFSETOF() --> offsetof(). - - IM_FLOOR() --> IM_TRUNC() [internal, for positive values only] -- Hashing: handling of "###" operator to reset to seed within a string identifier - doesn't include the "###" characters in the output hash anymore: - Before: GetID("Hello###World") == GetID("###World") != GetID("World"); - Now: GetID("Hello###World") == GetID("###World") == GetID("World"); - - This has the property of facilitating concatenating and manipulating - identifiers using "###", and will allow fixing other dangling issues. - - This will invalidate hashes (stored in .ini data) for Tables and Windows - that are using the "###" operators. (#713, #1698) -- Renamed helper macro IM_ARRAYSIZE() -> IM_COUNTOF(). Kept redirection/legacy name. + - Separator(): fixed a legacy quirk where Separator() was submitting a zero-height + item for layout purpose, even though it draws a 1-pixel separator. + The fix could affect code e.g. computing height from multiple widgets in order to + allocate vertical space for a footer or multi-line status bar. (#2657, #9263) + The "Console" example had such a bug: + float footer_height = style.ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); + BeginChild("ScrollingRegion", { 0, -footer_height }); + Should be: + float footer_height = style.ItemSpacing.y + style.SeparatorSize + ImGui::GetFrameHeightWithSpacing(); + BeginChild("ScrollingRegion", { 0, -footer_height }); + When such idiom was used and assuming zero-height Separator, it is likely that + in 1.92.7 the resulting window will have unexpected 1 pixel scrolling range. + - Combo(), ListBox(): commented out legacy signatures which were obsoleted in 1.90 + (Nov 2023), when the getter callback type was changed from: + getter type: bool (*getter)(void* user_data, int idx, const char** out_text) + To: + getter type: const char* (*getter)(void* user_data, int idx) + +Other Changes: + +- TreeNode: + - Moved TreeNodeGetOpen() helper to public API. I was hesitant to make this public + because I intend to provide a more generic and feature-full version, but in the meanwhile + this will do. (#3823, #9251, #7553, #6754, #5423, #2958, #2079, #1947, #1131, #722) + - In 'Demo->Property Editor' demonstrate a way to perform tree clipping by fast-forwarding + through non-visible chunks. (#3823, #9251, #6990, #6042) + Using SetNextItemStorageID() + TreeNodeGetOpen() makes this notably easier than + it was prior to 1.91. +- InputText: + - Shift+Enter in multi-line editor always adds a new line, regardless of + ImGuiInputTextFlags_CtrlEnterForNewLine being set or not. (#9239) +- Style: + - Border sizes are now scaled (and rounded) by ScaleAllSizes(). + - When using large values with ScallAllSizes(), the following items thickness + are scaled to integer amounts: + - InputText Caret/cursor thickness. (#7031) + - CloseButton() thickness. + - TextLink() underline thickness. + - ColorButton() border thickness. + - Separator() thickness, via scaling newly added style.SeparatorSize. (#2657, #9263) +- Clipper: + - Clear `DisplayStart`/`DisplayEnd` fields when `Step()` returns false. + - Added `UserIndex` helper storage. This is solely a convenience for cases where + you may want to carry an index around. +- Scrollbar: + - Implemented a custom tweak to extend hit-testing bounding box when window is sitting + at the edge of a viewport (e.g. fullscreen or docked window), so that e.g. mouse the + mouse at the extreme of the screen will reach the scrollbar. (#9276) +- Demo: fixed IMGUI_DEMO_MARKER locations for examples applets. (#9261, #3689) [@pthom] +- Backends: + - SDLGPU3: removed unnecessary call to SDL_WaitForGPUIdle when releasing + vertex/index buffers. (#9262) [@jaenis] + - WebGPU: fixed version check for Emscripten 5.0.0+. + - WebGPU: removed support for Emscripten <4.0.10. (#9281) [@ypujante] +- Examples: + - Emscripten: added `tabindex=-1` to canvas in our shell_minimal.htm. Without it, + the canvas was not focusable in the DOM, which in turn make some backends + (e.g. pongasoft/emscripten-glfw) not receive focus loss events. (#9259) [@pthom] + - Emscripten: fixed minor rendering issues with our HTML shell. (#9281) [@ypujante] + - hidden small blue outline when canvas is focused on Chrome. + - hidden scrollbar in Firefox. + - Vulkan: added ImGui_ImplVulkan_PipelineInfo::ExtraDynamicStates[] to allow specifying + extra dynamic states to add when creating the VkPipeline. (#9211) [@DziubanMaciej] + - WebGPU: fixed undefined behaviors in example code for requesting adapter + and device. (#9246, #9256) [@r-lyeh] + - GLFW/SDL2/SDL3+WebGPU: removed suport for Emscripten <4.0.10. (#9281) [@ypujante] + + +----------------------------------------------------------------------- + VERSION 1.92.6 (2026-02-17) +----------------------------------------------------------------------- + +Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.92.6 + +Breaking Changes: + - Fonts: - - AddFontDefault() now automatically selects an embedded font between: - - AddFontDefaultVector(): new scalable font. Recommended at any higher size. - - AddFontDefaultBitmap(): classic pixel-clean font. Recommended at Size 13px with no scaling. + - `AddFontDefault()` now automatically selects an embedded font between: + - `AddFontDefaultBitmap()`: classic pixel-clean font. Recommended at Size 13px with no scaling. + - `AddFontDefaultVector()`: new scalable font. Recommended at any higher size. - The default selection is based on (style.FontSizeBase * FontScaleMain * FontScaleDpi) - reaching a small threshold. Prefer calling either based on your own logic. - And you can call AddFontDefaultBitmap() to ensure legacy behavior. - - Fixed handling of `ImFontConfig::FontDataOwnedByAtlas = false` which - did erroneously make a copy of the font data, essentially defeating the purpose + reaching a small threshold, but old codebases may not set any of them properly. + As as a result, it is likely that old codebase may still default to AddFontDefaultBitmap(). + - Prefer explicitly calling either of them based on your own logic! + You can call `AddFontDefaultBitmap()` to ensure legacy behavior. + - Fixed handling of `ImFontConfig::FontDataOwnedByAtlas = false` which did + erroneously make a copy of the font data, essentially defeating the purpose of this flag and wasting memory (undetected since July 2015 and now spotted by @TellowKrinkle, this is perhaps the oldest bug in Dear ImGui history, albeit for a rarely used feature!) (#9086, #8465) HOWEVER, fixing this bug is likely to surface bugs in user/app code: - - Prior to 1.92, font data only needs to be available during the atlas->AddFontXXX() call. - Since 1.92, font data needs to available until atlas->RemoveFont(), or more typically + - Prior to 1.92, font data only needs to be available during the `atlas->AddFontXXX()` call. + Since 1.92, font data needs to available until `atlas->RemoveFont()`, or more typically until a shutdown of the owning context or font atlas. - The fact that handling of `FontDataOwnedByAtlas = false` was broken bypassed the issue altogether. - - Fixed a crash when trying to use AddFont() with MergeMode=true on a font that - has already been rendered. (#9162) [@ocornut, @cyfewlp] - - Removed ImFontConfig::PixelSnapV added in 1.92 which turns out is unnecessary - (and misdocumented). Post-rescale GlyphOffset is always rounded. - - Popups: changed compile-time 'ImGuiPopupFlags popup_flags = 1' default value to be '= 0' for - BeginPopupContextItem(), BeginPopupContextWindow(), BeginPopupContextVoid(), OpenPopupOnItemClick(). + - Removed `ImFontConfig::PixelSnapV` added in 1.92 which turns out is unnecessary + (and was mis-documented). Post-rescale `GlyphOffset` is always rounded. + - Popups: changed compile-time `ImGuiPopupFlags popup_flags = 1` default value to be `= 0` for + `BeginPopupContextItem()`, `BeginPopupContextWindow()`, `BeginPopupContextVoid()`, `OpenPopupOnItemClick()`. The default value has same meaning before and after. (#9157, #9146) - - Before this version, those functions had a 'ImGuiPopupFlags popup_flags = 1' default + - Before this version, those functions had a `ImGuiPopupFlags popup_flags = 1` default value in their function signature. This was introduced by a change on 2020/06/23 (1.77) - while changing the signature from 'int mouse_button' to 'ImGuiPopupFlags popup_flags' + while changing the signature from `int mouse_button` to `ImGuiPopupFlags popup_flags` and trying to preserve then-legacy behavior. - We have now changed this behavior to: cleanup a very old API quirk, facilitate use by bindings, and to remove the last and error-prone non-zero default value. Also because we deemed it extremely rare to use those helper functions with the Left mouse button! - As using the LMB would generally be triggered via another widget, e.g. a Button() + - a OpenPopup()/BeginPopup() call. - - Before: The default = 1 means ImGuiPopupFlags_MouseButtonRight. - Explicitly passing a literal 0 means ImGuiPopupFlags_MouseButtonLeft. - - After: The default = 0 means ImGuiPopupFlags_MouseButtonRight. - Explicitly passing a literal 1 also means ImGuiPopupFlags_MouseButtonRight + As using the LMB would generally be triggered via another widget, + e.g. a Button() + a OpenPopup()/BeginPopup() call. + - Before: The default = 1 means `ImGuiPopupFlags_MouseButtonRight`. + Explicitly passing a literal 0 means `ImGuiPopupFlags_MouseButtonLeft`. + - After: The default = 0 means `ImGuiPopupFlags_MouseButtonRight`. + Explicitly passing a literal 1 also means `ImGuiPopupFlags_MouseButtonRight`. (if legacy behavior are enabled) or will assert (if legacy behavior are disabled). - TL;DR: if you don't want to use right mouse button for popups, always specify it - explicitly using a named ImGuiPopupFlags_MouseButtonXXXX value. + explicitly using a named `ImGuiPopupFlags_MouseButtonXXXX` value. Recap: - BeginPopupContextItem("foo"); // Behavior unchanged (use Right button) - BeginPopupContextItem("foo", ImGuiPopupFlags_MouseButtonLeft); // Behavior unchanged (use Left button) @@ -105,39 +166,70 @@ Breaking Changes: - BeginPopupContextItem("foo", 1); // Behavior unchanged (as a courtesy we legacy interpret 1 as ImGuiPopupFlags_MouseButtonRight, will assert if disabling legacy behaviors. - BeginPopupContextItem("foo", 0); // !! Behavior changed !! Was Left button. Now will defaults to Right button! --> Use ImGuiPopupFlags_MouseButtonLeft. - BeginPopupContextItem("foo", ImGuiPopupFlags_NoReopen); // !! Behavior changed !! Was Left button + flags. Now will defaults to Right button! --> Use ImGuiPopupFlags_MouseButtonLeft | xxx. +- Commented out legacy names obsoleted in 1.90 (Sept 2023): + - `BeginChildFrame()` --> `BeginChild()` with `ImGuiChildFlags_FrameStyle` flag. + - `EndChildFrame()` --> `EndChild()`. + - `ShowStackToolWindow()` --> `ShowIDStackToolWindow()`. + - `IM_OFFSETOF()` --> `offsetof()`. + - `IM_FLOOR()` --> `IM_TRUNC()` [internal, for positive values only] +- Hashing: handling of "###" operator to reset to seed within a string identifier + doesn't include the "###" characters in the output hash anymore: + Before: `GetID("Hello###World") == GetID("###World") != GetID("World")` + After: `GetID("Hello###World") == GetID("###World") == GetID("World")` + - This has the property of facilitating concatenating and manipulating + identifiers using "###", and will allow fixing other dangling issues. + - This will invalidate hashes (stored in .ini data) for Tables and Windows + that are using the "###" operators. (#713, #1698) +- Renamed helper macro `IM_ARRAYSIZE()` -> `IM_COUNTOF()`. Kept redirection/legacy name. - Backends: - - Vulkan: optional ImGui_ImplVulkanH_DestroyWindow() helper used by our example - code does not call vkDestroySurfaceKHR(): because surface is created by caller - of ImGui_ImplVulkanH_CreateOrResizeWindow(), it is more consistent. (#9163) + - Vulkan: optional `ImGui_ImplVulkanH_DestroyWindow()` helper used by our example + code does not call `vkDestroySurfaceKHR()`: because surface is created by caller + of `ImGui_ImplVulkanH_CreateOrResizeWindow()`, it is more consistent. (#9163) Other Changes: - Fonts: - - Added AddFontDefaultVector(): a new embedded scalable font! - Based on ProggyVector by Tristan Grimmer, the same author as our good-old ProggyClean. - The font data was carefully subsetted, trimmed and compressed so the embedded - data is ~18 KB. Embedding a scalable default font ensures that Dear ImGui can - be easily and readily used in all contexts, even without file system access. - As always you can opt-out of the embedded font data if desired. A sizing tweak - was also applied to ensure the new font is a closer match to the classic font. - - AddFontDefault() now automatically selects an embedded font between + - Added `AddFontDefaultVector()`: a new embedded monospace scalable font: ProggyForever! + From https://github.com/ocornut/proggyforever: + "ProggyForever is an MIT-licensed partial reimplementation of the ProggyVector + font (originally by Tristan Grimmer), which itself is a vector-based + reinterpretation of the ProggyClean bitmap font that happily served as + Dear ImGui default font for over 10 years." [...] + "I commissioned Thiebault Courot to recreate this, applied various minor tweaks + and fixes, and reworked his editing pipeline toward shipping FontForge source + files so we can allow and track future changes." + - TL;DR; there was no strictly MIT-licensed matching font. We made it! + - The font data was carefully subsetted, trimmed and compressed so the embedded + data is ~14 KB. Embedding a scalable default font ensures that Dear ImGui can + be easily and readily used in all contexts, even without file system access. + - Expect minor fixes/improvements in following releases. + - As always you can opt-out of the embedded font data if desired. + - `AddFontDefault()` now automatically selects an embedded font between the classic pixel-looking one and the new scalable one. - - Fixed an issue related to EllipsisChar handling, while changing + Prefer calling `AddFontDefaultVector()` or `AddFontDefaultBitmap()` explicitly. + - Fixed a crash when trying to use `AddFont()` with `MergeMode==true` on a font that + has already been rendered. (#9162) [@ocornut, @cyfewlp] + - Fixed an issue where using `PushFont()` from the implicit/fallback "Debug" window + when its recorded state is collapsed would incorrectly early out. This would break + e.g. using direct draw-list calls such as `GetForegroundDrawList()` with current font. + (#9210, #8865) + - Fixed an issue related to `EllipsisChar` handling, while changing font loader or font loader flags dynamically in Style->Fonts menus. - - imgui_freetype: fixed overwriting ImFontConfig::PixelSnapH when hinting + - imgui_freetype: fixed overwriting `ImFontConfig::PixelSnapH` when hinting is enabled, creating side-effects when later disabling hinting or dynamically switching to stb_truetype rasterizer. - - Post rescale GlyphOffset is always rounded. + - Adding new fonts after removing all fonts mid-frame properly updates current state. - Textures: - - Fixed a building issue when ImTextureID is defined as a struct. + - Fixed a building issue when `ImTextureID` is defined as a struct. - Fixed displaying texture # in Metrics/Debugger window. - Menus: - - Fixed MenuItem() label position and BeginMenu() arrow/icon/popup positions, + - Fixed `MenuItem()` label position and `BeginMenu()` arrow/icon/popup positions, when used inside a line with a baseline offset. + - Made navigation into menu-bar auto wrap on X axis. (#9178) - TreeNode: - Fixed highlight position when used inside a line with a large text baseline offset. - (never quite worked in this situation; but then most of the time the text - baseline offset ends up being zero or FramePadding.y for a given line). + (it never quite worked in this situation; but then most of the time the text + baseline offset ends up being zero or `FramePadding.y` for a given line). - Tables: - Fixed an issue where a very thin scrolling table would advance parent layout slightly differently depending on its visibility (caused by a mismatch @@ -148,66 +240,114 @@ Other Changes: data has missing or duplicate values. (#9108, #4046) - ColorEdit: - Added R/G/B/A color markers next to each component (enabled by default). - - Added ImGuiColorEditFlags_NoColorMarkers to disable them. - - Added style.ColorMarkerSize to configure width of color component markers. + - Added `ImGuiColorEditFlags_NoColorMarkers` to disable them. + - Added `style.ColorMarkerSize` to configure width of color component markers. - Sliders, Drags: - - Added ImGuiSliderFlags_ColorMarkers to opt-in adding R/G/B/A color markers + - Added `ImGuiSliderFlags_ColorMarkers` to opt-in adding R/G/B/A color markers next to each components, in multi-components functions. - Added a way to select a specific marker color. +- InputText: + - InputTextMultiline(): fixed a minor bug where Shift+Wheel would allow a small + horizontal scroll offset when there should be none. (#9249) + - ImGuiInputTextCallbackData: `SelectAll()` also sets `CursorPos` to `SelectionEnd`. + - ImGuiInputTextCallbackData: Added `SetSelection()` helper. + - ImGuiInputTextCallbackData: Added `ID` and `EventActivated` members. (#9174) - Text, InputText: - Reworked word-wrapping logic: - - Try to not wrap in the middle of contiguous punctuations. (#8139, #8439, #9094) + - Try to not wrap in the middle of contiguous punctuation. (#8139, #8439, #9094) - Try to not wrap between a punctuation and a digit. (#8503) - - Inside InputTextMultiline() with _WordWrap: prefer keeping blanks at the - end of a line rather than at the beginning of next line. (#8990, #3237) - - Fixed low-level word-wrapping function reading from *text_end when passed + - Inside `InputTextMultiline()` with WordWrap enabled: prefer keeping blanks at + the end of a line rather than at the beginning of next line. (#8990, #3237) + - Fixed low-level word-wrapping function reading from `*text_end` when passed a string range. (#9107) [@achabense] + - Changed `RenderTextEllipsis()` logic to not trim trailing blanks before + the ellipsis, making ellipsis position more consistent and not arbitrary + hiding the possibility of multiple blanks. (#9229) - Nav: - Fixed remote/shortcut InputText() not teleporting mouse cursor when nav cursor is visible and `io.ConfigNavMoveSetMousePos` is enabled. -- Scrollbar: fixed a codepath leading to a divide-by-zero (which would not be + - Fixed a looping/wrapping issue when used in menu layer. (#9178) + - Fixed speed scale for resizing/moving with keyboard/gamepad. We incorrectly + used `io.DisplayFramebufferScale` as a scaling factor (very old code), + effectively making those actions faster on macOS/iOS retina screens. + (changed this to use a style scale factor that's not fully formalized yet) + - Fixed an UBSan warning when using in a `ImGuiListClipper` region . (#9160) +- Scrollbar: fixed a code-path leading to a divide-by-zero (which would not be noticeable by user but detected by sanitizers). (#9089) [@judicaelclair] - InvisibleButton: allow calling with size (0,0) to fit to available content size. (#9166, #7623) -- Added GetItemFlags() in public API for consistency and to expose generic +- Tooltips, Disabled: fixed `EndDisabledOverrideReenable()` assertion when + nesting a tooltip in a disabled block. (#9180, #7640) [@RegimantasSimkus] +- Added `GetItemFlags()` in public API for consistency and to expose generic flags of last submitted item. (#9127) +- Misc: fixed build on ARM64/ARM64EC targets trying to use SSE/immintrin.h. + (#9209, #5943, #4091) [@navvyswethgraphics] +- Log/Capture: + - Fixed erroneously injecting extra carriage returns in output text buffer + when `ItemSpacing.y` > `FramePadding.y + 1` while emitting items. - Images: - - Added style.ImageRounding, ImGuiStyleVar_ImageRounding to configure - rounding of Image() widgets. (#2942, #845) - - ImageButton() doesn't use a clamped style.FrameRounding value but instead - adjust inner image rounding when FramePadding > FrameRounding. (#2942, #845) + - Added `style.ImageRounding`, `ImGuiStyleVar_ImageRounding `to configure + rounding of `Image()` widgets. (#2942, #845) + - `ImageButton()` doesn't use a clamped `style.FrameRounding` value but instead + adjust inner image rounding when `FramePadding > `FrameRounding`. (#2942, #845) - Shortcuts: - - IsItemHovered() without ImGuiHoveredFlags_AllowWhenBlockedByActiveItem + - IsItemHovered() without `ImGuiHoveredFlags_AllowWhenBlockedByActiveItem` doesn't filter out the signal when activated item is a shortcut remote activation; - (which mimicks what's done internally in the ItemHoverable() function). (#9138) + (which mimics what's done internally in the `ItemHoverable()` function). (#9138) - Fixed tooltip placement being affected for a frame when located over an item - activated by SetNextItemShortcut(). (#9138) + activated by `SetNextItemShortcut()`. (#9138) - Error Handling: - - Improve error handling and recovery for EndMenu()/EndCombo(). (#1651, #9165, #8499) + - Improved error handling and recovery for `EndMenu()`/`EndCombo()`. (#1651, #9165, #8499) + - Improved error handling and recovery for `TableSetupColumn()`. - Debug Tools: - Debug Log: fixed incorrectly printing characters in IO log when submitting - non-ASCII values to io.AddInputCharacter(). (#9099) - - Debug Log: can output to debugger on Windows. (#5855) + non-ASCII values to `io.AddInputCharacter()`. (#9099) + - Debug Log: can output to debugger on Windows via Win32 `OutputDebugString()` (#5855) +- Demo: + - Slightly improve `Selectable()` demos. (#9193) - Backends: - - GLFW: Avoid repeated glfwSetCursor()/glfwSetInputMode() calls when unnecessary. + - DirectX10: added `SamplerNearest` in `ImGui_ImplDX10_RenderState`. + (+renamed `SamplerDefault` to `SamplerLinear`, which was tagged as beta API) + - DirectX11: added `SamplerNearest` in ImGui_ImplDX11_RenderState. + (+renamed `SamplerDefault` to `SamplerLinear`, which was tagged as beta API) + - GLFW: Avoid repeated `glfwSetCursor()` / `glfwSetInputMode()` unnecessary calls. Lowers overhead for very high framerates (e.g. 10k+ FPS). [@maxliani] - - GLFW: Added IMGUI_IMPL_GLFW_DISABLE_X11 / IMGUI_IMPL_GLFW_DISABLE_WAYLAND to + - GLFW: Added `IMGUI_IMPL_GLFW_DISABLE_X11` / `IMGUI_IMPL_GLFW_DISABLE_WAYLAND` to forcefully disable either. (#9109, #9116) + Try to set them automatically if headers are not accessible. (#9225) - OpenGL3: Fixed embedded loader multiple init/shutdown cycles broken on some platforms. (#8792, #9112) - - SDL2, SDL3: changed GetClipboardText() handler to return NULL on error aka + - SDL2, SDL3: changed `GetClipboardText()` handler to return NULL on error aka clipboard contents is not text. Consistent with other backends. (#9168) + - SDL2, SDL3: systems other than X11 are back to starting mouse capture on mouse down + (reverts 1.91.9 change). Only X11 requires waiting for a drag by default (not ideal, + but a better default for X11 users). Waiting for a drag to start mouse capture leads to + input drops when dragging after clicking on the edge of a window. + (#3650, #6410, #9235, #3956, #3835) + - SDL2, SDL3: added `ImGui_ImplSDL2_SetMouseCaptureMode()`/`ImGui_ImplSDL3_SetMouseCaptureMode()` + function for X11 users to disable mouse capturing/grabbing. (#3650, #6410, #9235, #3956, #3835) + - When attached to a debugger may want to call: + - `ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode_Disabled);` + - But you can also configure your system or debugger to automatically release + mouse grab when crashing/breaking in debugger, e.g. + - console: `setxkbmap -option grab:break_actions && xdotool key XF86Ungrab` + - or use a GDB script to call `SDL_CaptureMouse(false)`. See #3650. + - On platforms other than X11 this is unnecessary. + - SDL_GPU3: added `SamplerNearest` in `ImGui_ImplSDLGPU3_RenderState`. - SDL_GPU3: macOS version can use MSL shaders in order to support macOS 10.14+ (vs Metallib shaders requiring macOS 14+). Requires application calling - SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL. (#9076) [@Niminem] + `SDL_CreateGPUDevice()` with `SDL_GPU_SHADERFORMAT_MSL`. (#9076) [@Niminem] - Vulkan: helper for creating a swapchain (used by examples and multi-viewports) selects `VkSwapchainCreateInfoKHR`'s `compositeAlpha` value based on `cap.supportedCompositeAlpha`, which seems to be required on some Android devices. (#8784) [@FelixStach] - - Win32: handle WM_IME_CHAR/WM_IME_COMPOSITION to support Unicode inputs on + - WebGPU: fixes for Emscripten 5.0.0 (note: current examples do not build with 5.0.1). + - Win32: handle `WM_IME_CHAR`/`WM_IME_COMPOSITION` to support Unicode inputs on MBCS (non-Unicode) Windows. (#9099, #3653, #5961) [@ulhc, @ocornut, @Othereum] + - Win32: minor optimization not submitting gamepad input if packet number has not + changed (reworked previous 1.92.4). (#9202, #8556) [@AhmedSamyMousa, @MidTerm-CN] - Examples: - - Win32+DirectX12: ignore seemingly incorrect D3D12_MESSAGE_ID_FENCE_ZERO_WAIT + - Win32+DirectX12: ignore seemingly incorrect `D3D12_MESSAGE_ID_FENCE_ZERO_WAIT` warning on startups on some setups. (#9084, #9093) [@RT2Code, @LeoGautheron] @@ -317,7 +457,7 @@ Other Changes: debug/metrics window is not in the same viewport as the table. - Backends: - NULL: added imgui_impl_null platform/renderer backend. - This is designed if you need to run e.g. context with no input or no ouput. + This is designed if you need to run e.g. context with no input or no output. - GLFW: fixed building on Linux platforms where Wayland headers are not available. (#9024, #8969, #8921, #8920) [@jagot] - GLFW: lower minimum requirement from GLFW 3.1 to GLFW 3.0. Though @@ -799,7 +939,7 @@ Breaking changes: which font input is providing which glyph. - Fonts: **IMPORTANT** on Thread Safety: - A few functions such as font->CalcTextSizeA() were by sheer luck (== accidentally) - thread-safe even thou we had never provided that guarantee before. They are + thread-safe even though we had never provided that guarantee before. They are definitively not thread-safe anymore as new glyphs may be loaded. - Textures: diff --git a/docs/FAQ.md b/docs/FAQ.md index 282c65c3..05dd777b 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -55,6 +55,7 @@ or view this file with any Markdown viewer. - Handy [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) guide to integrate Dear ImGui in an existing application. - 20+ standalone example applications using e.g. OpenGL/DirectX are provided in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder to explain how to integrate Dear ImGui with your own engine/application. You can run those applications and explore them. - See demo code in [imgui_demo.cpp](https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp) and particularly the `ImGui::ShowDemoWindow()` function. The demo covers most features of Dear ImGui, so you can read the code and see its output. +- See pthom's online [imgui_explorer](https://pthom.github.io/imgui_explorer) which is a web version of the demo with a source code browser. - See documentation: [Backends](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md), [Examples](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md), [Fonts](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md). - See documentation and comments at the top of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) + general API comments in [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h). - The [Glossary](https://github.com/ocornut/imgui/wiki/Glossary) page may be useful. @@ -678,8 +679,8 @@ ImGui::PushFont(new_font, 42.0f); In `docking` branch or with multi-viewports: ```cpp -io.ConfigDpiScaleFonts = true; // Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now. -io.ConfigDpiScaleViewports = true; // Scale Dear ImGui and Platform Windows when Monitor DPI changes. +io.ConfigDpiScaleFonts = true; // (Docking branch only) Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now. +io.ConfigDpiScaleViewports = true; // (Docking branch only) Scale Dear ImGui and Platform Windows when Monitor DPI changes. ``` **Scaling style** (paddings, spacings, thicknesses) diff --git a/docs/FONTS.md b/docs/FONTS.md index a3eb57d9..1e51cde4 100644 --- a/docs/FONTS.md +++ b/docs/FONTS.md @@ -5,13 +5,16 @@ _(You may browse this at https://github.com/ocornut/imgui/blob/master/docs/FONTS The code in Dear ImGui embeds a copy of [ProggyClean.ttf](https://github.com/bluescan/proggyfonts) by Tristan Grimmer, a 13 pixels high, pixel-perfect font used by default. ProggyClean does not scale very nicely. -The code in Dear ImGui embeds a partial copy of [ProggyVector.ttf](https://github.com/bluescan/proggyfonts) by Tristan Grimmer and Source Foundry Authors, -a font mimicking ProggyClean which does scale nicely. +The code in Dear ImGui embeds a partial copy of [ProggyForever.ttf](https://github.com/ocornut/proggyforever) by Disco Hello & Tristan Grimmer, +a new font mimicking ProggyClean which does scale nicely. We embed fonts in the code so you can use Dear ImGui without any file system access. -If you use either of those fonts in your shipping product you should include their license as part of your software (see below for links). If you don't use them you can set `IMGUI_DISABLE_DEFAULT_FONT` in your [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) file to ship binaries without the fonts and save about ~26 KB. +Calling io.Fonts->AddFontDefaultVector() loads ProggyForever. +Calling io.Fonts->AddFontDefaultBitmap() loads ProggyClean. +Calling io.Fonts->AddFontDefault() selects one based on the expected default font size (when `style.FontSizeBase * style.FontScaleMain * style.FontSizeDpi >= 15` we use ProggyForever). + You may also load external .TTF/.OTF files, see instructions on this page. In the [misc/fonts/](https://github.com/ocornut/imgui/tree/master/misc/fonts) folder you can find a few suggested fonts, provided as a convenience. @@ -116,14 +119,14 @@ style.FontSizeBase = 20.0f; **Load default font:** ```cpp ImGuiIO& io = ImGui::GetIO(); -io.Fonts->AddFontDefault(); // Load embedded font (auto-selected). -``` -```cpp io.Fonts->AddFontDefaultVector(); // Load embedded scalable font. ``` ```cpp io.Fonts->AddFontDefaultBitmap(); // Load embedded bitmap font (legacy). ``` +```cpp +io.Fonts->AddFontDefault(); // Load embedded font (legacy: auto-selected between the two above). +``` **Load .TTF/.OTF file with:** @@ -167,7 +170,7 @@ ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config); 🆕 **Since 1.92, with an up to date backend: specifying glyph ranges is unnecessary.** ```cpp // Load a first font -ImFont* font = io.Fonts->AddFontDefault(); +ImFont* font = io.Fonts->AddFontDefaultVector(); ImFontConfig config; config.MergeMode = true; io.Fonts->AddFontFromFileTTF("DroidSans.ttf", 0.0f, &config); // Merge into first font to add e.g. Asian characters @@ -291,7 +294,7 @@ Example Setup: // Merge icons into default tool font #include "IconsFontAwesome.h" ImGuiIO& io = ImGui::GetIO(); -io.Fonts->AddFontDefault(); +io.Fonts->AddFontDefaultVector(); ImFontConfig config; config.MergeMode = true; config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced @@ -448,7 +451,7 @@ As an alternative to rendering colorful glyphs using imgui_freetype with `ImGuiF #### Pseudo-code: ```cpp // Add font, then register two custom 13x13 rectangles mapped to glyph 'a' and 'b' of this font -ImFont* font = io.Fonts->AddFontDefault(); +ImFont* font = io.Fonts->AddFontDefaultVector(); int rect_ids[2]; rect_ids[0] = io.Fonts->AddCustomRectFontGlyph(font, 'a', 13, 13, 13+1); rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, 'b', 13, 13, 13+1); @@ -561,7 +564,20 @@ You can use the `UTF-8 Encoding viewer` in `Metrics/Debugger` to verify the cont ## Credits/Licenses For Fonts Included In Repository -Some fonts files are available in the `misc/fonts/` folder: +Embedded in source code: + +**ProggyClean.ttf**, by Tristan Grimmer +
MIT License +
(recommended loading setting: Size = 13.0, GlyphOffset.y = +1, PixelSnapH = true) +
https://github.com/bluescan/proggyfonts + +**ProggyForever.ttf**, by Disco Hello, Tristan Grimmer +
MIT License +
https://github.com/ocornut/proggyforever + +Extra fonts files are available in the `misc/fonts/` folder. +Compared to 2014 when they were first introduced, we now have better font support and we embed ProggyForever. +I believe all the files here are unnecessary nowadays. You can find font yourself. They might eventually be removed. **Roboto-Medium.ttf**, by Christian Robetson
Apache License 2.0 @@ -576,20 +592,11 @@ Some fonts files are available in the `misc/fonts/` folder:
Apache License 2.0
https://www.fontsquirrel.com/fonts/droid-sans -**ProggyClean.ttf**, by Tristan Grimmer -
MIT License -
(recommended loading setting: Size = 13.0, GlyphOffset.y = +1) -
https://github.com/bluescan/proggyfonts - **ProggyTiny.ttf**, by Tristan Grimmer
MIT License
(recommended loading setting: Size = 10.0, GlyphOffset.y = +1)
https://github.com/bluescan/proggyfonts -**ProggyVector.ttf**, by Tristan Grimmer, Source Foundry Authors -
MIT License + Bitstream Vera License -
https://github.com/bluescan/proggyfonts - **Karla-Regular.ttf**, by Jonathan Pinhorn
SIL OPEN FONT LICENSE Version 1.1 diff --git a/docs/README.md b/docs/README.md index c1b41362..a409b930 100644 --- a/docs/README.md +++ b/docs/README.md @@ -55,8 +55,8 @@ if (ImGui::Button("Save")) ImGui::InputText("string", buf, IM_COUNTOF(buf)); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ``` -![sample code output (dark, segoeui font, freetype)](https://user-images.githubusercontent.com/8225057/191050833-b7ecf528-bfae-4a9f-ac1b-f3d83437a2f4.png) -![sample code output (light, segoeui font, freetype)](https://user-images.githubusercontent.com/8225057/191050838-8742efd4-504d-4334-a9a2-e756d15bc2ab.png) +sample code output (dark) +sample code output (light) ```cpp // Create a window called "My First Tool", with a menu bar. @@ -90,7 +90,7 @@ for (int n = 0; n < 50; n++) ImGui::EndChild(); ImGui::End(); ``` -![my_first_tool_v188](https://user-images.githubusercontent.com/8225057/191055698-690a5651-458f-4856-b5a9-e8cc95c543e2.gif) +![my_first_tool_v192 6](https://github.com/user-attachments/assets/6c76658c-302f-403b-af26-d517e2bfb0d4) Dear ImGui allows you to **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweak variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game-making editor/framework, etc. @@ -110,11 +110,23 @@ Reading the changelogs is a good way to keep up to date with the things Dear ImG ### Demo Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing a variety of features and examples. The code is always available for reference in `imgui_demo.cpp`. -- [Web version of the demo](https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html) courtesy of [@pthom](https://github.com/pthom). -- [Screenshot of the demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png). +- [imgui_explorer](https://pthom.github.io/imgui_explorer): Web version of the demo w/ source code browser, courtesy of [@pthom](https://github.com/pthom). You should be able to build the examples from sources. If you don't, let us know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: -- [imgui-demo-binaries-20250625.zip](https://www.dearimgui.com/binaries/imgui-demo-binaries-20250625.zip) (Windows, 1.92.0, built 2025/06/25, master) or [older binaries](https://www.dearimgui.com/binaries). +- [imgui-demo-binaries-20260225.zip](https://www.dearimgui.com/binaries/imgui-demo-binaries-20260225.zip) (Windows, 1.92.6, built 2026/02/25, master) or [older binaries](https://www.dearimgui.com/binaries). + +### Gallery + +Examples projects using Dear ImGui: [Tracy](https://github.com/wolfpld/tracy) (profiler), [ImHex](https://github.com/WerWolv/ImHex) (hex editor/data analysis), [RemedyBG](https://remedybg.itch.io/remedybg) (debugger) and [hundreds of others](https://github.com/ocornut/imgui/wiki/Software-using-Dear-ImGui). + +For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues?q=label%3Agallery)! + +For a list of third-party widgets and extensions, check out the [Useful Extensions/Widgets](https://github.com/ocornut/imgui/wiki/Useful-Extensions) wiki page. + +| | | +|--|--| +| Custom engine [erhe](https://github.com/tksuoran/erhe) (docking branch)
[![erhe](https://user-images.githubusercontent.com/8225057/190203358-6988b846-0686-480e-8663-1311fbd18abd.jpg)](https://user-images.githubusercontent.com/994606/147875067-a848991e-2ad2-4fd3-bf71-4aeb8a547bcf.png) | Custom engine for [Wonder Boy: The Dragon's Trap](http://www.TheDragonsTrap.com) (2017)
[![the dragon's trap](https://user-images.githubusercontent.com/8225057/190203379-57fcb80e-4aec-4fec-959e-17ddd3cd71e5.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) | +| Custom engine (untitled)
[![editor white](https://user-images.githubusercontent.com/8225057/190203393-c5ac9f22-b900-4d1e-bfeb-6027c63e3d92.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) | Tracy Profiler ([github](https://github.com/wolfpld/tracy))
[![tracy profiler](https://user-images.githubusercontent.com/8225057/190203401-7b595f6e-607c-44d3-97ea-4c2673244dfb.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v176/tracy_profiler.png) | ### Getting Started & Integration @@ -138,24 +150,13 @@ Officially maintained backends (in repository): - Frameworks: AGS/Adventure Game Studio, Amethyst, Blender, bsf, Cinder, Cocos2d-x, Defold, Diligent Engine, Ebiten, Flexium, GML/Game Maker Studio, GLEQ, Godot, GTK3, Irrlicht Engine, JUCE, LÖVE+LUA, Mach Engine, Magnum, Marmalade, Monogame, NanoRT, nCine, Nim Game Lib, Nintendo 3DS/Switch/WiiU (homebrew), Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, Photoshop, px_render, Qt/QtDirect3D, raylib, SFML, Sokol, Unity, Unreal Engine 4/5, UWP, vtk, VulkanHpp, VulkanSceneGraph, Win32 GDI, WxWidgets. - Many bindings are auto-generated (by good old [cimgui](https://github.com/cimgui/cimgui) or our newer [dear_bindings](https://github.com/dearimgui/dear_bindings)), you can use their metadata output to generate bindings for other languages. +Useful extensions + [Useful Extensions/Widgets](https://github.com/ocornut/imgui/wiki/Useful-Extensions) wiki page: - Automation/testing, Text editors, node editors, timeline editors, plotting, software renderers, remote network access, memory editors, gizmos, etc. Notable and well supported extensions include [ImPlot](https://github.com/epezent/implot) and [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine). Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. -### Gallery - -Examples projects using Dear ImGui: [Tracy](https://github.com/wolfpld/tracy) (profiler), [ImHex](https://github.com/WerWolv/ImHex) (hex editor/data analysis), [RemedyBG](https://remedybg.itch.io/remedybg) (debugger) and [hundreds of others](https://github.com/ocornut/imgui/wiki/Software-using-Dear-ImGui). - -For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues?q=label%3Agallery)! - -For a list of third-party widgets and extensions, check out the [Useful Extensions/Widgets](https://github.com/ocornut/imgui/wiki/Useful-Extensions) wiki page. - -| | | -|--|--| -| Custom engine [erhe](https://github.com/tksuoran/erhe) (docking branch)
[![erhe](https://user-images.githubusercontent.com/8225057/190203358-6988b846-0686-480e-8663-1311fbd18abd.jpg)](https://user-images.githubusercontent.com/994606/147875067-a848991e-2ad2-4fd3-bf71-4aeb8a547bcf.png) | Custom engine for [Wonder Boy: The Dragon's Trap](http://www.TheDragonsTrap.com) (2017)
[![the dragon's trap](https://user-images.githubusercontent.com/8225057/190203379-57fcb80e-4aec-4fec-959e-17ddd3cd71e5.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) | -| Custom engine (untitled)
[![editor white](https://user-images.githubusercontent.com/8225057/190203393-c5ac9f22-b900-4d1e-bfeb-6027c63e3d92.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) | Tracy Profiler ([github](https://github.com/wolfpld/tracy))
[![tracy profiler](https://user-images.githubusercontent.com/8225057/190203401-7b595f6e-607c-44d3-97ea-4c2673244dfb.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v176/tracy_profiler.png) | - ### Support, Frequently Asked Questions (FAQ) See: [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) where common questions are answered. @@ -209,7 +210,7 @@ Dear ImGui is using software and services provided free of charge for open sourc Credits ------- -Developed by [Omar Cornut](https://www.miracleworld.net) and every direct or indirect [contributors](https://github.com/ocornut/imgui/graphs/contributors) to the GitHub. The early version of this library was developed with the support of [Media Molecule](https://www.mediamolecule.com) and first used internally on the game [Tearaway](https://tearaway.mediamolecule.com) (PS Vita). +Developed by [Omar Cornut](https://www.miracleworld.net) and every direct or indirect [contributors](https://github.com/ocornut/imgui/graphs/contributors) to the GitHub. The early version of this library was developed with the support of [Media Molecule](https://www.mediamolecule.com) and first used internally on the game [Tearaway](https://youtu.be/w0oxBviRGlU) (PS Vita). Recurring contributors include Rokas Kupstys [@rokups](https://github.com/rokups) (2020-2022): a good portion of work on automation system and regression tests now available in [Dear ImGui Test Engine](https://github.com/ocornut/imgui_test_engine). @@ -217,7 +218,8 @@ Maintenance/support contracts, sponsoring invoices and other B2B transactions ar Omar: "I first discovered the IMGUI paradigm at [Q-Games](https://www.q-games.com) where Atman Binstock had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating and improving it." -Embeds [ProggyClean.ttf, ProggyVector.ttf](https://www.proggyfonts.net) fonts by Tristan Grimmer (MIT license). +Embeds [ProggyClean](https://www.proggyfonts.net) font by Tristan Grimmer (MIT license). +
Embeds [ProggyForever](https://github.com/ocornut/proggyforever) fonts by Disco Hello, Tristan Grimmer (MIT license).
Embeds [stb_textedit.h, stb_truetype.h, stb_rect_pack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain). Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Special thanks to Alex Evans, Patrick Doane, Marco Koegler for kindly helping. Also thank you to everyone posting feedback, questions and patches on GitHub. diff --git a/examples/example_allegro5/main.cpp b/examples/example_allegro5/main.cpp index 54674a5d..ebb6d76b 100644 --- a/examples/example_allegro5/main.cpp +++ b/examples/example_allegro5/main.cpp @@ -49,7 +49,7 @@ int main(int, char**) ImGui_ImplAllegro5_Init(display); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_android_opengl3/main.cpp b/examples/example_android_opengl3/main.cpp index 0de952db..382006fa 100644 --- a/examples/example_android_opengl3/main.cpp +++ b/examples/example_android_opengl3/main.cpp @@ -151,12 +151,6 @@ void Init(struct android_app* app) ImGui_ImplAndroid_Init(g_App->window); ImGui_ImplOpenGL3_Init("#version 300 es"); - // Load Fonts - // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. - // - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). - // - Read 'docs/FONTS.md' for more instructions and details. If you like the default font but want it to scale better, consider using the 'ProggyVector' from the same author! - // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! - // Setup scaling float main_scale = 2.0f; ImGuiStyle& style = ImGui::GetStyle(); @@ -164,7 +158,7 @@ void Init(struct android_app* app) style.FontScaleDpi = main_scale; // Set initial font scale. // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_apple_metal/main.mm b/examples/example_apple_metal/main.mm index 11f54549..b8edbd2d 100644 --- a/examples/example_apple_metal/main.mm +++ b/examples/example_apple_metal/main.mm @@ -69,7 +69,7 @@ ImGui_ImplMetal_Init(_device); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_apple_opengl2/main.mm b/examples/example_apple_opengl2/main.mm index aa9b39ba..1cfa882c 100644 --- a/examples/example_apple_opengl2/main.mm +++ b/examples/example_apple_opengl2/main.mm @@ -57,7 +57,7 @@ ImGui_ImplOpenGL2_Init(); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm index 9627de70..0ded0a3b 100644 --- a/examples/example_glfw_metal/main.mm +++ b/examples/example_glfw_metal/main.mm @@ -52,7 +52,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) id device = MTLCreateSystemDefaultDevice(); id commandQueue = [device newCommandQueue]; @@ -62,7 +62,7 @@ int main(int, char**) ImGui_ImplMetal_Init(device); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 4fa8b079..48584eaf 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -61,14 +61,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL2_Init(); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index af21d909..20d39fcc 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -92,7 +92,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForOpenGL(window, true); @@ -102,7 +102,7 @@ int main(int, char**) ImGui_ImplOpenGL3_Init(glsl_version); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index ccce94fb..d70c7ce1 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -397,7 +397,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForVulkan(window, true); @@ -420,7 +420,7 @@ int main(int, char**) ImGui_ImplVulkan_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_glfw_wgpu/CMakeLists.txt b/examples/example_glfw_wgpu/CMakeLists.txt index 11248df2..f1951cb5 100644 --- a/examples/example_glfw_wgpu/CMakeLists.txt +++ b/examples/example_glfw_wgpu/CMakeLists.txt @@ -52,23 +52,15 @@ set(IMGUI_EXAMPLE_SOURCE_FILES ) if(EMSCRIPTEN) - if(NOT IMGUI_EMSCRIPTEN_WEBGPU_FLAG) # if IMGUI_EMSCRIPTEN_WEBGPU_FLAG not used, set by current EMSCRIPTEN version - if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.10") - set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Choose between --use-port=emdawnwebgpu (Dawn implementation of EMSCRIPTEN) and -sUSE_WEBGPU=1 (WGPU implementation of EMSCRIPTEN, deprecated in 4.0.10): default to --use-port=emdawnwebgpu for EMSCRIPTEN >= 4.0.10") - else() - set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "-sUSE_WEBGPU=1" CACHE STRING "Use -sUSE_WEBGPU=1 for EMSCRIPTEN WGPU implementation") - endif() - else() # if IMGUI_EMSCRIPTEN_WEBGPU_FLAG used, check correct version - if(EMSCRIPTEN_VERSION VERSION_LESS "4.0.10" AND "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}" MATCHES "emdawnwebgpu") - # it's necessary EMSCRIPTEN >= v4.0.10 (although "--use-port=path/to/emdawnwebgpu.port.py" is supported/tested from v4.0.8) - message(FATAL_ERROR "emdawnwebgpu needs EMSCRIPTEN version >= 4.0.10") - endif() + if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.10") + set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Default to --use-port=emdawnwebgpu. You can override to provide your own local port.") + else() + message(FATAL_ERROR "emdawnwebgpu needs EMSCRIPTEN version >= 4.0.10") endif() - if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "3.1.57") + if(NOT IMGUI_EMSCRIPTEN_GLFW3) + # Defaults to contrib.glfw3 because Emscripten version is > 3.1.57 set(IMGUI_EMSCRIPTEN_GLFW3 "--use-port=contrib.glfw3" CACHE STRING "Choose between --use-port=contrib.glfw3 and -sUSE_GLFW=3 for GLFW implementation (default to --use-port=contrib.glfw3)") - else() # cannot use contrib.glfw3 prior to 3.1.57 - set(IMGUI_EMSCRIPTEN_GLFW3 "-sUSE_GLFW=3" CACHE STRING "Use -sUSE_GLFW=3 for GLFW implementation" FORCE) endif() set(LIBRARIES glfw) @@ -102,7 +94,7 @@ else() # Native/Desktop build option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON) set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE STRING "Build monolithic library: SHARED, STATIC, or OFF.") - option(DAWN_USE_GLFW OFF) # disable buildin GLFW in DAWN when we use SDL2 / SDL3 + option(DAWN_USE_GLFW OFF) # disable builtin GLFW in DAWN when we use SDL2 / SDL3 # Dawn builds many things by default - disable things we don't need option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF) @@ -165,7 +157,6 @@ endif() # In this example IMGUI_IMPL_WEBGPU_BACKEND_DAWN / IMGUI_IMPL_WEBGPU_BACKEND_WGPU internal define is set according to: # EMSCRIPTEN: by used FLAG # --use-port=emdawnwebgpu --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN defined -# -sUSE_WEBGPU=1 --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU defined # NATIVE: by used SDK installation directory # if IMGUI_DAWN_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN defined # if IMGUI_WGPU_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU defined @@ -191,12 +182,8 @@ else() # Emscripten settings endif() message(STATUS "Using ${IMGUI_EMSCRIPTEN_GLFW3} GLFW implementation") - if("${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}" MATCHES "emdawnwebgpu") - target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}") - target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN") - else() - target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGPU") - endif() + target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}") + target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN") message(STATUS "Using ${IMGUI_EMSCRIPTEN_WEBGPU_FLAG} WebGPU implementation") target_link_options(${IMGUI_EXECUTABLE} PRIVATE diff --git a/examples/example_glfw_wgpu/Makefile.emscripten b/examples/example_glfw_wgpu/Makefile.emscripten index 8fee2fc7..ff386fec 100644 --- a/examples/example_glfw_wgpu/Makefile.emscripten +++ b/examples/example_glfw_wgpu/Makefile.emscripten @@ -19,8 +19,8 @@ WEB_DIR = web EXE = $(WEB_DIR)/index.html IMGUI_DIR = ../.. SOURCES = main.cpp -SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp +SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) CPPFLAGS = @@ -40,11 +40,7 @@ LDFLAGS += -s ASYNCIFY=1 LDFLAGS += -s NO_EXIT_RUNTIME=0 LDFLAGS += -s ASSERTIONS=1 -# (1) Using legacy WebGPU implementation (Emscripten < 4.0.10) -#EMS += -DIMGUI_IMPL_WEBGPU_BACKEND_WGPU -#LDFLAGS += -s USE_WEBGPU=1 - -# or (2) Using newer Dawn-based WebGPU port (Emscripten >= 4.0.10) +# Using Dawn-based WebGPU port (requires Emscripten >= 4.0.10) EMS += --use-port=emdawnwebgpu LDFLAGS += --use-port=emdawnwebgpu diff --git a/examples/example_glfw_wgpu/README.md b/examples/example_glfw_wgpu/README.md index 11964721..c1c40a59 100644 --- a/examples/example_glfw_wgpu/README.md +++ b/examples/example_glfw_wgpu/README.md @@ -60,14 +60,10 @@ For the WASM code produced by Emscripten to work correctly, it will also be nece CMake checks the EMSCRIPEN version then: - if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define - - if EMS < 4.0.10 uses `-sUSE_WEBGPU=1` flag to build - - it set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define - -#### Generate Emscripten forcing `-sUSE_WEBGPU=1` deprecated flag even with EMS >= 4.0.10 -- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="-sUSE_WEBGPU=1" -B where_to_build_dir` - - it set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define + - if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend) #### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg) + - `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir` - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define - *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:* @@ -89,7 +85,7 @@ Once the procedure for the specific builder is generated, the build command is * --- ### CMake useful options -#### Generator types (alternative to **ninja** bulder): +#### Generator types (alternative to **ninja** builder): - `-G Ninja` to build with __ninja__ builder - `-G "Unix Makefiles"` to build with __make__ builder - `-G "Visual Studio 17 2022" -A x64` to create a VS 2022 solution (.sln) file, Windows only diff --git a/examples/example_glfw_wgpu/main.cpp b/examples/example_glfw_wgpu/main.cpp index 60662b03..54dfc690 100644 --- a/examples/example_glfw_wgpu/main.cpp +++ b/examples/example_glfw_wgpu/main.cpp @@ -19,9 +19,6 @@ #ifdef __EMSCRIPTEN__ #include #include -#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#include -#endif #include "../libs/emscripten/emscripten_mainloop_stub.h" #endif @@ -40,8 +37,8 @@ static int wgpu_surface_width = 1280; static int wgpu_surface_height = 800; // Forward declarations -static bool InitWGPU(GLFWwindow* window); -static WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, GLFWwindow* window); +static bool InitWGPU(GLFWwindow* window); +WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, GLFWwindow* window); static void glfw_error_callback(int error, const char* description) { @@ -98,7 +95,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForOther(window, true); @@ -113,7 +110,7 @@ int main(int, char**) ImGui_ImplWGPU_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). @@ -344,17 +341,6 @@ static WGPUDevice RequestDevice(wgpu::Instance& instance, wgpu::Adapter& adapter return acquired_device.MoveToCHandle(); } #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#ifdef __EMSCRIPTEN__ -// Adapter and device initialization via JS -EM_ASYNC_JS( void, getAdapterAndDeviceViaJS, (), -{ - if (!navigator.gpu) - throw Error("WebGPU not supported."); - const adapter = await navigator.gpu.requestAdapter(); - const device = await adapter.requestDevice(); - Module.preinitializedWebGPUDevice = device; -} ); -#else // __EMSCRIPTEN__ static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2) { if (status == WGPURequestAdapterStatus_Success) @@ -385,30 +371,35 @@ static WGPUAdapter RequestAdapter(WGPUInstance& instance) { WGPURequestAdapterOptions adapter_options = {}; - WGPUAdapter local_adapter; + WGPUAdapter local_adapter = nullptr; WGPURequestAdapterCallbackInfo adapterCallbackInfo = {}; + adapterCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly; adapterCallbackInfo.callback = handle_request_adapter; adapterCallbackInfo.userdata1 = &local_adapter; - wgpuInstanceRequestAdapter(instance, &adapter_options, adapterCallbackInfo); + WGPUFuture future = wgpuInstanceRequestAdapter(instance, &adapter_options, adapterCallbackInfo); + WGPUFutureWaitInfo waitInfo = { future, false }; + wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull); IM_ASSERT(local_adapter && "Error on Adapter request"); return local_adapter; } -static WGPUDevice RequestDevice(WGPUAdapter& adapter) +static WGPUDevice RequestDevice(WGPUInstance& instance, WGPUAdapter& adapter) { - WGPUDevice local_device; + WGPUDevice local_device = nullptr; WGPURequestDeviceCallbackInfo deviceCallbackInfo = {}; + deviceCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly; deviceCallbackInfo.callback = handle_request_device; deviceCallbackInfo.userdata1 = &local_device; - wgpuAdapterRequestDevice(adapter, nullptr, deviceCallbackInfo); + WGPUFuture future = wgpuAdapterRequestDevice(adapter, nullptr, deviceCallbackInfo); + WGPUFutureWaitInfo waitInfo = { future, false }; + wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull); IM_ASSERT(local_device && "Error on Device request"); return local_device; } -#endif // __EMSCRIPTEN__ #endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU -static bool InitWGPU(GLFWwindow* window) +bool InitWGPU(GLFWwindow* window) { WGPUTextureFormat preferred_fmt = WGPUTextureFormat_Undefined; // acquired from SurfaceCapabilities @@ -449,25 +440,12 @@ static bool InitWGPU(GLFWwindow* window) // WGPU backend: Adapter and Device acquisition, Surface creation #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) - wgpu_instance = wgpuCreateInstance(nullptr); + WGPUInstanceDescriptor instanceDesc = {}; + WGPUInstanceFeatureName timedWaitAny = WGPUInstanceFeatureName_TimedWaitAny; + instanceDesc.requiredFeatureCount = 1; + instanceDesc.requiredFeatures = &timedWaitAny; + wgpu_instance = wgpuCreateInstance(&instanceDesc); -#ifdef __EMSCRIPTEN__ - getAdapterAndDeviceViaJS(); - - wgpu_device = emscripten_webgpu_get_device(); - IM_ASSERT(wgpu_device != nullptr && "Error creating the Device"); - - WGPUSurfaceDescriptorFromCanvasHTMLSelector html_surface_desc = {}; - html_surface_desc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector; - html_surface_desc.selector = "#canvas"; - - WGPUSurfaceDescriptor surface_desc = {}; - surface_desc.nextInChain = &html_surface_desc.chain; - - // Create the surface. - wgpu_surface = wgpuInstanceCreateSurface(wgpu_instance, &surface_desc); - preferred_fmt = wgpuSurfaceGetPreferredFormat(wgpu_surface, {} /* adapter */); -#else // __EMSCRIPTEN__ wgpuSetLogCallback( [](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr ); @@ -476,7 +454,7 @@ static bool InitWGPU(GLFWwindow* window) WGPUAdapter adapter = RequestAdapter(wgpu_instance); ImGui_ImplWGPU_DebugPrintAdapterInfo(adapter); - wgpu_device = RequestDevice(adapter); + wgpu_device = RequestDevice(wgpu_instance, adapter); // Create the surface. wgpu_surface = CreateWGPUSurface(wgpu_instance, window); @@ -487,7 +465,6 @@ static bool InitWGPU(GLFWwindow* window) wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities); preferred_fmt = surface_capabilities.formats[0]; -#endif // __EMSCRIPTEN__ #endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo; diff --git a/examples/example_glut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp index f3b4270f..ca8017f5 100644 --- a/examples/example_glut_opengl2/main.cpp +++ b/examples/example_glut_opengl2/main.cpp @@ -79,7 +79,7 @@ int main(int argc, char** argv) ImGui_ImplGLUT_InstallFuncs(); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl2_directx11/main.cpp b/examples/example_sdl2_directx11/main.cpp index 1018913b..cf397164 100644 --- a/examples/example_sdl2_directx11/main.cpp +++ b/examples/example_sdl2_directx11/main.cpp @@ -83,14 +83,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL2_InitForD3D(window); ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl2_metal/main.mm b/examples/example_sdl2_metal/main.mm index 6dbe190d..ea2afdab 100644 --- a/examples/example_sdl2_metal/main.mm +++ b/examples/example_sdl2_metal/main.mm @@ -30,7 +30,7 @@ int main(int, char**) //ImGui::StyleColorsLight(); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl2_opengl2/main.cpp b/examples/example_sdl2_opengl2/main.cpp index 59cd7ed8..3b3412b1 100644 --- a/examples/example_sdl2_opengl2/main.cpp +++ b/examples/example_sdl2_opengl2/main.cpp @@ -72,14 +72,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL2_InitForOpenGL(window, gl_context); ImGui_ImplOpenGL2_Init(); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl2_opengl3/main.cpp b/examples/example_sdl2_opengl3/main.cpp index 43e5aad0..0d992d47 100644 --- a/examples/example_sdl2_opengl3/main.cpp +++ b/examples/example_sdl2_opengl3/main.cpp @@ -112,14 +112,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL2_InitForOpenGL(window, gl_context); ImGui_ImplOpenGL3_Init(glsl_version); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl2_sdlrenderer2/main.cpp b/examples/example_sdl2_sdlrenderer2/main.cpp index 9ede2cac..b6986735 100644 --- a/examples/example_sdl2_sdlrenderer2/main.cpp +++ b/examples/example_sdl2_sdlrenderer2/main.cpp @@ -74,14 +74,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL2_InitForSDLRenderer(window, renderer); ImGui_ImplSDLRenderer2_Init(renderer); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl2_vulkan/main.cpp b/examples/example_sdl2_vulkan/main.cpp index 87a38ff9..f3953439 100644 --- a/examples/example_sdl2_vulkan/main.cpp +++ b/examples/example_sdl2_vulkan/main.cpp @@ -403,7 +403,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL2_InitForVulkan(window); @@ -426,7 +426,7 @@ int main(int, char**) ImGui_ImplVulkan_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl2_wgpu/CMakeLists.txt b/examples/example_sdl2_wgpu/CMakeLists.txt index c4c3eee8..c2c45094 100644 --- a/examples/example_sdl2_wgpu/CMakeLists.txt +++ b/examples/example_sdl2_wgpu/CMakeLists.txt @@ -52,17 +52,10 @@ set(IMGUI_EXAMPLE_SOURCE_FILES ) if(EMSCRIPTEN) - if(NOT IMGUI_EMSCRIPTEN_WEBGPU_FLAG) # if IMGUI_EMSCRIPTEN_WEBGPU_FLAG not used, set by current EMSCRIPTEN version - if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.10") - set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Choose between --use-port=emdawnwebgpu (Dawn implementation of EMSCRIPTEN) and -sUSE_WEBGPU=1 (WGPU implementation of EMSCRIPTEN, deprecated in 4.0.10): default to --use-port=emdawnwebgpu for EMSCRIPTEN >= 4.0.10") - else() - set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "-sUSE_WEBGPU=1" CACHE STRING "Use -sUSE_WEBGPU=1 for EMSCRIPTEN WGPU implementation") - endif() - else() # if IMGUI_EMSCRIPTEN_WEBGPU_FLAG used, check correct version - if(EMSCRIPTEN_VERSION VERSION_LESS "4.0.10" AND "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}" MATCHES "emdawnwebgpu") - # it's necessary EMSCRIPTEN >= v4.0.10 (although "--use-port=path/to/emdawnwebgpu.port.py" is supported/tested from v4.0.8) - message(FATAL_ERROR "emdawnwebgpu needs EMSCRIPTEN version >= 4.0.10") - endif() + if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.10") + set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Default to --use-port=emdawnwebgpu. You can override to provide your own local port.") + else() + message(FATAL_ERROR "emdawnwebgpu needs EMSCRIPTEN version >= 4.0.10") endif() add_compile_options(-sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1) @@ -92,7 +85,7 @@ else() # Native/Desktop build else() set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository") - option(DAWN_USE_GLFW OFF) # disable buildin GLFW in DAWN when we use SDL2 / SDL3 + option(DAWN_USE_GLFW OFF) # disable builtin GLFW in DAWN when we use SDL2 / SDL3 option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON) set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE STRING "Build monolithic library: SHARED, STATIC, or OFF.") @@ -160,7 +153,6 @@ endif() # IMGUI_IMPL_WEBGPU_BACKEND_DAWN/WGPU internal define is set according to: # EMSCRIPTEN: by used FLAG # --use-port=emdawnwebgpu --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN enabled (+EMSCRIPTEN) -# -sUSE_WEBGPU=1 --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU enabled (+EMSCRIPTEN) # NATIVE: by used SDK installation directory # if IMGUI_DAWN_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN enabled # if IMGUI_WGPU_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU enabled @@ -180,12 +172,8 @@ if(NOT EMSCRIPTEN) # WegGPU-Native settings else() # Emscripten settings set(CMAKE_EXECUTABLE_SUFFIX ".html") - if("${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}" MATCHES "emdawnwebgpu") - target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}") - target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN") - else() - target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGPU") - endif() + target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}") + target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN") message(STATUS "Using ${IMGUI_EMSCRIPTEN_WEBGPU_FLAG} WebGPU implementation") target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "-sUSE_SDL=2") diff --git a/examples/example_sdl2_wgpu/Makefile.emscripten b/examples/example_sdl2_wgpu/Makefile.emscripten index 69bcb00e..ebc7f97c 100644 --- a/examples/example_sdl2_wgpu/Makefile.emscripten +++ b/examples/example_sdl2_wgpu/Makefile.emscripten @@ -19,8 +19,8 @@ WEB_DIR = web EXE = $(WEB_DIR)/index.html IMGUI_DIR = ../.. SOURCES = main.cpp -SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl2.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp +SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) CPPFLAGS = @@ -40,11 +40,7 @@ LDFLAGS += -s ASYNCIFY=1 LDFLAGS += -s NO_EXIT_RUNTIME=0 LDFLAGS += -s ASSERTIONS=1 -# (1) Using legacy WebGPU implementation (Emscripten < 4.0.10) -#EMS += -DIMGUI_IMPL_WEBGPU_BACKEND_WGPU -#LDFLAGS += -s USE_WEBGPU=1 - -# or (2) Using newer Dawn-based WebGPU port (Emscripten >= 4.0.10) +# Using Dawn-based WebGPU port (requires Emscripten >= 4.0.10) EMS += --use-port=emdawnwebgpu LDFLAGS += --use-port=emdawnwebgpu diff --git a/examples/example_sdl2_wgpu/README.md b/examples/example_sdl2_wgpu/README.md index cdfd032d..3a0f2a63 100644 --- a/examples/example_sdl2_wgpu/README.md +++ b/examples/example_sdl2_wgpu/README.md @@ -60,14 +60,10 @@ For the WASM code produced by Emscripten to work correctly, it will also be nece CMake checks the EMSCRIPEN version then: - if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define - - if EMS < 4.0.10 uses `-sUSE_WEBGPU=1` flag to build - - it set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define - -#### Generate Emscripten forcing `-sUSE_WEBGPU=1` deprecated flag even with EMS >= 4.0.10 -- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="-sUSE_WEBGPU=1" -B where_to_build_dir` - - it set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define + - if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend) #### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg) + - `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir` - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define - *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:* @@ -89,7 +85,7 @@ Once the procedure for the specific builder is generated, the build command is * --- ### CMake useful options -#### Generator types (alternative to **ninja** bulder): +#### Generator types (alternative to **ninja** builder): - `-G Ninja` to build with __ninja__ builder - `-G "Unix Makefiles"` to build with __make__ builder - `-G "Visual Studio 17 2022" -A x64` to create a VS 2022 solution (.sln) file, Windows only diff --git a/examples/example_sdl2_wgpu/main.cpp b/examples/example_sdl2_wgpu/main.cpp index cddce3e6..b4c1be96 100644 --- a/examples/example_sdl2_wgpu/main.cpp +++ b/examples/example_sdl2_wgpu/main.cpp @@ -18,9 +18,6 @@ #ifdef __EMSCRIPTEN__ #include #include -#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#include -#endif #include "../libs/emscripten/emscripten_mainloop_stub.h" #endif @@ -81,7 +78,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL2_InitForOther(window); @@ -93,7 +90,7 @@ int main(int, char**) ImGui_ImplWGPU_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). @@ -328,17 +325,6 @@ static WGPUDevice RequestDevice(wgpu::Instance& instance, wgpu::Adapter& adapter return acquired_device.MoveToCHandle(); } #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#ifdef __EMSCRIPTEN__ -// Adapter and device initialization via JS -EM_ASYNC_JS( void, getAdapterAndDeviceViaJS, (), -{ - if (!navigator.gpu) - throw Error("WebGPU not supported."); - const adapter = await navigator.gpu.requestAdapter(); - const device = await adapter.requestDevice(); - Module.preinitializedWebGPUDevice = device; -} ); -#else // __EMSCRIPTEN__ static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2) { if (status == WGPURequestAdapterStatus_Success) @@ -369,27 +355,32 @@ static WGPUAdapter RequestAdapter(WGPUInstance& instance) { WGPURequestAdapterOptions adapter_options = {}; - WGPUAdapter local_adapter; + WGPUAdapter local_adapter = nullptr; WGPURequestAdapterCallbackInfo adapterCallbackInfo = {}; + adapterCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly; adapterCallbackInfo.callback = handle_request_adapter; adapterCallbackInfo.userdata1 = &local_adapter; - wgpuInstanceRequestAdapter(instance, &adapter_options, adapterCallbackInfo); + WGPUFuture future = wgpuInstanceRequestAdapter(instance, &adapter_options, adapterCallbackInfo); + WGPUFutureWaitInfo waitInfo = { future, false }; + wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull); IM_ASSERT(local_adapter && "Error on Adapter request"); return local_adapter; } -static WGPUDevice RequestDevice(WGPUAdapter& adapter) +static WGPUDevice RequestDevice(WGPUInstance& instance, WGPUAdapter& adapter) { - WGPUDevice local_device; + WGPUDevice local_device = nullptr; WGPURequestDeviceCallbackInfo deviceCallbackInfo = {}; + deviceCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly; deviceCallbackInfo.callback = handle_request_device; deviceCallbackInfo.userdata1 = &local_device; - wgpuAdapterRequestDevice(adapter, nullptr, deviceCallbackInfo); + WGPUFuture future = wgpuAdapterRequestDevice(adapter, nullptr, deviceCallbackInfo); + WGPUFutureWaitInfo waitInfo = { future, false }; + wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull); IM_ASSERT(local_device && "Error on Device request"); return local_device; } -#endif // __EMSCRIPTEN__ #endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU static bool InitWGPU(SDL_Window* window) @@ -434,25 +425,12 @@ static bool InitWGPU(SDL_Window* window) // WGPU backend: Adapter and Device acquisition, Surface creation #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) - wgpu_instance = wgpuCreateInstance(nullptr); + WGPUInstanceDescriptor instanceDesc = {}; + WGPUInstanceFeatureName timedWaitAny = WGPUInstanceFeatureName_TimedWaitAny; + instanceDesc.requiredFeatureCount = 1; + instanceDesc.requiredFeatures = &timedWaitAny; + wgpu_instance = wgpuCreateInstance(&instanceDesc); -#ifdef __EMSCRIPTEN__ - getAdapterAndDeviceViaJS(); - - wgpu_device = emscripten_webgpu_get_device(); - assert(wgpu_device != nullptr && "Error creating the Device"); - - WGPUSurfaceDescriptorFromCanvasHTMLSelector html_surface_desc = {}; - html_surface_desc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector; - html_surface_desc.selector = "#canvas"; - - WGPUSurfaceDescriptor surface_desc = {}; - surface_desc.nextInChain = &html_surface_desc.chain; - - // Create the surface. - wgpu_surface = wgpuInstanceCreateSurface(wgpu_instance, &surface_desc); - preferred_fmt = wgpuSurfaceGetPreferredFormat(wgpu_surface, {} /* adapter */); -#else // __EMSCRIPTEN__ wgpuSetLogCallback( [](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr ); @@ -461,7 +439,7 @@ static bool InitWGPU(SDL_Window* window) WGPUAdapter adapter = RequestAdapter(wgpu_instance); ImGui_ImplWGPU_DebugPrintAdapterInfo(adapter); - wgpu_device = RequestDevice(adapter); + wgpu_device = RequestDevice(wgpu_instance, adapter); // Create the surface. wgpu_surface = CreateWGPUSurface(wgpu_instance, window); @@ -472,7 +450,6 @@ static bool InitWGPU(SDL_Window* window) wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities); preferred_fmt = surface_capabilities.formats[0]; -#endif // __EMSCRIPTEN__ #endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo; diff --git a/examples/example_sdl3_directx11/main.cpp b/examples/example_sdl3_directx11/main.cpp index 06d8ea50..4337d4e2 100644 --- a/examples/example_sdl3_directx11/main.cpp +++ b/examples/example_sdl3_directx11/main.cpp @@ -74,14 +74,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForD3D(window); ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl3_metal/main.mm b/examples/example_sdl3_metal/main.mm index 9c9eab54..e6e30662 100644 --- a/examples/example_sdl3_metal/main.mm +++ b/examples/example_sdl3_metal/main.mm @@ -70,14 +70,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplMetal_Init(layer.device); ImGui_ImplSDL3_InitForMetal(window); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl3_opengl3/main.cpp b/examples/example_sdl3_opengl3/main.cpp index 1b0e100e..a36cfaba 100644 --- a/examples/example_sdl3_opengl3/main.cpp +++ b/examples/example_sdl3_opengl3/main.cpp @@ -102,14 +102,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForOpenGL(window, gl_context); ImGui_ImplOpenGL3_Init(glsl_version); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl3_sdlgpu3/main.cpp b/examples/example_sdl3_sdlgpu3/main.cpp index 3372d56b..8edbbbba 100644 --- a/examples/example_sdl3_sdlgpu3/main.cpp +++ b/examples/example_sdl3_sdlgpu3/main.cpp @@ -76,7 +76,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForSDLGPU(window); @@ -89,7 +89,7 @@ int main(int, char**) ImGui_ImplSDLGPU3_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl3_sdlrenderer3/main.cpp b/examples/example_sdl3_sdlrenderer3/main.cpp index e275e5f0..88f9ac7f 100644 --- a/examples/example_sdl3_sdlrenderer3/main.cpp +++ b/examples/example_sdl3_sdlrenderer3/main.cpp @@ -64,14 +64,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForSDLRenderer(window, renderer); ImGui_ImplSDLRenderer3_Init(renderer); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl3_vulkan/main.cpp b/examples/example_sdl3_vulkan/main.cpp index 38c48d3a..f461aab4 100644 --- a/examples/example_sdl3_vulkan/main.cpp +++ b/examples/example_sdl3_vulkan/main.cpp @@ -402,7 +402,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForVulkan(window); @@ -425,7 +425,7 @@ int main(int, char**) ImGui_ImplVulkan_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_sdl3_wgpu/CMakeLists.txt b/examples/example_sdl3_wgpu/CMakeLists.txt index 0b8dc48e..6e418821 100644 --- a/examples/example_sdl3_wgpu/CMakeLists.txt +++ b/examples/example_sdl3_wgpu/CMakeLists.txt @@ -55,18 +55,8 @@ if(EMSCRIPTEN) if(EMSCRIPTEN_VERSION VERSION_LESS "4.0.15") message(FATAL_ERROR "Using Emscripten with SDL3 needs Emscripten version >= 4.0.15") endif() - if(NOT IMGUI_EMSCRIPTEN_WEBGPU_FLAG) # if IMGUI_EMSCRIPTEN_WEBGPU_FLAG not used, set by current EMSCRIPTEN version - if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.10") - set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Choose between --use-port=emdawnwebgpu (Dawn implementation of EMSCRIPTEN) and -sUSE_WEBGPU=1 (WGPU implementation of EMSCRIPTEN, deprecated in 4.0.10): default to --use-port=emdawnwebgpu for EMSCRIPTEN >= 4.0.10") - else() - set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "-sUSE_WEBGPU=1" CACHE STRING "Use -sUSE_WEBGPU=1 for EMSCRIPTEN WGPU implementation") - endif() - else() # if IMGUI_EMSCRIPTEN_WEBGPU_FLAG used, check correct version - if(EMSCRIPTEN_VERSION VERSION_LESS "4.0.10" AND "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}" MATCHES "emdawnwebgpu") - # it's necessary EMSCRIPTEN >= v4.0.10 (although "--use-port=path/to/emdawnwebgpu.port.py" is supported/tested from v4.0.8) - message(FATAL_ERROR "emdawnwebgpu needs EMSCRIPTEN version >= 4.0.10") - endif() - endif() + # emdawnwebgpu was introduced in 4.0.10 so, due to the prior requirement, this will work + set(IMGUI_EMSCRIPTEN_WEBGPU_FLAG "--use-port=emdawnwebgpu" CACHE STRING "Default to --use-port=emdawnwebgpu. You can override to provide your own local port.") add_compile_options(-sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1) else() # Native/Desktop build @@ -95,7 +85,7 @@ else() # Native/Desktop build else() set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository") - option(DAWN_USE_GLFW OFF) # disable buildin GLFW in DAWN when we use SDL2 / SDL3 + option(DAWN_USE_GLFW OFF) # disable builtin GLFW in DAWN when we use SDL2 / SDL3 option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON) set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE STRING "Build monolithic library: SHARED, STATIC, or OFF.") @@ -162,7 +152,6 @@ endif() # IMGUI_IMPL_WEBGPU_BACKEND_DAWN/WGPU internal define is set according to: # EMSCRIPTEN: by used FLAG # --use-port=emdawnwebgpu --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN enabled (+EMSCRIPTEN) -# -sUSE_WEBGPU=1 --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU enabled (+EMSCRIPTEN) # NATIVE: by used SDK installation directory # if IMGUI_DAWN_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_DAWN enabled # if IMGUI_WGPU_DIR is valid --> IMGUI_IMPL_WEBGPU_BACKEND_WGPU enabled @@ -182,12 +171,8 @@ if(NOT EMSCRIPTEN) # WegGPU-Native settings else() # Emscripten settings set(CMAKE_EXECUTABLE_SUFFIX ".html") - if("${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}" MATCHES "emdawnwebgpu") - target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}") - target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN") - else() - target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_WGPU") - endif() + target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "${IMGUI_EMSCRIPTEN_WEBGPU_FLAG}") + target_compile_definitions(${IMGUI_EXECUTABLE} PUBLIC "IMGUI_IMPL_WEBGPU_BACKEND_DAWN") message(STATUS "Using ${IMGUI_EMSCRIPTEN_WEBGPU_FLAG} WebGPU implementation") target_compile_options(${IMGUI_EXECUTABLE} PUBLIC "-sUSE_SDL=3") diff --git a/examples/example_sdl3_wgpu/Makefile.emscripten b/examples/example_sdl3_wgpu/Makefile.emscripten index 58639a1f..c84acc77 100644 --- a/examples/example_sdl3_wgpu/Makefile.emscripten +++ b/examples/example_sdl3_wgpu/Makefile.emscripten @@ -19,8 +19,8 @@ WEB_DIR = web EXE = $(WEB_DIR)/index.html IMGUI_DIR = ../.. SOURCES = main.cpp -SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl3.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp +SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) CPPFLAGS = @@ -40,11 +40,7 @@ LDFLAGS += -s ASYNCIFY=1 LDFLAGS += -s NO_EXIT_RUNTIME=0 LDFLAGS += -s ASSERTIONS=1 -# (1) Using legacy WebGPU implementation (Emscripten < 4.0.10) -#EMS += -DIMGUI_IMPL_WEBGPU_BACKEND_WGPU -#LDFLAGS += -s USE_WEBGPU=1 - -# or (2) Using newer Dawn-based WebGPU port (Emscripten >= 4.0.10) +# Using Dawn-based WebGPU port (requires Emscripten >= 4.0.10) EMS += --use-port=emdawnwebgpu LDFLAGS += --use-port=emdawnwebgpu diff --git a/examples/example_sdl3_wgpu/README.md b/examples/example_sdl3_wgpu/README.md index bd7c3365..c7d6aec7 100644 --- a/examples/example_sdl3_wgpu/README.md +++ b/examples/example_sdl3_wgpu/README.md @@ -60,14 +60,10 @@ For the WASM code produced by Emscripten to work correctly, it will also be nece CMake checks the EMSCRIPEN version then: - if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define - - if EMS < 4.0.10 uses `-sUSE_WEBGPU=1` flag to build - - it set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define - -#### Generate Emscripten forcing `-sUSE_WEBGPU=1` deprecated flag even with EMS >= 4.0.10 -- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="-sUSE_WEBGPU=1" -B where_to_build_dir` - - it set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define + - if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend #### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg) + - `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir` - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define - *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:* @@ -89,7 +85,7 @@ Once the procedure for the specific builder is generated, the build command is * --- ### CMake useful options -#### Generator types (alternative to **ninja** bulder): +#### Generator types (alternative to **ninja** builder): - `-G Ninja` to build with __ninja__ builder - `-G "Unix Makefiles"` to build with __make__ builder - `-G "Visual Studio 17 2022" -A x64` to create a VS 2022 solution (.sln) file, Windows only diff --git a/examples/example_sdl3_wgpu/main.cpp b/examples/example_sdl3_wgpu/main.cpp index b5ae84bf..523d6215 100644 --- a/examples/example_sdl3_wgpu/main.cpp +++ b/examples/example_sdl3_wgpu/main.cpp @@ -20,9 +20,6 @@ #ifdef __EMSCRIPTEN__ #include #include -#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#include -#endif #include "../libs/emscripten/emscripten_mainloop_stub.h" #endif @@ -40,8 +37,8 @@ static int wgpu_surface_width = 1280; static int wgpu_surface_height = 800; // Forward declarations -static bool InitWGPU(SDL_Window* window); -static WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, SDL_Window* window); +static bool InitWGPU(SDL_Window* window); +WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, SDL_Window* window); static void ResizeSurface(int width, int height) { @@ -88,7 +85,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForOther(window); @@ -101,7 +98,7 @@ int main(int, char**) ImGui_ImplWGPU_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). @@ -339,17 +336,6 @@ static WGPUDevice RequestDevice(wgpu::Instance& instance, wgpu::Adapter& adapter return acquired_device.MoveToCHandle(); } #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) -#ifdef __EMSCRIPTEN__ -// Adapter and device initialization via JS -EM_ASYNC_JS( void, getAdapterAndDeviceViaJS, (), -{ - if (!navigator.gpu) - throw Error("WebGPU not supported."); - const adapter = await navigator.gpu.requestAdapter(); - const device = await adapter.requestDevice(); - Module.preinitializedWebGPUDevice = device; -} ); -#else // __EMSCRIPTEN__ static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2) { if (status == WGPURequestAdapterStatus_Success) @@ -380,27 +366,32 @@ static WGPUAdapter RequestAdapter(WGPUInstance& instance) { WGPURequestAdapterOptions adapter_options = {}; - WGPUAdapter local_adapter; + WGPUAdapter local_adapter = nullptr; WGPURequestAdapterCallbackInfo adapterCallbackInfo = {}; + adapterCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly; adapterCallbackInfo.callback = handle_request_adapter; adapterCallbackInfo.userdata1 = &local_adapter; - wgpuInstanceRequestAdapter(instance, &adapter_options, adapterCallbackInfo); + WGPUFuture future = wgpuInstanceRequestAdapter(instance, &adapter_options, adapterCallbackInfo); + WGPUFutureWaitInfo waitInfo = { future, false }; + wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull); IM_ASSERT(local_adapter && "Error on Adapter request"); return local_adapter; } -static WGPUDevice RequestDevice(WGPUAdapter& adapter) +static WGPUDevice RequestDevice(WGPUInstance& instance, WGPUAdapter& adapter) { - WGPUDevice local_device; + WGPUDevice local_device = nullptr; WGPURequestDeviceCallbackInfo deviceCallbackInfo = {}; + deviceCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly; deviceCallbackInfo.callback = handle_request_device; deviceCallbackInfo.userdata1 = &local_device; - wgpuAdapterRequestDevice(adapter, nullptr, deviceCallbackInfo); + WGPUFuture future = wgpuAdapterRequestDevice(adapter, nullptr, deviceCallbackInfo); + WGPUFutureWaitInfo waitInfo = { future, false }; + wgpuInstanceWaitAny(instance, 1, &waitInfo, ~0ull); IM_ASSERT(local_device && "Error on Device request"); return local_device; } -#endif // __EMSCRIPTEN__ #endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU static bool InitWGPU(SDL_Window* window) @@ -445,25 +436,12 @@ static bool InitWGPU(SDL_Window* window) // WGPU backend: Adapter and Device acquisition, Surface creation #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) - wgpu_instance = wgpuCreateInstance(nullptr); + WGPUInstanceDescriptor instanceDesc = {}; + WGPUInstanceFeatureName timedWaitAny = WGPUInstanceFeatureName_TimedWaitAny; + instanceDesc.requiredFeatureCount = 1; + instanceDesc.requiredFeatures = &timedWaitAny; + wgpu_instance = wgpuCreateInstance(&instanceDesc); -#ifdef __EMSCRIPTEN__ - getAdapterAndDeviceViaJS(); - - wgpu_device = emscripten_webgpu_get_device(); - IM_ASSERT(wgpu_device != nullptr && "Error creating the Device"); - - WGPUSurfaceDescriptorFromCanvasHTMLSelector html_surface_desc = {}; - html_surface_desc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector; - html_surface_desc.selector = "#canvas"; - - WGPUSurfaceDescriptor surface_desc = {}; - surface_desc.nextInChain = &html_surface_desc.chain; - - // Create the surface. - wgpu_surface = wgpuInstanceCreateSurface(wgpu_instance, &surface_desc); - preferred_fmt = wgpuSurfaceGetPreferredFormat(wgpu_surface, {} /* adapter */); -#else // __EMSCRIPTEN__ wgpuSetLogCallback( [](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr ); @@ -472,7 +450,7 @@ static bool InitWGPU(SDL_Window* window) WGPUAdapter adapter = RequestAdapter(wgpu_instance); ImGui_ImplWGPU_DebugPrintAdapterInfo(adapter); - wgpu_device = RequestDevice(adapter); + wgpu_device = RequestDevice(wgpu_instance, adapter); // Create the surface. wgpu_surface = CreateWGPUSurface(wgpu_instance, window); @@ -483,7 +461,6 @@ static bool InitWGPU(SDL_Window* window) wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities); preferred_fmt = surface_capabilities.formats[0]; -#endif // __EMSCRIPTEN__ #endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo; @@ -513,7 +490,7 @@ static bool InitWGPU(SDL_Window* window) #include #endif -static WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, SDL_Window* window) +WGPUSurface CreateWGPUSurface(const WGPUInstance& instance, SDL_Window* window) { SDL_PropertiesID propertiesID = SDL_GetWindowProperties(window); diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index 6a768753..2c342070 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -65,14 +65,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplWin32_Init(hwnd); ImGui_ImplDX10_Init(g_pd3dDevice); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index 9ca7705f..524538ac 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -65,14 +65,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplWin32_Init(hwnd); ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_win32_directx12/example_win32_directx12.vcxproj b/examples/example_win32_directx12/example_win32_directx12.vcxproj index bb98c414..c4b81e76 100644 --- a/examples/example_win32_directx12/example_win32_directx12.vcxproj +++ b/examples/example_win32_directx12/example_win32_directx12.vcxproj @@ -21,34 +21,34 @@ {b4cf9797-519d-4afe-a8f4-5141a6b521d3} example_win32_directx12 - 10.0.20348.0 + 10.0 Application true Unicode - v140 + v142 Application true Unicode - v140 + v142 Application false true Unicode - v140 + v142 Application false true Unicode - v140 + v142 diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 85c598fb..0d8bb20b 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -145,7 +145,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplWin32_Init(hwnd); @@ -167,7 +167,7 @@ int main(int, char**) //ImGui_ImplDX12_Init(g_pd3dDevice, APP_NUM_FRAMES_IN_FLIGHT, DXGI_FORMAT_R8G8B8A8_UNORM, g_pd3dSrvDescHeap, g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp index 2fe01420..fbe4c398 100644 --- a/examples/example_win32_directx9/main.cpp +++ b/examples/example_win32_directx9/main.cpp @@ -63,14 +63,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplWin32_Init(hwnd); ImGui_ImplDX9_Init(g_pd3dDevice); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_win32_opengl3/main.cpp b/examples/example_win32_opengl3/main.cpp index f83d693f..d18ea0bd 100644 --- a/examples/example_win32_opengl3/main.cpp +++ b/examples/example_win32_opengl3/main.cpp @@ -73,14 +73,14 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplWin32_InitForOpenGL(hwnd); ImGui_ImplOpenGL3_Init(); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/example_win32_vulkan/main.cpp b/examples/example_win32_vulkan/main.cpp index 75c5605c..7f1ccd0c 100644 --- a/examples/example_win32_vulkan/main.cpp +++ b/examples/example_win32_vulkan/main.cpp @@ -390,7 +390,7 @@ int main(int, char**) // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) - style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + style.FontScaleDpi = main_scale; // Set initial font scale. (in docking branch: using io.ConfigDpiScaleFonts=true automatically overrides this for every window depending on the current monitor) // Setup Platform/Renderer backends ImGui_ImplWin32_Init(hwnd); @@ -413,7 +413,7 @@ int main(int, char**) ImGui_ImplVulkan_Init(&init_info); // Load Fonts - // - If fonts are not explicitly loaded, Dear ImGui will call AddFontDefault() to select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). + // - If fonts are not explicitly loaded, Dear ImGui will select an embedded font: either AddFontDefaultVector() or AddFontDefaultBitmap(). // This selection is based on (style.FontSizeBase * style.FontScaleMain * style.FontScaleDpi) reaching a small threshold. // - You can load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If a file cannot be loaded, AddFont functions will return a nullptr. Please handle those errors in your code (e.g. use an assertion, display an error and quit). diff --git a/examples/libs/emscripten/shell_minimal.html b/examples/libs/emscripten/shell_minimal.html index bcf62626..939dc177 100644 --- a/examples/libs/emscripten/shell_minimal.html +++ b/examples/libs/emscripten/shell_minimal.html @@ -5,7 +5,7 @@ Dear ImGui Emscripten example - +