-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce IMGUI_USE_BGRA_PACKED_COLOR in imconfig.h. #844
Conversation
When IMGUI_USE_BGRA_PACKED_COLOR is defined packed color hold in ImU32 use BGRA format instead RGBA.
…RR,GG,BB,AA) format.
Merged, thanks. Sorry for the late reaction. I'm particularly eager to tidy up the inconsistent handling of colors (ImVec4 or U32) and a little cautious around those areas. |
Not sure if this is appropriate (I still have to understand if old code is backward-compatible with this PR). However the question is: if ((col >> 24) == 0) {...} or not ? |
Yes we should.. |
Old code will work since in both cases alpha occupy same bits. |
Ah you are right, alpha hasn't moved. So it's not urgent/important. Just I can do it, it's easy. |
Done. |
@thedmd I am curious: if you are using this, are you able to also use functions such as ColorEdit4() ? How do you encode your user/app-side colors that may need authoring using imgui tools? Are they encoded the same way as your renderer packed color values? |
@ocornut I'm using this mode in our engine, since I'm stuck with a variant of fixed pipeline compatibility layer where I can pick what vertex buffer is build from but do not have precise control over format. Using BGRA allows me to just memcpy vertex data to our vertex buffer. User code never touches render code directly. Instead it operate on high level primitives like Image or Text where color is set using our version of ImColor structure. ImGui works as usual. Including ColorEdit4() where our color can be used directly. When dealing with draw lists colors are converted using ImColor() or stated explicitly using IM_COL32() macro. Raw values are never used. Does that answer to your question? |
Hmm I guess my question didn't entirely make sense, since currently What I am wondering is, if people store U32 colors in their game objects and they want to edit them, would they necessarily be in the same format as the U32 colors for rendering? |
I'm using floats. They are lingua franca in color world. If game object choose packed format over floats edit code can unpack it prior to calling ColorEdit4() and repack if changed. I think if game object store color in packed format and it is very same ImGui use it is a convinient coincidence rather than desired behavior. |
PR was recreated due to lost references after changing fork origin. That was not my intention, sorry.
For comments please look at previous PR.
PR adds ability to tell ImGui to generate packed color in BGRA format instead of RGBA.
This change simplify backend implementation by removing need to convert colors in vertex buffer before uploading to engine. For ImGui packing colors differently make no difference and backend can use memcpy().
To change color packing uncomment
#define IMGUI_USE_BGRA_PACKED_COLOR
in imconfig.hWhat changes. Hardcoded bit shifts were replaced by constants like
IM_COL32_R_SHIFT
. Depending ofIMGUI_USE_BGRA_PACKED_COLOR
being defined constants have different values.