Debian Codegraph @

src/delphi/castleinternalfmxutils_windows.inc

raw
1 {%MainUnit castleinternalfmxutils.pas}
2 {
3 Copyright 2023-2023 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 { Implementation of CastleInternalFmxUtils (initialize OpenGL context in FMX,
18 code shared between FMX TOpenGLControl and FMX TCastleControl)
19 for Windows. }
20
21 uses
22 Windows, SysUtils,
23 CastleInternalContextWgl,
24 CastleLog, CastleUtils;
25
26 { TFmxOpenGLUtility --------------------------------------------------------- }
27
28 procedure TFmxOpenGLUtility.ContextAdjustEarly(const PlatformContext: TGLContext);
29 var
30 WinContext: TGLContextWgl;
31 begin
32 WinContext := PlatformContext as TGLContextWgl;
33 WinContext.WndPtr :=
34 (Control.Presentation as TWinPresentation).Handle;
35 if WinContext.WndPtr = 0 then
36 raise Exception.Create('Native handle not ready when calling ContextAdjustEarly');
37 WinContext.h_Dc := GetWindowDC(WinContext.WndPtr);
38 end;
39
40 procedure TFmxOpenGLUtility.HandleNeeded;
41 var
42 H: HWND;
43 begin
44 if Control.Presentation = nil then
45 raise EInternalError.CreateFmt('%s: Cannot use ControlHandleNeeded as Presentation not created yet', [Control.ClassName]);
46 H := (Control.Presentation as TWinPresentation).Handle;
47 if H = 0 { NullHWnd } then
48 raise Exception.CreateFmt('%s: ControlHandleNeeded failed to create a handle', [Control.ClassName]);
49 end;
50
51 procedure TFmxOpenGLUtility.HandleRelease;
52 begin
53 end;
54
55 procedure TFmxOpenGLUtility.Update;
56 begin
57 end;
58
59 function TFmxOpenGLUtility.Scale: Single;
60 begin
61 // this may be called at units finalization, when Handle is no longer available
62 if Control.Presentation <> nil then
63 Result := (Control.Presentation as TWinPresentation).Scale
64 else
65 Result := 1;
66 end;