From 2285a6ab210257f9e4d93b93704a5b03b72ac6da Mon Sep 17 00:00:00 2001 From: ANSI TV Admin Date: Wed, 11 Nov 2026 16:48:49 -0800 Subject: [PATCH 22/24] Exclusive border: drawn over the picture's edge, never by shrinking it -- Pointy stays sharp With a frame and no window margin, the picture was shrunk by 2b pixels to make room, which scaled it by a non-integer factor and lost Pointy's sharp edges (and blurred Blocky/External). The picture now always keeps its own size. The frame goes in the margin when there is room (letterboxed, maximised), round the screen in fullscreen, and otherwise over the picture's outermost pixels -- drawn AFTER the picture: with the SDL renderer after RenderCopy, and on the GPU Pointy path with scissored glClears after gpu_pointy_present. --- src/conio/gpu_pointy.c | 33 ++++++++++++++- src/conio/gpu_pointy.h | 1 + src/conio/sdl_con.c | 92 ++++++++++++++++++++++-------------------- 3 files changed, 82 insertions(+), 44 deletions(-) diff --git a/src/conio/gpu_pointy.c b/src/conio/gpu_pointy.c index 9a4c5345..2dc75914 100644 --- a/src/conio/gpu_pointy.c +++ b/src/conio/gpu_pointy.c @@ -45,7 +45,11 @@ F(void, DeleteVertexArrays, (GLsizei, const GLuint *)) \ F(void, BindVertexArray, (GLuint)) \ F(void, DrawArrays, (GLenum, GLint, GLsizei)) \ - F(void, ReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void *)) + F(void, ReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void *)) \ + F(void, Scissor, (GLint, GLint, GLsizei, GLsizei)) \ + F(void, ClearColor, (GLfloat, GLfloat, GLfloat, GLfloat)) \ + F(void, Clear, (GLbitfield)) \ + F(void, GetFloatv, (GLenum, GLfloat *)) #define DECLARE(ret, name, args) ret (APIENTRY *name) args; static struct { GPU_GL(DECLARE) } gl; @@ -308,6 +312,33 @@ bool gpu_pointy_present(int w,int h,int ww,int wh) return ok; } +/* The exclusive-mouse frame, drawn OVER what is on the default framebuffer + * (after gpu_pointy_present), so the picture keeps its exact integer size. + * Rectangles are in window pixels with a top-left origin. */ +bool gpu_pointy_frame(int ww,int wh,int x,int y,int w,int h,int b,uint32_t rgb) +{ + struct state saved; + GLfloat cc[4]; + int r[4][4]={{x,y,w,b},{x,y+h-b,w,b},{x,y,b,h},{x+w-b,y,b,h}}; + (void)ww; + if (b<=0 || w<=0 || h<=0) + return true; + save(&saved); + gl.GetFloatv(GL_COLOR_CLEAR_VALUE,cc); + gl.BindFramebuffer(GL_FRAMEBUFFER,0); + gl.Enable(GL_SCISSOR_TEST); + gl.ClearColor(((rgb>>16)&0xFF)/255.0f,((rgb>>8)&0xFF)/255.0f,(rgb&0xFF)/255.0f,1.0f); + for (int i=0;i<4;i++) { + gl.Scissor(r[i][0],wh-(r[i][1]+r[i][3]),r[i][2],r[i][3]); + gl.Clear(GL_COLOR_BUFFER_BIT); + } + gl.Disable(GL_SCISSOR_TEST); + gl.ClearColor(cc[0],cc[1],cc[2],cc[3]); + bool ok=check(); + restore(&saved); + return ok; +} + bool gpu_pointy_read(uint32_t *pixels,int w,int h) { struct state saved; diff --git a/src/conio/gpu_pointy.h b/src/conio/gpu_pointy.h index 1efd0aff..f46a9fa6 100644 --- a/src/conio/gpu_pointy.h +++ b/src/conio/gpu_pointy.h @@ -7,6 +7,7 @@ bool gpu_pointy_init(void *(*getproc)(const char *)); bool gpu_pointy_scale(const uint32_t *pixels, int w, int h, int width, int height); bool gpu_pointy_present(int width, int height, int window_width, int window_height); bool gpu_pointy_read(uint32_t *pixels, int width, int height); +bool gpu_pointy_frame(int window_width, int window_height, int x, int y, int w, int h, int b, uint32_t rgb); void gpu_pointy_destroy(void); const char *gpu_pointy_error(void); #endif diff --git a/src/conio/sdl_con.c b/src/conio/sdl_con.c index c188dd48..085b4aa5 100644 --- a/src/conio/sdl_con.c +++ b/src/conio/sdl_con.c @@ -998,62 +998,44 @@ ciolib_set_exclusive_border(int px, int attr) static void sdl_picture_size(struct video_stats *vs, int *w, int *h, bool fit) { - int b = sdl_xborder_cur; - int pw, ph, aw, ah; - double f; - - if (b <= 0) { - bitmap_get_scaled_win_size(vs->scaling, w, h, - fit ? vs->winwidth : 0, fit ? vs->winheight : 0); - return; - } - bitmap_get_scaled_win_size(vs->scaling, &pw, &ph, vs->winwidth, vs->winheight); - aw = vs->winwidth - 2 * b; - ah = vs->winheight - 2 * b; - if (aw < 1 || ah < 1 || pw <= 0 || ph <= 0 || (pw <= aw && ph <= ah)) { - *w = pw; - *h = ph; - return; - } - f = fmin((double)aw / pw, (double)ah / ph); - *w = (int)floor(pw * f); - *h = (int)floor(ph * f); - if (*w < 1) - *w = 1; - if (*h < 1) - *h = 1; + /* The frame never resizes the picture: a picture shrunk by a few + * pixels is scaled by a non-integer factor, and Pointy's sharp edges + * are lost (2026-11-12). The frame sits in the margin when there is + * room, else over the picture's outermost pixels (sdl_xborder_rect). */ + bitmap_get_scaled_win_size(vs->scaling, w, h, + fit ? vs->winwidth : 0, fit ? vs->winheight : 0); } -/* Draw the frame round a centred pw x ph picture. Called right after - * RenderClear, so the picture (drawn after) is never under it. */ -static void -sdl_draw_xborder(int winw, int winh, int pw, int ph) +/* Where the frame goes round a centred pw x ph picture: the screen's + * edges in fullscreen; round the picture when the window's margin has room + * for it; else on the picture's own outermost pixels, so the picture keeps + * its exact size. */ +static bool +sdl_xborder_rect(int winw, int winh, int pw, int ph, int *rx, int *ry, int *rw, int *rh) { int b = sdl_xborder_cur; int x, y, w, h; - uint32_t rgb; - Uint8 or, og, ob, oa; - SDL_Rect r[4]; - if (b <= 0 || renderer == NULL || sdl.SetRenderDrawColor == NULL - || sdl.GetRenderDrawColor == NULL || sdl.RenderFillRects == NULL) - return; + if (b <= 0) + return false; if (fullscreen) { - /* Fullscreen: the frame runs round the screen's edges, not - * round the picture -- the picture keeps its place and size - * (sdl_picture_size leaves it room when the letterbox is - * narrower than the frame). */ x = 0; y = 0; w = winw; h = winh; } - else { + else if (winw - pw >= 2 * b && winh - ph >= 2 * b) { x = (winw - pw) / 2 - b; y = (winh - ph) / 2 - b; w = pw + 2 * b; h = ph + 2 * b; } + else { + x = (winw - pw) / 2; + y = (winh - ph) / 2; + w = pw; + h = ph; + } if (x < 0) { w += x; x = 0; @@ -1066,7 +1048,30 @@ sdl_draw_xborder(int winw, int winh, int pw, int ph) w = winw - x; if (y + h > winh) h = winh - y; - if (w <= 0 || h <= 0) + if (w <= 2 * b || h <= 2 * b) + return false; + *rx = x; + *ry = y; + *rw = w; + *rh = h; + return true; +} + +/* Draw the frame with the SDL renderer, AFTER the picture (RenderCopy), so + * it may lie over the picture's edge without the picture being resized. */ +static void +sdl_draw_xborder(int winw, int winh, int pw, int ph) +{ + int b = sdl_xborder_cur; + int x, y, w, h; + uint32_t rgb; + Uint8 or, og, ob, oa; + SDL_Rect r[4]; + + if (renderer == NULL || sdl.SetRenderDrawColor == NULL + || sdl.GetRenderDrawColor == NULL || sdl.RenderFillRects == NULL) + return; + if (!sdl_xborder_rect(winw, winh, pw, ph, &x, &y, &w, &h)) return; r[0] = (SDL_Rect){x, y, w, b}; r[1] = (SDL_Rect){x, y + h - b, w, b}; @@ -1828,11 +1833,13 @@ void sdl_video_event_thread(void *data) if (sdl.GetRendererInfo && sdl.RenderFlush && sdl.GL_GetProcAddress && sdl.GetRendererInfo(renderer,&info)==0 && strcmp(info.name,"opengl")==0) { sdl.RenderClear(renderer); - sdl_draw_xborder(cvstat.winwidth, cvstat.winheight, dst.w, dst.h); if (sdl.RenderFlush(renderer)==0) { + int fx, fy, fw, fh; ok=gpu_pointy_init(sdl.GL_GetProcAddress) && gpu_pointy_scale(list->data,sw,sh,dst.w,dst.h) && gpu_pointy_present(dst.w,dst.h,cvstat.winwidth,cvstat.winheight); + if (ok && sdl_xborder_rect(cvstat.winwidth, cvstat.winheight, dst.w, dst.h, &fx, &fy, &fw, &fh)) + ok=gpu_pointy_frame(cvstat.winwidth, cvstat.winheight, fx, fy, fw, fh, sdl_xborder_cur, bitmap_attr_rgb(sdl_xborder_attr)); error=gpu_pointy_error(); } } @@ -1864,7 +1871,6 @@ void sdl_video_event_thread(void *data) if (sdl.QueryTexture(texture, NULL, NULL, &tw, &th) != 0) fprintf(stderr, "Unable to query texture (%s)\n", sdl.GetError()); sdl.RenderClear(renderer); - sdl_draw_xborder(cvstat.winwidth, cvstat.winheight, gb->w, gb->h); if (sdl.LockTexture(texture, &src, &pixels, &pitch) != 0) fprintf(stderr, "Unable to lock texture (%s)\n", sdl.GetError()); if (pitch != gb->w * sizeof(gb->data[0])) { @@ -1919,7 +1925,6 @@ void sdl_video_event_thread(void *data) if (src.h > th) src.h = th; sdl.RenderClear(renderer); - sdl_draw_xborder(cvstat.winwidth, cvstat.winheight, dst.w, dst.h); if (sdl.LockTexture(texture, &src, &pixels, &pitch) != 0) fprintf(stderr, "Unable to lock texture (%s)\n", sdl.GetError()); if (ts > 1) { @@ -1979,6 +1984,7 @@ void sdl_video_event_thread(void *data) } if (sdl.RenderCopy(renderer, texture, &src, &dst)) fprintf(stderr, "RenderCopy() failed! (%s)\n", sdl.GetError()); + sdl_draw_xborder(cvstat.winwidth, cvstat.winheight, dst.w, dst.h); sdl.RenderPresent(renderer); } bitmap_drv_free_rect(list); -- 2.47.3