aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtOpenGL
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/QtOpenGL')
-rw-r--r--sources/pyside6/tests/QtOpenGL/CMakeLists.txt2
-rw-r--r--sources/pyside6/tests/QtOpenGL/QtOpenGL.pyproject4
-rw-r--r--sources/pyside6/tests/QtOpenGL/qopenglbuffer_test.py78
-rw-r--r--sources/pyside6/tests/QtOpenGL/qopenglwindow_test.py97
4 files changed, 181 insertions, 0 deletions
diff --git a/sources/pyside6/tests/QtOpenGL/CMakeLists.txt b/sources/pyside6/tests/QtOpenGL/CMakeLists.txt
new file mode 100644
index 000000000..92b4afbac
--- /dev/null
+++ b/sources/pyside6/tests/QtOpenGL/CMakeLists.txt
@@ -0,0 +1,2 @@
+PYSIDE_TEST(qopenglbuffer_test.py)
+PYSIDE_TEST(qopenglwindow_test.py)
diff --git a/sources/pyside6/tests/QtOpenGL/QtOpenGL.pyproject b/sources/pyside6/tests/QtOpenGL/QtOpenGL.pyproject
new file mode 100644
index 000000000..9a19a32b6
--- /dev/null
+++ b/sources/pyside6/tests/QtOpenGL/QtOpenGL.pyproject
@@ -0,0 +1,4 @@
+{
+ "files": ["qopenglbuffer_test.py",
+ "qopenglwindow_test.py"]
+}
diff --git a/sources/pyside6/tests/QtOpenGL/qopenglbuffer_test.py b/sources/pyside6/tests/QtOpenGL/qopenglbuffer_test.py
new file mode 100644
index 000000000..a1433ca4c
--- /dev/null
+++ b/sources/pyside6/tests/QtOpenGL/qopenglbuffer_test.py
@@ -0,0 +1,78 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Unit tests for QOpenGLBuffer'''
+
+import ctypes
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from helper.usesqapplication import UsesQApplication
+from PySide6.QtGui import QOffscreenSurface, QOpenGLContext, QSurface, QWindow
+from PySide6.QtOpenGL import QOpenGLBuffer
+
+
+def createSurface(surfaceClass):
+ if surfaceClass == QSurface.Window:
+ window = QWindow()
+ window.setSurfaceType(QWindow.OpenGLSurface)
+ window.setGeometry(0, 0, 10, 10)
+ window.create()
+ return window
+ elif surfaceClass == QSurface.Offscreen:
+ # Create a window and get the format from that. For example, if an EGL
+ # implementation provides 565 and 888 configs for PBUFFER_BIT but only
+ # 888 for WINDOW_BIT, we may end up with a pbuffer surface that is
+ # incompatible with the context since it could choose the 565 while the
+ # window and the context uses a config with 888.
+ format = QSurfaceFormat
+ if format.redBufferSize() == -1:
+ window = QWindow()
+ window.setSurfaceType(QWindow.OpenGLSurface)
+ window.setGeometry(0, 0, 10, 10)
+ window.create()
+ format = window.format()
+ offscreenSurface = QOffscreenSurface()
+ offscreenSurface.setFormat(format)
+ offscreenSurface.create()
+ return offscreenSurface
+ return 0
+
+
+class QOpenGLBufferTest(UsesQApplication):
+ def testBufferCreate(self):
+ surface = createSurface(QSurface.Window)
+ ctx = QOpenGLContext()
+ ctx.create()
+ ctx.makeCurrent(surface)
+
+ buf = QOpenGLBuffer()
+
+ self.assertTrue(not buf.isCreated())
+
+ self.assertTrue(buf.create())
+ self.assertTrue(buf.isCreated())
+
+ self.assertEqual(buf.type(), QOpenGLBuffer.VertexBuffer)
+
+ buf.bind()
+ buf.allocate(128)
+ self.assertEqual(buf.size(), 128)
+
+ buf.release()
+
+ buf.destroy()
+ self.assertTrue(not buf.isCreated())
+
+ ctx.doneCurrent()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtOpenGL/qopenglwindow_test.py b/sources/pyside6/tests/QtOpenGL/qopenglwindow_test.py
new file mode 100644
index 000000000..88ae85a2e
--- /dev/null
+++ b/sources/pyside6/tests/QtOpenGL/qopenglwindow_test.py
@@ -0,0 +1,97 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Unit test for QOpenGLContext, QOpenGLTexture, QOpenGLWindow and related classes'''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from helper.usesqapplication import UsesQApplication
+
+from PySide6.QtCore import QSize, QTimer, Qt
+from PySide6.QtGui import (QColor, QGuiApplication, QImage, QOpenGLContext,
+ QSurfaceFormat)
+from PySide6.QtOpenGL import QOpenGLTexture, QOpenGLWindow
+
+
+try:
+ from OpenGL import GL
+ from PySide6.QtOpenGL import QOpenGLVersionProfile, QOpenGLVersionFunctionsFactory
+except ImportError:
+ print("Skipping test due to missing OpenGL module/GLES only build")
+ sys.exit(0)
+
+
+class OpenGLWindow(QOpenGLWindow):
+ def __init__(self):
+ super().__init__()
+
+ self.m_functions = None
+ self.m_texture = None
+ self.visibleChanged.connect(self.slotVisibleChanged)
+
+ def slotVisibleChanged(self, visible):
+ if not visible and self.m_texture is not None and self.context().makeCurrent(self):
+ self.m_texture = None
+ self.context().doneCurrent()
+
+ def initializeGL(self):
+ profile = QOpenGLVersionProfile()
+ profile.setVersion(1, 3)
+ profile.setProfile(QSurfaceFormat.CompatibilityProfile)
+ self.m_functions = QOpenGLVersionFunctionsFactory.get(profile)
+ self.m_functions.initializeOpenGLFunctions()
+
+ print("GL_MAX_LIGHTS=", self.m_functions.glGetIntegerv(GL.GL_MAX_LIGHTS))
+ image = QImage(QSize(200, 200), QImage.Format_RGBA8888)
+ image.fill(QColor(Qt.red))
+ self.m_texture = QOpenGLTexture(image)
+
+ def paintGL(self):
+ self.m_functions.glMatrixMode(GL.GL_MODELVIEW)
+ self.m_functions.glLoadIdentity()
+
+ self.m_functions.glMatrixMode(GL.GL_PROJECTION)
+ self.m_functions.glLoadIdentity()
+ self.m_functions.glOrtho(0, 1, 1, 0, -1, 1)
+
+ self.m_functions.glClear(GL.GL_COLOR_BUFFER_BIT)
+ self.m_functions.glEnable(GL.GL_TEXTURE_2D)
+ self.m_texture.bind()
+
+ d = 0.5
+ self.m_functions.glBegin(GL.GL_QUADS)
+ self.m_functions.glTexCoord2f(0, 0)
+ self.m_functions.glVertex2f(0, 0)
+ self.m_functions.glTexCoord2f(d, 0)
+ self.m_functions.glVertex2f(d, 0)
+ self.m_functions.glTexCoord2f(d, d)
+ self.m_functions.glVertex2f(d, d)
+ self.m_functions.glTexCoord2f(0, d)
+ self.m_functions.glVertex2f(0, d)
+ self.m_functions.glEnd()
+ self.m_texture.release()
+
+ def resizeGL(self, w, h):
+ self.m_functions.glViewport(0, 0, self.width(), self.height())
+
+
+class QOpenGLWindowTest(UsesQApplication):
+ # On macOS, glClear(), glViewport() are rejected due to GLbitfield/GLint not being resolved properly
+ def test(self):
+ openGlWindow = OpenGLWindow()
+ openGlWindow.resize(640, 480)
+ openGlWindow.show()
+ QTimer.singleShot(100, openGlWindow.close)
+ self.app.exec()
+
+
+if __name__ == '__main__':
+ unittest.main()