aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/opengl/contextinfo/contextinfo.py6
-rw-r--r--examples/opengl/hellogl2/hellogl2.py41
-rw-r--r--sources/pyside6/PySide6/QtOpenGL/typesystem_opengl.xml9
-rw-r--r--sources/pyside6/PySide6/glue/qtopengl.cpp9
4 files changed, 39 insertions, 26 deletions
diff --git a/examples/opengl/contextinfo/contextinfo.py b/examples/opengl/contextinfo/contextinfo.py
index 5ca7ecb26..37c5f5d43 100644
--- a/examples/opengl/contextinfo/contextinfo.py
+++ b/examples/opengl/contextinfo/contextinfo.py
@@ -133,9 +133,9 @@ class RenderWindow(QWindow):
self.vbo.write(vertices_size, VoidPtr(self._colors_data), colors_size)
self.vbo.release()
- vao_binder = QOpenGLVertexArrayObject.Binder(self.vao)
- if self.vao.isCreated(): # have VAO support, use it
- self.setup_vertex_attribs()
+ with QOpenGLVertexArrayObject.Binder(self.vao):
+ if self.vao.isCreated(): # have VAO support, use it
+ self.setup_vertex_attribs()
def setup_vertex_attribs(self):
self.vbo.bind()
diff --git a/examples/opengl/hellogl2/hellogl2.py b/examples/opengl/hellogl2/hellogl2.py
index 7ea3b7ad3..e66177e04 100644
--- a/examples/opengl/hellogl2/hellogl2.py
+++ b/examples/opengl/hellogl2/hellogl2.py
@@ -343,21 +343,19 @@ class GLWidget(QOpenGLWidget, QOpenGLFunctions):
self._light_pos_loc = self.program.uniformLocation("lightPos")
self.vao.create()
- vao_binder = QOpenGLVertexArrayObject.Binder(self.vao)
+ with QOpenGLVertexArrayObject.Binder(self.vao):
+ self._logo_vbo.create()
+ self._logo_vbo.bind()
+ float_size = ctypes.sizeof(ctypes.c_float)
+ self._logo_vbo.allocate(self.logo.const_data(), self.logo.count() * float_size)
- self._logo_vbo.create()
- self._logo_vbo.bind()
- float_size = ctypes.sizeof(ctypes.c_float)
- self._logo_vbo.allocate(self.logo.const_data(), self.logo.count() * float_size)
-
- self.setup_vertex_attribs()
+ self.setup_vertex_attribs()
- self.camera.setToIdentity()
- self.camera.translate(0, 0, -1)
+ self.camera.setToIdentity()
+ self.camera.translate(0, 0, -1)
- self.program.setUniformValue(self._light_pos_loc, QVector3D(0, 0, 70))
- self.program.release()
- vao_binder = None
+ self.program.setUniformValue(self._light_pos_loc, QVector3D(0, 0, 70))
+ self.program.release()
def setup_vertex_attribs(self):
self._logo_vbo.bind()
@@ -382,16 +380,15 @@ class GLWidget(QOpenGLWidget, QOpenGLFunctions):
self.world.rotate(self._y_rot / 16, 0, 1, 0)
self.world.rotate(self._z_rot / 16, 0, 0, 1)
- vao_binder = QOpenGLVertexArrayObject.Binder(self.vao)
- self.program.bind()
- self.program.setUniformValue(self._proj_matrix_loc, self.proj)
- self.program.setUniformValue(self._mv_matrix_loc, self.camera * self.world)
- normal_matrix = self.world.normalMatrix()
- self.program.setUniformValue(self._normal_matrix_loc, normal_matrix)
-
- self.glDrawArrays(GL.GL_TRIANGLES, 0, self.logo.vertex_count())
- self.program.release()
- vao_binder = None
+ with QOpenGLVertexArrayObject.Binder(self.vao):
+ self.program.bind()
+ self.program.setUniformValue(self._proj_matrix_loc, self.proj)
+ self.program.setUniformValue(self._mv_matrix_loc, self.camera * self.world)
+ normal_matrix = self.world.normalMatrix()
+ self.program.setUniformValue(self._normal_matrix_loc, normal_matrix)
+
+ self.glDrawArrays(GL.GL_TRIANGLES, 0, self.logo.vertex_count())
+ self.program.release()
def resizeGL(self, width, height):
self.proj.setToIdentity()
diff --git a/sources/pyside6/PySide6/QtOpenGL/typesystem_opengl.xml b/sources/pyside6/PySide6/QtOpenGL/typesystem_opengl.xml
index 166f81765..12dc36a69 100644
--- a/sources/pyside6/PySide6/QtOpenGL/typesystem_opengl.xml
+++ b/sources/pyside6/PySide6/QtOpenGL/typesystem_opengl.xml
@@ -678,7 +678,14 @@
</object-type>
<value-type name="QOpenGLVersionProfile" since="5.1"/>
<object-type name="QOpenGLVertexArrayObject">
- <object-type name="Binder"/>
+ <object-type name="Binder">
+ <add-function signature="__enter__()" return-type="QOpenGLVertexArrayObject::Binder">
+ <inject-code file="../glue/qtopengl.cpp" snippet="vao-binder-enter"/>
+ </add-function>
+ <add-function signature="__exit__(PyObject*,PyObject*,PyObject*)">
+ <inject-code file="../glue/qtopengl.cpp" snippet="vao-binder-exit"/>
+ </add-function>
+ </object-type>
</object-type>
<suppress-warning text="^There's no user provided way.*QOpenGLFunctions_\d_\d.*::glIndex.*$"/>
diff --git a/sources/pyside6/PySide6/glue/qtopengl.cpp b/sources/pyside6/PySide6/glue/qtopengl.cpp
index 5d318deaf..cdfaafb3b 100644
--- a/sources/pyside6/PySide6/glue/qtopengl.cpp
+++ b/sources/pyside6/PySide6/glue/qtopengl.cpp
@@ -78,3 +78,12 @@ int glGetVReturnSize(GLenum pname);
// @snippet glgeti-vreturnsize_declaration
int glGetI_VReturnSize(GLenum pname);
// @snippet glgeti-vreturnsize_declaration
+
+// @snippet vao-binder-enter
+Py_INCREF(%PYSELF);
+pyResult = %PYSELF;
+// @snippet vao-binder-enter
+
+// @snippet vao-binder-exit
+%CPPSELF.release();
+// @snippet vao-binder-exit