impr: Slightly simplify subpixel rendering logic and required ImGui patches

This commit is contained in:
WerWolv
2025-05-24 22:32:08 +02:00
parent c6548d5ad1
commit de16375903
3 changed files with 62 additions and 73 deletions

View File

@@ -420,17 +420,13 @@ void ImGui_ImplOpenGL3_NewFrame()
}
// IMHEX PATCH BEGIN
bool useFontShaders = false;
void FontShadersOn(const ImDrawList *parent_list, const ImDrawCmd *cmd) {
static bool useFontShaders = false;
void ImGui_ImplOpenGL3_TurnFontShadersOn(const ImDrawList *parent_list, const ImDrawCmd *cmd) {
useFontShaders = true;
}
void FontShadersOff(const ImDrawList *parent_list, const ImDrawCmd *cmd) {
void ImGui_ImplOpenGL3_TurnFontShadersOff(const ImDrawList *parent_list, const ImDrawCmd *cmd) {
useFontShaders = false;
}
ImDrawCallback ImGui_ImplOpenGL3_TurnFontShadersOn = &FontShadersOn;
ImDrawCallback ImGui_ImplOpenGL3_TurnFontShadersOff = &FontShadersOff;
// IMHEX PATCH END
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
@@ -496,10 +492,9 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
// IMHEX PATCH END
const float ortho_projection[4][4] =
{
// IMHEX PATCH BEGIN
// IMHEX PATCH BEGIN
{ 2.0f/(R-L), 0.0f, Gamma, 0.0f },
// { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
// IMHEX PATCH END
// IMHEX PATCH END
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
@@ -639,14 +634,6 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
// IMHEX PATCH BEGIN
else if (pcmd->UserCallback == ImGui_ImplOpenGL3_TurnFontShadersOn) {
ImGui_ImplOpenGL3_TurnFontShadersOn(cmd_list, pcmd);
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
} else if (pcmd->UserCallback == ImGui_ImplOpenGL3_TurnFontShadersOff) {
ImGui_ImplOpenGL3_TurnFontShadersOff(cmd_list, pcmd);
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
} // IMHEX PATCH END
else
pcmd->UserCallback(cmd_list, pcmd);
}

View File

@@ -1695,10 +1695,7 @@ void ImDrawList::AddBezierQuadratic(const ImVec2& p1, const ImVec2& p2, const Im
PathBezierQuadraticCurveTo(p2, p3, num_segments);
PathStroke(col, 0, thickness);
}
// IMHEX PATCH BEGIN
extern ImDrawCallback ImGui_ImplOpenGL3_TurnFontShadersOn;
extern ImDrawCallback ImGui_ImplOpenGL3_TurnFontShadersOff;
// IMHEX PATCH END
void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect)
{
if ((col & IM_COL32_A_MASK) == 0)
@@ -1732,15 +1729,21 @@ void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32
flags = font->ContainerAtlas->FontBuilderFlags;
is_subpixel = (flags & ImGuiFreeTypeBuilderFlags_SubPixel) != 0;
}
if (is_subpixel)
void ImGui_ImplOpenGL3_TurnFontShadersOn(const ImDrawList *parent_list, const ImDrawCmd *cmd);
void ImGui_ImplOpenGL3_TurnFontShadersOff(const ImDrawList *parent_list, const ImDrawCmd *cmd);
if (is_subpixel) {
AddCallback(ImGui_ImplOpenGL3_TurnFontShadersOn, NULL);
// IMHEX PATCH END
AddCallback(ImDrawCallback_ResetRenderState, NULL);
}
font->RenderText(this, font_size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip_rect != NULL);
// IMHEX PATCH BEGIN
if (is_subpixel)
if (is_subpixel) {
AddCallback(ImGui_ImplOpenGL3_TurnFontShadersOff, NULL);
AddCallback(ImDrawCallback_ResetRenderState, NULL);
}
// IMHEX PATCH END
}