diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-10-06 08:04:30 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-10-14 12:19:06 +0200 |
commit | 63d31a37577474ba722f836e751c7e1f9113c1b7 (patch) | |
tree | 8c5717496f0fb78c9613197089990772a0f1c670 /examples/opengl/hellogl2/hellogl2.py | |
parent | a68fb1816d3fa67b322bb30f6bdd5347a149aaea (diff) |
Add a context manager for QOpenGLVertexArrayObject.Binder
[ChangeLog][PySide6] A context manager for QOpenGLVertexArrayObject.Binder
has been added.
Pick-to: 6.4
Change-Id: Ic839ed87f17f99c33b88d7fc5a0dd4842a4c7560
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'examples/opengl/hellogl2/hellogl2.py')
-rw-r--r-- | examples/opengl/hellogl2/hellogl2.py | 41 |
1 files changed, 19 insertions, 22 deletions
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() |