aboutsummaryrefslogtreecommitdiffstats
path: root/examples/opengl/contextinfo/contextinfo.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/contextinfo/contextinfo.py')
-rw-r--r--examples/opengl/contextinfo/contextinfo.py68
1 files changed, 18 insertions, 50 deletions
diff --git a/examples/opengl/contextinfo/contextinfo.py b/examples/opengl/contextinfo/contextinfo.py
index 73b55df13..311d5b765 100644
--- a/examples/opengl/contextinfo/contextinfo.py
+++ b/examples/opengl/contextinfo/contextinfo.py
@@ -1,43 +1,5 @@
-
-#############################################################################
-##
-## Copyright (C) 2017 The Qt Company Ltd.
-## Contact: http://www.qt.io/licensing/
-##
-## This file is part of the Qt for Python examples of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## You may use this file under the terms of the BSD license as follows:
-##
-## "Redistribution and use in source and binary forms, with or without
-## modification, are permitted provided that the following conditions are
-## met:
-## * Redistributions of source code must retain the above copyright
-## notice, this list of conditions and the following disclaimer.
-## * Redistributions in binary form must reproduce the above copyright
-## notice, this list of conditions and the following disclaimer in
-## the documentation and/or other materials provided with the
-## distribution.
-## * Neither the name of The Qt Company Ltd nor the names of its
-## contributors may be used to endorse or promote products derived
-## from this software without specific prior written permission.
-##
-##
-## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
"""PySide6 port of the opengl/contextinfo example from Qt v5.x"""
@@ -47,20 +9,20 @@ import sys
from textwrap import dedent
-from PySide6.QtCore import QCoreApplication, QLibraryInfo, QSize, QTimer, Qt
+from PySide6.QtCore import (QCoreApplication, QLibraryInfo, QSize, QTimer, Qt,
+ Slot)
from PySide6.QtGui import (QMatrix4x4, QOpenGLContext, QSurfaceFormat, QWindow)
from PySide6.QtOpenGL import (QOpenGLBuffer, QOpenGLShader,
QOpenGLShaderProgram, QOpenGLVertexArrayObject)
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QMessageBox, QPlainTextEdit,
- QWidget)
+ QWidget)
from PySide6.support import VoidPtr
try:
from OpenGL import GL
except ImportError:
app = QApplication(sys.argv)
message_box = QMessageBox(QMessageBox.Critical, "ContextInfo",
- "PyOpenGL must be installed to run this example.",
- QMessageBox.Close)
+ "PyOpenGL must be installed to run this example.", QMessageBox.Close)
message_box.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate")
message_box.exec()
sys.exit(1)
@@ -111,7 +73,10 @@ colors = numpy.array([1, 0, 0, 0, 1, 0, 0, 0, 1], dtype=numpy.float32)
def print_surface_format(surface_format):
- profile_name = 'core' if surface_format.profile() == QSurfaceFormat.CoreProfile else 'compatibility'
+ if surface_format.profile() == QSurfaceFormat.CoreProfile:
+ profile_name = 'core'
+ else:
+ profile_name = 'compatibility'
major = surface_format.majorVersion()
minor = surface_format.minorVersion()
return f"{profile_name} version {major}.{minor}"
@@ -141,11 +106,13 @@ class RenderWindow(QWindow):
# concept 3.2+ has. This may still fail since version 150 (3.2) is
# specified in the sources but it's worth a try.
if (fmt.renderableType() == QSurfaceFormat.OpenGL and fmt.majorVersion() == 3
- and fmt.minorVersion() <= 1):
+ and fmt.minorVersion() <= 1):
use_new_style_shader = not fmt.testOption(QSurfaceFormat.DeprecatedFunctions)
vertex_shader = vertex_shader_source if use_new_style_shader else vertex_shader_source_110
- fragment_shader = fragment_shader_source if use_new_style_shader else fragment_shader_source_110
+ fragment_shader = (fragment_shader_source
+ if use_new_style_shader
+ else fragment_shader_source_110)
if not self.program.addShaderFromSourceCode(QOpenGLShader.Vertex, vertex_shader):
log = self.program.log()
raise Exception("Vertex shader could not be added: {log} ({vertexShader})")
@@ -170,9 +137,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()
@@ -230,6 +197,7 @@ class RenderWindow(QWindow):
self.context.swapBuffers(self)
self.context.doneCurrent()
+ @Slot()
def slot_timer(self):
self.render()
self.angle += 1