From 4537d98d46005cb68f7c00e00154cf1aaeaa68c6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 2 Mar 2021 15:03:16 +0100 Subject: [PATCH] Backends: DX9: Fix to support colored glyphs, using newly introduced 'TexPixelsUseColors' info. (#3369, #3844) --- backends/imgui_impl_dx9.cpp | 19 ++++++++++++++----- docs/CHANGELOG.txt | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backends/imgui_impl_dx9.cpp b/backends/imgui_impl_dx9.cpp index 7e851ec7..3fe0fe3e 100644 --- a/backends/imgui_impl_dx9.cpp +++ b/backends/imgui_impl_dx9.cpp @@ -45,6 +45,12 @@ struct CUSTOMVERTEX }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) +#ifdef IMGUI_USE_BGRA_PACKED_COLOR +#define IMGUI_COL_TO_DX9_ARGB(_COL) (_COL) +#else +#define IMGUI_COL_TO_DX9_ARGB(_COL) (((_COL) & 0xFF00FF00) | (((_COL) & 0xFF0000) >> 16) | (((_COL) & 0xFF) << 16)) +#endif + static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data) { // Setup viewport @@ -157,11 +163,7 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) vtx_dst->pos[0] = vtx_src->pos.x; vtx_dst->pos[1] = vtx_src->pos.y; vtx_dst->pos[2] = 0.0f; -#ifdef IMGUI_USE_BGRA_PACKED_COLOR - vtx_dst->col = vtx_src->col; -#else - vtx_dst->col = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000) >> 16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 -#endif + vtx_dst->col = IMGUI_COL_TO_DX9_ARGB(vtx_src->col); vtx_dst->uv[0] = vtx_src->uv.x; vtx_dst->uv[1] = vtx_src->uv.y; vtx_dst++; @@ -248,6 +250,13 @@ static bool ImGui_ImplDX9_CreateFontsTexture() int width, height, bytes_per_pixel; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &bytes_per_pixel); + // Convert RGBA32 to BGRA32 as the earlier is not well supported by DX9 devices +#ifndef IMGUI_USE_BGRA_PACKED_COLOR + if (io.Fonts->TexPixelsUseColors) + for (ImU32* p = (ImU32*)pixels, *p_end = p + width * height; p < p_end; p++) + *p = IMGUI_COL_TO_DX9_ARGB(*p); +#endif + // Upload texture to graphics system g_FontTexture = NULL; if (g_pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_FontTexture, NULL) < 0) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bc9a75c3..75516745 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -63,6 +63,7 @@ Other Changes: accross all backends), facilitating compositing of the output buffer with another buffer. (#2693, #2764, #2766, #2873, #3447, #3813, #3816) [@ocornut, @thedmd, @ShawnM427, @Ubpa, @aiekick] - Backends: DX9: Fix to support IMGUI_USE_BGRA_PACKED_COLOR. (#3844) [@Xiliusha] +- Backends: DX9: Fix to support colored glyphs, using newly introduced 'TexPixelsUseColors' info. (#3844) - Examples: Reworked setup of clear color to be compatible with transparent values. - CI: Use a dedicated "scheduled" workflow to trigger scheduled builds. Forks may disable this workflow if scheduled builds builds are not required. [@rokups]