From 20f118801d8b18b0dd77ae35c8049ca5d6d9ad44 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 15 Aug 2021 08:45:12 +0300 Subject: SDL 2.0.16 line drawing regression (OpenGL renderer) This is not specific to macOS, but seems to affect OpenGL rendering on all platforms. --- src/macos.m | 1 + src/ui/labelwidget.c | 11 ++++++----- src/ui/paint.c | 12 +++++++----- src/ui/window.c | 7 +++++++ src/ui/window.h | 2 ++ 5 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/macos.m b/src/macos.m index 6bec3c12..d588fa4a 100644 --- a/src/macos.m +++ b/src/macos.m @@ -60,6 +60,7 @@ static NSString *currentSystemAppearance_(void) { } iBool shouldDefaultToMetalRenderer_MacOS(void) { + /* TODO: Test if SDL 2.0.16 works better (no stutters with Metal?). */ return iFalse; /* const iInt2 ver = macVer_(); return ver.x > 10 || ver.y > 13;*/ diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c index d6cc31cb..edc36a49 100644 --- a/src/ui/labelwidget.c +++ b/src/ui/labelwidget.c @@ -300,14 +300,15 @@ static void draw_LabelWidget_(const iLabelWidget *d) { bottomLeft_Rect(frameRect), topLeft_Rect(frameRect), topRight_Rect(frameRect), -#if SDL_VERSION_ATLEAST(2, 0, 16) && defined (iPlatformApple) - /* A very curious regression in SDL 2.0.16 on macOS. */ - addX_I2(bottomRight_Rect(frameRect), -1), -#else bottomRight_Rect(frameRect), -#endif bottomLeft_Rect(frameRect) }; +#if SDL_VERSION_ATLEAST(2, 0, 16) + if (isOpenGLRenderer_Window()) { + /* A very curious regression in SDL 2.0.16. */ + points[3].x--; + } +#endif drawLines_Paint(&p, points + 2, 3, frame2); drawLines_Paint( &p, points, !isHover && flags & d->flags.noTopFrame ? 2 : 3, frame); diff --git a/src/ui/paint.c b/src/ui/paint.c index 869238d5..79adb7d1 100644 --- a/src/ui/paint.c +++ b/src/ui/paint.c @@ -89,17 +89,19 @@ void drawRect_Paint(const iPaint *d, iRect rect, int color) { /* Keep the right/bottom edge visible in the window. */ if (br.x == d->dst->size.x) br.x--; if (br.y == d->dst->size.y) br.y--; - const SDL_Point edges[] = { + SDL_Point edges[] = { { left_Rect(rect), top_Rect(rect) }, { br.x, top_Rect(rect) }, { br.x, br.y }, -#if SDL_VERSION_ATLEAST(2, 0, 16) && defined (iPlatformApple) - { left_Rect(rect), br.y - 1 }, /* regression in SDL 2.0.16? */ -#else { left_Rect(rect), br.y }, -#endif { left_Rect(rect), top_Rect(rect) } }; +#if SDL_VERSION_ATLEAST(2, 0, 16) + if (isOpenGLRenderer_Window()) { + /* A very curious regression in SDL 2.0.16. */ + edges[3].y--; + } +#endif setColor_Paint_(d, color); SDL_RenderDrawLines(renderer_Paint_(d), edges, iElemCount(edges)); } diff --git a/src/ui/window.c b/src/ui/window.c index 6b8abb4d..86d22b1c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -65,6 +65,8 @@ static float initialUiScale_ = 1.0f; static float initialUiScale_ = 1.1f; #endif +static iBool isOpenGLRenderer_; + iDefineTypeConstructionArgs(Window, (iRect rect), rect) /* TODO: Define menus per platform. */ @@ -446,6 +448,7 @@ void init_Window(iWindow *d, iRect rect) { /* Some info. */ { SDL_RendererInfo info; SDL_GetRendererInfo(d->render, &info); + isOpenGLRenderer_ = !iCmpStr(info.name, "opengl"); printf("[window] renderer: %s%s\n", info.name, info.flags & SDL_RENDERER_ACCELERATED ? " (accelerated)" : ""); #if !defined (NDEBUG) @@ -1187,6 +1190,10 @@ iWindow *get_Window(void) { return theWindow_; } +iBool isOpenGLRenderer_Window(void) { + return isOpenGLRenderer_; +} + void setKeyboardHeight_Window(iWindow *d, int height) { if (d->keyboardHeight != height) { d->keyboardHeight = height; diff --git a/src/ui/window.h b/src/ui/window.h index bb98dbe9..63f7e5f2 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -137,6 +137,8 @@ iRoot * findRoot_Window (const iWindow *, const iWidget *widget); iRoot * otherRoot_Window (const iWindow *, iRoot *root); iWindow * get_Window (void); +iBool isOpenGLRenderer_Window (void); + #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) SDL_HitTestResult hitTest_Window(const iWindow *d, iInt2 pos); #endif -- cgit v1.2.3