Skip to content

Commit 394fcde

Browse files
committed
Clean up VAO docstrings
1 parent 01f285c commit 394fcde

File tree

2 files changed

+75
-32
lines changed

2 files changed

+75
-32
lines changed

demosys/opengl/vao.py

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,29 @@ def has_attribute(self, name):
7676
class VAO:
7777
"""
7878
Represents a vertex array object.
79-
A name must be provided for debug puporses.
80-
The default draw mode is ``moderngl.TRIANGLES``
79+
This is a wrapper class over ``moderngl.VertexArray`` to provide helper method.
80+
81+
The main purpose is to provide render methods taking a program as parameter.
82+
The class will auto detect the programs attributes and add padding when needed
83+
to match the vertex object.
84+
A new vertexbuffer object is created and stored internally for each unique
85+
shader program used.
86+
87+
A secondary purpose is to provide an alternate way to build vertexbuffers
88+
This can be practical when loading or creating various geometry.
89+
90+
There is no requirements to use this class, but most methods in the
91+
system creating vertexbuffers will return this type. You can obtain
92+
a single vertexbuffer instance by calling :py:meth:`VAO.instance`
93+
method if you prefer to work directly on moderngl instances.
8194
"""
82-
def __init__(self, name, mode=moderngl.TRIANGLES):
95+
def __init__(self, name="", mode=moderngl.TRIANGLES):
8396
"""
8497
Create and empty VAO
8598
86-
:param name: The name for debug purposes
87-
:param mode: Default draw mode for this VAO
99+
Keyword Args:
100+
name (str): The name for debug purposes
101+
mode (int): Default draw mode
88102
"""
89103
self.ctx = context.ctx()
90104
self.name = name
@@ -106,11 +120,14 @@ def render(self, program: moderngl.Program, mode=None, vertices=-1, first=0, ins
106120
"""
107121
Render the VAO.
108122
109-
:param program: The program to draw with
110-
:param mode: Override the draw mode (TRIANGLES etc)
111-
:param vertices: The number of vertices to transform
112-
:param first: The index of the first vertex to start with
113-
:param instances: The number of instances
123+
Args:
124+
program: The ``moderngl.Program``
125+
126+
Keyword Args:
127+
mode: Override the draw mode (``TRIANGLES`` etc)
128+
vertices (int): The number of vertices to transform
129+
first (int): The index of the first vertex to start with
130+
instances (int): The number of instances
114131
"""
115132
vao = self.instance(program)
116133

@@ -124,11 +141,14 @@ def render_indirect(self, program: moderngl.Program, buffer, mode=None, count=-1
124141
The render primitive (mode) must be the same as the input primitive of the GeometryShader.
125142
The draw commands are 5 integers: (count, instanceCount, firstIndex, baseVertex, baseInstance).
126143
127-
:param program: (Buffer) Indirect drawing commands.
128-
:param buffer: (Buffer) Indirect drawing commands.
129-
:param mode: (int) By default :py:data:`TRIANGLES` will be used.
130-
:param count: (int) The number of draws.
131-
:param first: (int) The index of the first indirect draw command.
144+
Args:
145+
program: The ``moderngl.Program``
146+
buffer: The ``moderngl.Buffer`` containing indirect draw commands
147+
148+
Keyword Args:
149+
mode (int): By default :py:data:`TRIANGLES` will be used.
150+
count (int): The number of draws.
151+
first (int): The index of the first indirect draw command.
132152
"""
133153
vao = self.instance(program)
134154

@@ -142,12 +162,15 @@ def transform(self, program: moderngl.Program, buffer: moderngl.Buffer,
142162
"""
143163
Transform vertices. Stores the output in a single buffer.
144164
145-
:param program: The program
146-
:param buffer: The buffer to store the output
147-
:param mode: Draw mode (for example `POINTS`
148-
:param vertices: The number of vertices to transform
149-
:param first: The index of the first vertex to start with
150-
:param instances: The number of instances
165+
Args:
166+
program: The ``moderngl.Program``
167+
buffer: The ``moderngl.buffer`` to store the output
168+
169+
Keyword Args:
170+
mode: Draw mode (for example ``moderngl.POINTS``)
171+
vertices (int): The number of vertices to transform
172+
first (int): The index of the first vertex to start with
173+
instances (int): The number of instances
151174
"""
152175
vao = self.instance(program)
153176

@@ -161,9 +184,15 @@ def buffer(self, buffer, buffer_format: str, attribute_names, per_instance=False
161184
Register a buffer/vbo for the VAO. This can be called multiple times.
162185
adding multiple buffers (interleaved or not)
163186
164-
:param buffer: The buffer object. Can be ndarray or Buffer
165-
:param buffer_format: The format of the buffer ('f', 'u', 'i')
166-
:returns: The buffer object
187+
Args:
188+
buffer: The buffer data. Can be ``numpy.array``, ``moderngl.Buffer`` or ``bytes``.
189+
buffer_format (str): The format of the buffer. (eg. ``3f 3f`` for interleaved positions and normals).
190+
attribute_names: A list of attribute names this buffer should map to.
191+
192+
Keyword Args:
193+
per_instance (bool): Is this buffer per instance data for instanced rendering?
194+
195+
Returns: The ``moderngl.Buffer`` instance object. This is handy when providing ``bytes`` and ``numpy.array``.
167196
"""
168197
if not isinstance(attribute_names, list):
169198
attribute_names = [attribute_names, ]
@@ -190,8 +219,11 @@ def index_buffer(self, buffer, index_element_size=4):
190219
"""
191220
Set the index buffer for this VAO
192221
193-
:param buffer: Buffer object or ndarray
194-
:param index_element_size: Byte size of each element. 1, 2 or 4
222+
Args:
223+
buffer: ``moderngl.Buffer``, ``numpy.array`` or ``bytes``
224+
225+
Keyword Args:
226+
index_element_size (int): Byte size of each element. 1, 2 or 4
195227
"""
196228
if not type(buffer) in [moderngl.Buffer, numpy.ndarray, bytes]:
197229
raise VAOError("buffer parameter must be a moderngl.Buffer, numpy.ndarray or bytes instance")
@@ -207,9 +239,10 @@ def index_buffer(self, buffer, index_element_size=4):
207239

208240
def instance(self, program: moderngl.Program) -> moderngl.VertexArray:
209241
"""
210-
Obtain the moderngl.VertexArray instance for the program
242+
Obtain the ``moderngl.VertexArray`` instance for the program.
243+
The instance is only created once and cached internally.
211244
212-
:return: moderngl.VertexArray
245+
Returns: ``moderngl.VertexArray`` instance
213246
"""
214247
vao = self.vaos.get(program.glo)
215248
if vao:
@@ -258,7 +291,8 @@ def release(self, buffer=True):
258291
"""
259292
Destroy the vao object
260293
261-
:param buffers: (bool) also release buffers
294+
Keyword Args:
295+
buffers (bool): also release buffers
262296
"""
263297
for key, vao in self.vaos:
264298
vao.release()

docs/reference/vao.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ VAO
66
77
.. autoclass:: VAO
88

9-
Methods
10-
-------
9+
Create
10+
------
1111

12+
.. automethod:: VAO.__init__
1213
.. automethod:: VAO.buffer(buffer, buffer_format:str, attribute_names, per_instance=False)
1314
.. automethod:: VAO.index_buffer(buffer, index_element_size=4)
14-
.. automethod:: VAO.instance(program:Program) -> VertexArray
15+
16+
Render Methods
17+
--------------
18+
1519
.. automethod:: VAO.render(program:Program, mode=None, vertices=-1, first=0, instances=1)
1620
.. automethod:: VAO.render_indirect(program:Program, buffer, mode=None, count=-1, first=0)
1721
.. automethod:: VAO.transform(program:Program, buffer:Buffer, mode=None, vertices=-1, first=0, instances=1)
22+
23+
Other Methods
24+
-------------
25+
26+
.. automethod:: VAO.instance(program:Program) -> VertexArray
1827
.. automethod:: VAO.release(buffer=True)

0 commit comments

Comments
 (0)