Introduce IMGUI_USE_BGRA_PACKED_COLOR in imconfig.h.

When IMGUI_USE_BGRA_PACKED_COLOR is defined packed color hold in ImU32 use BGRA format instead RGBA.
This commit is contained in:
Michał Cichoń 2016-08-05 11:04:05 +02:00
parent 82dcdc9dfc
commit d75d2b1871
3 changed files with 24 additions and 6 deletions

View File

@ -26,6 +26,9 @@
//---- Don't define obsolete functions names //---- Don't define obsolete functions names
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS //#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 //---- Implement STB libraries in a namespace to avoid conflicts
//#define IMGUI_STB_NAMESPACE ImGuiStb //#define IMGUI_STB_NAMESPACE ImGuiStb

View File

@ -1195,16 +1195,20 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e
ImVec4 ImGui::ColorConvertU32ToFloat4(ImU32 in) ImVec4 ImGui::ColorConvertU32ToFloat4(ImU32 in)
{ {
float s = 1.0f/255.0f; 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 ImGui::ColorConvertFloat4ToU32(const ImVec4& in)
{ {
ImU32 out; ImU32 out;
out = ((ImU32)IM_F32_TO_INT8_SAT(in.x)); out = ((ImU32)IM_F32_TO_INT8_SAT(in.x)) << IM_COL32_R_SHIFT;
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.y)) << 8; out |= ((ImU32)IM_F32_TO_INT8_SAT(in.y)) << IM_COL32_G_SHIFT;
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.z)) << 16; out |= ((ImU32)IM_F32_TO_INT8_SAT(in.z)) << IM_COL32_B_SHIFT;
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.w)) << 24; out |= ((ImU32)IM_F32_TO_INT8_SAT(in.w)) << IM_COL32_A_SHIFT;
return out; return out;
} }

13
imgui.h
View File

@ -1091,7 +1091,18 @@ struct ImGuiListClipper
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Helpers macros to generate 32-bits encoded colors // 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)<<IM_COL32_A_SHIFT) | ((ImU32)(B)<<IM_COL32_B_SHIFT) | ((ImU32)(G)<<IM_COL32_G_SHIFT) | ((ImU32)(R)<<IM_COL32_R_SHIFT))
#define IM_COL32_WHITE (0xFFFFFFFF) #define IM_COL32_WHITE (0xFFFFFFFF)
#define IM_COL32_BLACK (0xFF000000) #define IM_COL32_BLACK (0xFF000000)
#define IM_COL32_BLACK_TRANS (0x00000000) // Transparent black #define IM_COL32_BLACK_TRANS (0x00000000) // Transparent black