Skip to content

Commit 222c3ef

Browse files
committed
Simplify VAO class
It should only be responsible for bulding and providing wrappers for render methods. instance() is now publicly available.
1 parent 6225424 commit 222c3ef

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

demosys/opengl/vao.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,41 @@ def __init__(self, name, mode=moderngl.TRIANGLES):
102102
self.vertex_count = 0
103103
self.vaos = {}
104104

105-
def draw(self, program: moderngl.Program, mode=None, vertices=-1, first=0, instances=1):
105+
def render(self, program: moderngl.Program, mode=None, vertices=-1, first=0, instances=1):
106106
"""
107-
Draw the VAO.
108-
Will use ``glDrawElements`` if an element buffer is present
109-
and ``glDrawArrays`` if no element array is present.
107+
Render the VAO.
110108
111109
:param program: The program to draw with
112110
:param mode: Override the draw mode (TRIANGLES etc)
113111
:param vertices: The number of vertices to transform
114112
:param first: The index of the first vertex to start with
115113
:param instances: The number of instances
116114
"""
117-
vao = self._create_vao_instance(program)
115+
vao = self.instance(program)
118116

119117
if mode is None:
120118
mode = self.mode
121119

122120
vao.render(mode, vertices=vertices, first=first, instances=instances)
123121

122+
def render_indirect(self, program, buffer, mode=None, count=-1, *, first=0):
123+
"""
124+
The render primitive (mode) must be the same as the input primitive of the GeometryShader.
125+
The draw commands are 5 integers: (count, instanceCount, firstIndex, baseVertex, baseInstance).
126+
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.
132+
"""
133+
vao = self.instance(program)
134+
135+
if mode is None:
136+
mode = self.mode
137+
138+
vao.render_indirect(buffer, mode=mode, count=count, first=first)
139+
124140
def transform(self, program: moderngl.Program, buffer: moderngl.Buffer,
125141
mode=None, vertices=-1, first=0, instances=1):
126142
"""
@@ -133,18 +149,13 @@ def transform(self, program: moderngl.Program, buffer: moderngl.Buffer,
133149
:param first: The index of the first vertex to start with
134150
:param instances: The number of instances
135151
"""
136-
vao = self._create_vao_instance(program)
152+
vao = self.instance(program)
137153

138154
if mode is None:
139155
mode = self.mode
140156

141157
vao.transform(buffer, mode=mode, vertices=vertices, first=first, instances=instances)
142158

143-
def subroutines(self, shader, routines: tuple):
144-
"""Set the active subroutines"""
145-
vao = self._create_vao_instance(shader)
146-
vao.subroutines = (r.index for r in routines)
147-
148159
def buffer(self, buffer, buffer_format: str, attribute_names, per_instance=False):
149160
"""
150161
Register a buffer/vbo for the VAO. This can be called multiple times.
@@ -194,7 +205,12 @@ def index_buffer(self, buffer, index_element_size=4):
194205
self._index_buffer = buffer
195206
self._index_element_size = index_element_size
196207

197-
def _create_vao_instance(self, program: moderngl.Program):
208+
def instance(self, program: moderngl.Program):
209+
"""
210+
Obtain the moderngl.VertexArray instance for the program
211+
212+
:return: moderngl.VertexArray
213+
"""
198214
vao = self.vaos.get(program.glo)
199215
if vao:
200216
return vao

0 commit comments

Comments
 (0)