From dd9717b982d681063e8069691c863dc256e05d1c Mon Sep 17 00:00:00 2001 From: Uladzimir Date: Sat, 4 Jul 2026 16:12:11 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20TCustomOpenGLControl.PixelScale=20?= =?UTF-8?q?=E2=80=94=20devicePixelRatio=20=D0=B4=D0=BB=D1=8F=20HiDPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LOpenGLPixelScale в Qt-бэкенде (QLCLGLWidget_devicePixelRatioF), на прочих бэкендах возвращает 1.0. Нужен коду с явными glViewport и текстурами в физических пикселях. Co-Authored-By: Claude Fable 5 --- glqtnativecontext.pas | 19 ++++++++++++++----- openglcontextex.pas | 12 ++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/glqtnativecontext.pas b/glqtnativecontext.pas index 921e5e2..122907d 100644 --- a/glqtnativecontext.pas +++ b/glqtnativecontext.pas @@ -57,6 +57,7 @@ uses qtwidgets, qtint; procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer); +function LOpenGLPixelScale(Handle: HWND): Double; procedure LOpenGLSwapBuffers(Handle: HWND); function LOpenGLMakeCurrent(Handle: HWND): boolean; function LOpenGLReleaseContext(Handle: HWND): boolean; @@ -250,17 +251,25 @@ begin end; end; -procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer); +// devicePixelRatio виджета (1.0 если недоступен) — для явных glViewport +// в пользовательском коде и текстур в физических пикселях. +function LOpenGLPixelScale(Handle: HWND): Double; var Widget: TQtGLWidget; - Dpr: Double; begin - Dpr := 1.0; + Result := 1.0; if (Handle <> 0) and Assigned(QLCLGLWidget_devicePixelRatioF) then begin Widget := TQtGLWidget(Handle); - Dpr := QLCLGLWidget_devicePixelRatioF(Widget.Widget); - if Dpr <= 0 then Dpr := 1.0; + Result := QLCLGLWidget_devicePixelRatioF(Widget.Widget); + if Result <= 0 then Result := 1.0; end; +end; + +procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer); +var + Dpr: Double; +begin + Dpr := LOpenGLPixelScale(Handle); glViewport(Round(Left*Dpr), Round(Top*Dpr), Round(Width*Dpr), Round(Height*Dpr)); end; diff --git a/openglcontextex.pas b/openglcontextex.pas index cfaab01..854c3de 100644 --- a/openglcontextex.pas +++ b/openglcontextex.pas @@ -166,6 +166,9 @@ type procedure SwapBuffers; virtual; function MakeCurrent(SaveOldToStack: boolean = false): boolean; virtual; function ReleaseContext: boolean; virtual; + // devicePixelRatio фреймбуфера (HiDPI). 1.0 на бэкендах без поддержки. + // Явные glViewport/текстуры в пользовательском коде должны умножать на него. + function PixelScale: Double; function RestoreOldOpenGLControl: boolean; function SharingControlCount: integer; property SharingControls[Index: integer]: TCustomOpenGLControl read GetSharingControls; @@ -643,6 +646,15 @@ begin Result:=LOpenGLReleaseContext(Handle); end; +function TCustomOpenGLControl.PixelScale: Double; +begin + Result:=1.0; + {$IFDEF UseQtNative} + if HandleAllocated then + Result:=LOpenGLPixelScale(Handle); + {$ENDIF} +end; + function TCustomOpenGLControl.RestoreOldOpenGLControl: boolean; var RestoredControl: TCustomOpenGLControl;