From eadf2af5d39c20e4a200d6c4d8668370a6a88ded Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 26 Jan 2022 11:10:45 +0100 Subject: Use Opaque container for OpenGL in the hellogl2 example Task-number: PYSIDE-1605 Change-Id: Ieefae548195c19ba9968b48c57d48a8255ed9633 Reviewed-by: Christian Tismer --- examples/opengl/hellogl2/hellogl2.py | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'examples/opengl/hellogl2/hellogl2.py') diff --git a/examples/opengl/hellogl2/hellogl2.py b/examples/opengl/hellogl2/hellogl2.py index 2f170dc90..245b172be 100644 --- a/examples/opengl/hellogl2/hellogl2.py +++ b/examples/opengl/hellogl2/hellogl2.py @@ -2,7 +2,7 @@ ############################################################################ ## ## Copyright (C) 2013 Riverbank Computing Limited. -## Copyright (C) 2021 The Qt Company Ltd. +## Copyright (C) 2022 The Qt Company Ltd. ## Contact: http://www.qt.io/licensing/ ## ## This file is part of the Qt for Python examples of the Qt Toolkit. @@ -45,11 +45,10 @@ from argparse import ArgumentParser, RawTextHelpFormatter import ctypes import math -import numpy import sys from PySide6.QtCore import QCoreApplication, Signal, SIGNAL, SLOT, Qt, QSize, QPointF from PySide6.QtGui import (QVector3D, QOpenGLFunctions, - QMatrix4x4, QOpenGLContext, QSurfaceFormat) + QMatrix4x4, QOpenGLContext, QSurfaceFormat, QVector3DList) from PySide6.QtOpenGL import (QOpenGLVertexArrayObject, QOpenGLBuffer, QOpenGLShaderProgram, QOpenGLShader) from PySide6.QtWidgets import (QApplication, QWidget, QMessageBox, QHBoxLayout, @@ -124,9 +123,8 @@ class Window(QWidget): class Logo(): def __init__(self): - self.m_count = 0 - self.i = 0 - self.m_data = numpy.empty(2500 * 6, dtype=ctypes.c_float) + self.m_data = QVector3DList() + self.m_data.reserve(5000) x1 = +0.06 y1 = -0.14 @@ -169,13 +167,13 @@ class Logo(): self.extrude(x8, y8, x5, y5) def const_data(self): - return self.m_data.tobytes() + return self.m_data.constData() def count(self): - return self.m_count + return len(self.m_data) * 3 def vertex_count(self): - return self.m_count / 6 + return self.count() / 6 def quad(self, x1, y1, x2, y2, x3, y3, x4, y4): n = QVector3D.normal(QVector3D(x4 - x1, y4 - y1, 0), QVector3D(x2 - x1, y2 - y1, 0)) @@ -210,19 +208,8 @@ class Logo(): self.add(QVector3D(x1, y1, -0.05), n) def add(self, v, n): - self.m_data[self.i] = v.x() - self.i += 1 - self.m_data[self.i] = v.y() - self.i += 1 - self.m_data[self.i] = v.z() - self.i += 1 - self.m_data[self.i] = n.x() - self.i += 1 - self.m_data[self.i] = n.y() - self.i += 1 - self.m_data[self.i] = n.z() - self.i += 1 - self.m_count += 6 + self.m_data.append(v) + self.m_data.append(n) class GLWidget(QOpenGLWidget, QOpenGLFunctions): -- cgit v1.2.3