Skip to content

Commit 26dae41

Browse files
committed
Support using VAO binding context manager
1 parent 96412b1 commit 26dae41

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

demosys/opengl/vao.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ def __init__(self, name, mode=GL.GL_TRIANGLES):
8080
self.vertex_count = 0
8181
self.combos = {}
8282

83+
self.bind_context = VAOBindContext(self)
84+
8385
def bind(self, shader):
8486
shader.bind()
8587
combo = self.generate_vao_combo(shader)
8688
combo.bind()
89+
# Return context manager
90+
self.bind_context.shader = shader
91+
return self.bind_context
8792

8893
def draw(self, mode=None):
8994
"""
@@ -202,3 +207,16 @@ def generate_vao_combo(self, shader):
202207
self.combos[shader.attribute_key] = combo
203208
GL.glBindVertexArray(0)
204209
return combo
210+
211+
212+
class VAOBindContext:
213+
"""Context managers for bound VAOs"""
214+
def __init__(self, vao):
215+
self.vao = vao
216+
self.shader = None
217+
218+
def __enter__(self):
219+
return self.shader
220+
221+
def __exit__(self, exc_type, exc_val, exc_tb):
222+
pass

0 commit comments

Comments
 (0)