66
77
88class Window (BaseWindow ):
9-
9+ """
10+ Headless window using a standalone ``moderngl.Context``.
11+ """
1012 def __init__ (self ):
13+ """
14+ Creates a standalone ``moderngl.Context``.
15+ The headless window currently have no event input from keyboard or mouse.
16+
17+ Using this window require either ``settings`` values to be present:
18+
19+ * ``HEADLESS_FRAMES``: How many frames should be rendered before closing the window
20+ * ``HEADLESS_DURATION``: How many seconds rendering should last before the window closes
21+
22+ """
1123 super ().__init__ ()
1224
1325 self .headless_frames = getattr (settings , 'HEADLESS_FRAMES' , 0 )
@@ -29,31 +41,47 @@ def __init__(self):
2941 self .fbo .use ()
3042
3143 def draw (self , current_time , frame_time ):
44+ """
45+ Calls the superclass ``draw()`` methods and checks ``HEADLESS_FRAMES``/``HEADLESS_DURATION``
46+ """
3247 super ().draw (current_time , frame_time )
3348
3449 if self .headless_duration and current_time >= self .headless_duration :
3550 self .close ()
3651
3752 def use (self ):
53+ """
54+ Binds the framebuffer representing this window
55+ """
3856 self .fbo .use ()
3957
40- def should_close (self ):
58+ def should_close (self ) -> bool :
59+ """Checks if the internal close state is set"""
4160 return self ._close
4261
4362 def close (self ):
63+ """Sets the internal close state"""
4464 self ._close = True
4565
4666 def resize (self , width , height ):
67+ """
68+ Resizing is not supported by the headless window.
69+ We simply override with an empty method.
70+ """
4771 pass
4872
4973 def swap_buffers (self ):
74+ """
75+ Headless window currently don't support double buffering.
76+ We only increment the frame counter here.
77+ """
5078 self .frames += 1
5179
5280 if self .headless_frames and self .frames >= self .headless_frames :
5381 self .close ()
5482
5583 def terminate (self ):
84+ """
85+ No teardown is needed. We override with an empty method
86+ """
5687 pass
57-
58- def mgl_fbo (self ):
59- return self .screenbuffer .mglo
0 commit comments