mirror of
https://git.vladimir.cc/vladimir/lazopenglcontextex.git
synced 2026-08-25 17:37:31 +00:00
feat: TCustomOpenGLControl.PixelScale — devicePixelRatio для HiDPI
LOpenGLPixelScale в Qt-бэкенде (QLCLGLWidget_devicePixelRatioF), на прочих бэкендах возвращает 1.0. Нужен коду с явными glViewport и текстурами в физических пикселях. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+14
-5
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user