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;