diff --git a/imconfig.h b/imconfig.h index 33cbadd17e36..2a956d3772b2 100644 --- a/imconfig.h +++ b/imconfig.h @@ -26,6 +26,9 @@ //---- Don't define obsolete functions names //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +//---- Pack colors to BGRA instead of RGBA (remove need to post process vertex buffer in back ends) +//#define IMGUI_USE_BGRA_PACKED_COLOR + //---- Implement STB libraries in a namespace to avoid conflicts //#define IMGUI_STB_NAMESPACE ImGuiStb diff --git a/imgui.cpp b/imgui.cpp index c33efc98e4c8..3fb183b46594 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1195,16 +1195,20 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e ImVec4 ImGui::ColorConvertU32ToFloat4(ImU32 in) { float s = 1.0f/255.0f; - return ImVec4((in & 0xFF) * s, ((in >> 8) & 0xFF) * s, ((in >> 16) & 0xFF) * s, (in >> 24) * s); + return ImVec4( + ((in >> IM_COL32_R_SHIFT) & 0xFF) * s, + ((in >> IM_COL32_G_SHIFT) & 0xFF) * s, + ((in >> IM_COL32_B_SHIFT) & 0xFF) * s, + ((in >> IM_COL32_A_SHIFT) & 0xFF) * s); } ImU32 ImGui::ColorConvertFloat4ToU32(const ImVec4& in) { ImU32 out; - out = ((ImU32)IM_F32_TO_INT8_SAT(in.x)); - out |= ((ImU32)IM_F32_TO_INT8_SAT(in.y)) << 8; - out |= ((ImU32)IM_F32_TO_INT8_SAT(in.z)) << 16; - out |= ((ImU32)IM_F32_TO_INT8_SAT(in.w)) << 24; + out = ((ImU32)IM_F32_TO_INT8_SAT(in.x)) << IM_COL32_R_SHIFT; + out |= ((ImU32)IM_F32_TO_INT8_SAT(in.y)) << IM_COL32_G_SHIFT; + out |= ((ImU32)IM_F32_TO_INT8_SAT(in.z)) << IM_COL32_B_SHIFT; + out |= ((ImU32)IM_F32_TO_INT8_SAT(in.w)) << IM_COL32_A_SHIFT; return out; } diff --git a/imgui.h b/imgui.h index d6b12b27de98..15149c1bda99 100644 --- a/imgui.h +++ b/imgui.h @@ -1091,7 +1091,18 @@ struct ImGuiListClipper //----------------------------------------------------------------------------- // Helpers macros to generate 32-bits encoded colors -#define IM_COL32(R,G,B,A) (((ImU32)(A)<<24) | ((ImU32)(B)<<16) | ((ImU32)(G)<<8) | ((ImU32)(R))) +#ifdef IMGUI_USE_BGRA_PACKED_COLOR +#define IM_COL32_R_SHIFT 16 +#define IM_COL32_G_SHIFT 8 +#define IM_COL32_B_SHIFT 0 +#define IM_COL32_A_SHIFT 24 +#else +#define IM_COL32_R_SHIFT 0 +#define IM_COL32_G_SHIFT 8 +#define IM_COL32_B_SHIFT 16 +#define IM_COL32_A_SHIFT 24 +#endif +#define IM_COL32(R,G,B,A) (((ImU32)(A)<