indigodarkwolf / box16

A fork of the official X16 emulator, converted to C++20 and with a bunch of features tweaked and added.
MIT License
42 stars 19 forks source link

Palette shows colour values in RGBA #65

Open Yazwh0 opened 1 year ago

Yazwh0 commented 1 year ago

This is probably an enhancement, rather than a bug.

The palette shows the colour in 32bit RGBA, rather than 12bit X16 colours. Showing colour number would be handy as well.

image

bylickilabs commented 1 year ago

Absolutely

indigodarkwolf commented 1 year ago

Yeah, I'd categorize this as an enhancement. Imgui's color widget doesn't support 12bit color. Box16 should be rounding it appropriately, but I'll need to write a bespoke color widget, or modify Imgui's widget.

indigodarkwolf commented 1 year ago

In terms of priority, I'm currently looking at adding read/write data breakpoints, so far this would come after that.

indigodarkwolf commented 1 year ago

So I've been looking into this. Fixing UIs and whatnot to only show 4-bit color components is easy enough. Fixing the color wheel and triangle in the color picker to only show VERA-legal colors is probably impossible.

The issue is that OpenGL is drawing the UI elements in 32-bit color, and it's blending the color on the triangles making up those widgets with 32-bit precision. There's no good way that I'm seeing to fix that in ImGui, because ImGui is queuing up all the geometry (and texture UVs and color data) to draw before issuing its draw calls. Even if I clamp the colors of the vertices to VERA-legal colors, the blending between different verts with different colors is still a problem.

It may still be possible to fix the color wheel specifically, but the problem is finding the thresholds where the color changes so I can slice it up into a bunch of tiny, monochrome arcs. I don't have any ideas right now that would fix the triangle to only show VERA-legal colors.

The "right" way would probably be to change the fragment shader in use by ImGui, maybe adding a parameter to various verts to indicate when their associated fragments should be clamped to VERA-legal colors. But that will require some deep digging to find the shader and make changes, and propagate the data structure changes through ImGui. That's quite a large amount of work and likely means never being able to pick up fixes or updates to ImGui ever again... so I'm not a super big fan of that.

At the very least, I'm inclined to commit the changes I have at present that don't address the colors represented on the color wheel or the triangle, and leave those specific widgets for another day.

indigodarkwolf commented 1 year ago

So unless/until I dig into the rendering pipeline to create a specialized 4-bit color case for this widget, 3d434511b08a61e679e47a08fc11fa2238af21f7 is about as good as this can get: 4-bit color palette in the various text fields and inputs, but the color gradients themselves are still 32-bit and shall remain 32-bit for the foreseeable future.

If folks want, we can still leave this open, but at the moment I have no plans to dig that far into Imgui.