Skip to content

Commit af5e167

Browse files
committed
Docs: Headless window
1 parent cb82c66 commit af5e167

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

demosys/context/headless.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,20 @@
66

77

88
class 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
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
.. py:module:: demosys.context.headless
3+
.. py:currentmodule:: demosys.context.headless
4+
5+
demosys.context.headless.Window
6+
===============================
7+
8+
.. autodata:: Window
9+
:annotation:
10+
11+
Methods
12+
-------
13+
14+
.. automethod:: Window.__init__
15+
.. automethod:: Window.draw
16+
.. automethod:: Window.use
17+
.. automethod:: Window.should_close
18+
.. automethod:: Window.close
19+
.. automethod:: Window.resize
20+
.. automethod:: Window.swap_buffers
21+
.. automethod:: Window.terminate
22+
23+
Attributes
24+
----------

docs/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Reference
1717
demosys.timers.vlc
1818
demosys.context.base
1919
demosys.context.glfw
20+
demosys.context.headless

0 commit comments

Comments
 (0)