Debian Codegraph @

src/window/unix/castlewindow_glx.inc

raw
1 {%MainUnit ../castlewindow.pas}
2 {
3 Copyright 2001-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 { Use this from castlewindow_xlib.inc to make a CastleWindow backend
18 using Xlib and glX (initialize window on X, without any toolkit,
19 with OpenGL context). }
20
21 {$ifdef read_interface_uses}
22 CastleInternalContextGlx,
23 {$endif}
24
25 {$ifdef read_window_interface}
26 private
27 Context: TGLContextGlx;
28
29 // Initialized by ContextCreateEarly, freed by ContextDestroyLate
30 XVisual: PXVisualInfo;
31
32 procedure ContextCreateEarly;
33 procedure ContextCreate;
34 procedure ContextDestroy;
35 procedure ContextDestroyLate;
36 { @groupEnd }
37 {$endif}
38
39 {$ifdef read_implementation}
40
41 procedure TCastleWindow.ContextCreateEarly;
42 begin
43 Context := TGLContextGlx.Create;
44 { All backends that can use glX (this means now Xlib and GTK)
45 must define Application.XDisplay / XScreen. }
46 Context.XDisplay := Application.XDisplay;
47 Context.XScreen := Application.XScreen;
48 Context.InitializeEarly(FRequirements);
49 XVisual := Context.XVisual;
50 end;
51
52 procedure TCastleWindow.ContextCreate;
53 begin
54 Assert(Context <> nil);
55 Context.Initialize(FRequirements);
56 end;
57
58 procedure TCastleWindow.ContextDestroy;
59 begin
60 if Context <> nil then
61 begin
62 Context.Finalize;
63 // FreeAndNil(Context); // leave it for ContextDestroyLate
64 end;
65 end;
66
67 procedure TCastleWindow.ContextDestroyLate;
68 begin
69 if Context <> nil then
70 begin
71 Context.FinalizeLate;
72 FreeAndNil(Context);
73 end;
74 end;
75
76 procedure TCastleWindow.BackendMakeCurrent;
77 begin
78 Assert(not Closed);
79 Assert(Context <> nil);
80 Context.WindowXID := WindowXID;
81 Context.MakeCurrent;
82 end;
83
84 procedure TCastleWindow.SwapBuffers;
85 begin
86 Assert(not Closed);
87 Assert(Context <> nil);
88 Context.WindowXID := WindowXID;
89 Context.SwapBuffers;
90 end;
91
92 {$endif read_implementation}