diff options
author | Sergey Dubitskiy <sergey.dubitskiy@nokia.com> | 2012-02-13 14:27:29 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-14 01:37:52 +0100 |
commit | 35e1fc8ae0ef05eb59c55de707813233757de456 (patch) | |
tree | 943869f40c9f571840749d79f2b0265a52fae5b8 /examples/qt3d | |
parent | 00d127f73034c0aa4b21db5ef13490ea2ddf65b8 (diff) |
Resource handling needs refactoring.
Phase Two:
Fix all C++based demos/examples/tutorials.
Call cleanupResources() for all textures created.
Task-number: QTBUG-24043
Change-Id: I4bef23f7fe56e092de79bb91b41d6d691329b2cf
Reviewed-by: Sarah Jane Smith <sarah.j.smith@nokia.com>
Reviewed-by: Danny Pope <daniel.pope@nokia.com>
Diffstat (limited to 'examples/qt3d')
-rw-r--r-- | examples/qt3d/basket/basketview.cpp | 4 | ||||
-rw-r--r-- | examples/qt3d/builder/builder.cpp | 3 | ||||
-rw-r--r-- | examples/qt3d/builder/builder.h | 1 | ||||
-rw-r--r-- | examples/qt3d/cube/cubeview.cpp | 4 | ||||
-rw-r--r-- | examples/qt3d/cube/cubeview.h | 1 | ||||
-rw-r--r-- | examples/qt3d/cylinder/cylinderview.cpp | 5 | ||||
-rw-r--r-- | examples/qt3d/cylinder/cylinderview.h | 1 | ||||
-rw-r--r-- | examples/qt3d/geometry/geometry.cpp | 7 | ||||
-rw-r--r-- | examples/qt3d/geometry/geometry.h | 4 | ||||
-rw-r--r-- | examples/qt3d/nesting/cubeview.cpp | 1 | ||||
-rw-r--r-- | examples/qt3d/solarsystem/solarsystem.cpp | 7 | ||||
-rw-r--r-- | examples/qt3d/solarsystem/solarsystem.h | 1 | ||||
-rw-r--r-- | examples/qt3d/tank/quadplane.cpp | 12 | ||||
-rw-r--r-- | examples/qt3d/tank/quadplane.h | 4 | ||||
-rw-r--r-- | examples/qt3d/tank/tank.cpp | 16 | ||||
-rw-r--r-- | examples/qt3d/tank/tank.h | 3 |
16 files changed, 70 insertions, 4 deletions
diff --git a/examples/qt3d/basket/basketview.cpp b/examples/qt3d/basket/basketview.cpp index ea91fb14e..b5618455d 100644 --- a/examples/qt3d/basket/basketview.cpp +++ b/examples/qt3d/basket/basketview.cpp @@ -80,6 +80,10 @@ BasketView::BasketView(QWindow *parent) BasketView::~BasketView() { + const QGLMaterialCollection* pPalette = basket->palette().data(); + for (int i=0; i<pPalette->size(); ++i) { + pPalette->material(i)->texture()->cleanupResources(); + } delete basket; } diff --git a/examples/qt3d/builder/builder.cpp b/examples/qt3d/builder/builder.cpp index 07078b8d0..2e1db9842 100644 --- a/examples/qt3d/builder/builder.cpp +++ b/examples/qt3d/builder/builder.cpp @@ -53,6 +53,7 @@ BuilderView::BuilderView(QWindow *parent) : QGLView(parent) , canScene(new QGLSceneNode(this)) + , texture(0) { //! [0] QGLSceneNode *can = buildGeometry(); @@ -97,6 +98,7 @@ BuilderView::BuilderView(QWindow *parent) BuilderView::~BuilderView() { + texture->cleanupResources(); delete canScene; } @@ -132,6 +134,7 @@ QGLSceneNode *BuilderView::buildGeometry() url.setPath(QLatin1String(":/images/qt-soup.png")); url.setScheme(QLatin1String("file")); mat->setTextureUrl(url); + texture = mat->texture(); int canMat = root->palette()->addMaterial(mat); root->setMaterialIndex(canMat); root->setEffect(QGL::LitMaterial); diff --git a/examples/qt3d/builder/builder.h b/examples/qt3d/builder/builder.h index 9bd95128f..014e7c631 100644 --- a/examples/qt3d/builder/builder.h +++ b/examples/qt3d/builder/builder.h @@ -63,6 +63,7 @@ private: QGLSceneNode *buildGeometry(); QGLSceneNode *canScene; + QGLTexture2D *texture; }; #endif diff --git a/examples/qt3d/cube/cubeview.cpp b/examples/qt3d/cube/cubeview.cpp index 6f84996d0..e588305a2 100644 --- a/examples/qt3d/cube/cubeview.cpp +++ b/examples/qt3d/cube/cubeview.cpp @@ -46,6 +46,8 @@ CubeView::CubeView(QWindow *parent) : QGLView(parent) + , cube(0) + , texture(0) { QGLBuilder builder; builder << QGL::Faceted << QGLCube(1.5f); @@ -57,6 +59,7 @@ CubeView::CubeView(QWindow *parent) url.setPath(QLatin1String(":/qtlogo.png")); url.setScheme(QLatin1String("file")); mat->setTextureUrl(url); + texture = mat->texture(); cube->setMaterial(mat); cube->setEffect(QGL::LitDecalTexture2D); @@ -64,6 +67,7 @@ CubeView::CubeView(QWindow *parent) CubeView::~CubeView() { + texture->cleanupResources(); delete cube; } diff --git a/examples/qt3d/cube/cubeview.h b/examples/qt3d/cube/cubeview.h index 3b537aa50..dbe256247 100644 --- a/examples/qt3d/cube/cubeview.h +++ b/examples/qt3d/cube/cubeview.h @@ -59,6 +59,7 @@ protected: private: QGLSceneNode *cube; + QGLTexture2D *texture; }; #endif diff --git a/examples/qt3d/cylinder/cylinderview.cpp b/examples/qt3d/cylinder/cylinderview.cpp index 3cc7b9468..26036bee1 100644 --- a/examples/qt3d/cylinder/cylinderview.cpp +++ b/examples/qt3d/cylinder/cylinderview.cpp @@ -57,6 +57,7 @@ CylinderView::CylinderView(QWindow *parent) urlLid.setPath(QLatin1String(":/latte.png")); urlLid.setScheme(QLatin1String("file")); matLid->setTextureUrl(urlLid); + m_LoadedTextures.push_back(matLid->texture()); QGLMaterial *matSides = new QGLMaterial; matSides->setColor(QColor(170, 202, 0)); @@ -64,6 +65,7 @@ CylinderView::CylinderView(QWindow *parent) urlSides.setPath(QLatin1String(":/cupTexture.png")); urlSides.setScheme(QLatin1String("file")); matSides->setTextureUrl(urlSides); + m_LoadedTextures.push_back(matSides->texture()); QGLSceneNode *root = builder.sceneNode(); @@ -89,6 +91,9 @@ CylinderView::CylinderView(QWindow *parent) CylinderView::~CylinderView() { + for (int i=0; i<m_LoadedTextures.count(); ++i) { + m_LoadedTextures.at(i)->cleanupResources(); + } delete cylinder; } diff --git a/examples/qt3d/cylinder/cylinderview.h b/examples/qt3d/cylinder/cylinderview.h index 124c56c71..7d55fccd1 100644 --- a/examples/qt3d/cylinder/cylinderview.h +++ b/examples/qt3d/cylinder/cylinderview.h @@ -59,6 +59,7 @@ protected: private: QGLSceneNode *cylinder; + QList<QGLTexture2D*> m_LoadedTextures; }; #endif diff --git a/examples/qt3d/geometry/geometry.cpp b/examples/qt3d/geometry/geometry.cpp index f1f89760d..98e8e25cf 100644 --- a/examples/qt3d/geometry/geometry.cpp +++ b/examples/qt3d/geometry/geometry.cpp @@ -52,6 +52,7 @@ const float phi = 1.618033988749894848f; Geometry::Geometry(QObject *parent, QSharedPointer<QGLMaterialCollection> materials) : QGLSceneNode(parent) + , m_texture(0) { setPalette(materials); @@ -198,8 +199,14 @@ Geometry::Geometry(QObject *parent, QSharedPointer<QGLMaterialCollection> materi QGLTexture2D *texture = new QGLTexture2D(mat); texture->setImage(uv); mat->setTexture(texture); + m_texture = texture; setMaterial(mat); QGLSceneNode *n = b.finalizedSceneNode(); addNode(n); } + +Geometry::~Geometry() +{ + m_texture->cleanupResources(); +} diff --git a/examples/qt3d/geometry/geometry.h b/examples/qt3d/geometry/geometry.h index 8504c0254..b83c49918 100644 --- a/examples/qt3d/geometry/geometry.h +++ b/examples/qt3d/geometry/geometry.h @@ -53,6 +53,10 @@ class Geometry : public QGLSceneNode { public: Geometry(QObject *parent, QSharedPointer<QGLMaterialCollection> materials); + ~Geometry(); + +private: + QGLTexture2D *m_texture; }; #endif // GEOMETRY_H diff --git a/examples/qt3d/nesting/cubeview.cpp b/examples/qt3d/nesting/cubeview.cpp index 274b85db6..ae7b8a7b2 100644 --- a/examples/qt3d/nesting/cubeview.cpp +++ b/examples/qt3d/nesting/cubeview.cpp @@ -101,6 +101,7 @@ CubeView::CubeView(QWindow *parent) CubeView::~CubeView() { + qtlogo.cleanupResources(); delete fbo; } diff --git a/examples/qt3d/solarsystem/solarsystem.cpp b/examples/qt3d/solarsystem/solarsystem.cpp index 73c2f159e..baa1e9826 100644 --- a/examples/qt3d/solarsystem/solarsystem.cpp +++ b/examples/qt3d/solarsystem/solarsystem.cpp @@ -106,6 +106,9 @@ SolarSystemView::SolarSystemView(QWindow *parent) SolarSystemView::~SolarSystemView() { + for (int i=0; i<m_LoadedTextures.count(); ++i) { + m_LoadedTextures.at(i)->cleanupResources(); + } delete spaceScene; delete sunEffect; } @@ -146,6 +149,8 @@ QGLSceneNode *SolarSystemView::createScene() url.setPath(QLatin1String(":/solar2.jpg")); url.setScheme(QLatin1String("file")); mat1->setTextureUrl(url, 1); + m_LoadedTextures.push_back(mat1->texture(0)); + m_LoadedTextures.push_back(mat1->texture(1)); //mat1->setEmittedLight(Qt::white); int sunMat = root->palette()->addMaterial(mat1); @@ -154,6 +159,7 @@ QGLSceneNode *SolarSystemView::createScene() url.setPath(QLatin1String(":/planet.jpg")); url.setScheme(QLatin1String("file")); mat2->setTextureUrl(url); + m_LoadedTextures.push_back(mat2->texture()); int planetMat = root->palette()->addMaterial(mat2); //moon surface @@ -161,6 +167,7 @@ QGLSceneNode *SolarSystemView::createScene() url.setPath(QLatin1String(":/moon-texture.jpg")); url.setScheme(QLatin1String("file")); mat3->setTextureUrl(url); + m_LoadedTextures.push_back(mat3->texture()); int moonMat = root->palette()->addMaterial(mat3); //Set the rotation of the solar-system diff --git a/examples/qt3d/solarsystem/solarsystem.h b/examples/qt3d/solarsystem/solarsystem.h index a5aad7a03..53c89674a 100644 --- a/examples/qt3d/solarsystem/solarsystem.h +++ b/examples/qt3d/solarsystem/solarsystem.h @@ -87,6 +87,7 @@ private: QGraphicsRotation3D *moonRotation; QGraphicsRotation3D *systemRotation; QGLSceneNode *spaceScene; + QList<QGLTexture2D*> m_LoadedTextures; QGLShaderProgramEffect* sunEffect; diff --git a/examples/qt3d/tank/quadplane.cpp b/examples/qt3d/tank/quadplane.cpp index 16b416da1..16935c912 100644 --- a/examples/qt3d/tank/quadplane.cpp +++ b/examples/qt3d/tank/quadplane.cpp @@ -70,6 +70,7 @@ QGLMaterial *qCreateFloor() QuadPlane::QuadPlane(QObject *parent, QSizeF size, int level) : QGLSceneNode(parent) + , m_texture(0) { setObjectName("QuadPlane"); if (level > 8) @@ -102,9 +103,18 @@ QuadPlane::QuadPlane(QObject *parent, QSizeF size, int level) } QGLSceneNode *n = builder.finalizedSceneNode(); addNode(n); - n->setMaterial(qCreateFloor()); + QGLMaterial *mat = qCreateFloor(); + m_texture = mat->texture(); + n->setMaterial(mat); QGraphicsRotation3D *rot = new QGraphicsRotation3D(n); rot->setAxis(QVector3D(1, 0, 0)); rot->setAngle(90.0f); n->addTransform(rot); } + +QuadPlane::~QuadPlane() +{ + if (m_texture) + m_texture->cleanupResources(); +} + diff --git a/examples/qt3d/tank/quadplane.h b/examples/qt3d/tank/quadplane.h index db2aee6f3..0bb3f122a 100644 --- a/examples/qt3d/tank/quadplane.h +++ b/examples/qt3d/tank/quadplane.h @@ -50,6 +50,10 @@ class QuadPlane : public QGLSceneNode public: QuadPlane(QObject *parent = 0, QSizeF size = QSizeF(100.0f, 100.0f), int level = 3); + ~QuadPlane(); + +private: + QGLTexture2D *m_texture; }; #endif // QUADPLANE_H diff --git a/examples/qt3d/tank/tank.cpp b/examples/qt3d/tank/tank.cpp index b4e055652..f10daee42 100644 --- a/examples/qt3d/tank/tank.cpp +++ b/examples/qt3d/tank/tank.cpp @@ -87,8 +87,9 @@ static QGLMaterial *qCreateFluid() return mat; } -Tank::Tank(QObject *parent) : - QGLSceneNode(parent) +Tank::Tank(QObject *parent) + : QGLSceneNode(parent) + , m_texture(0) { QSequentialAnimationGroup *seq = new QSequentialAnimationGroup(this); QGraphicsScale3D *scale = new QGraphicsScale3D(this); @@ -110,7 +111,16 @@ Tank::Tank(QObject *parent) : seq->start(); addNode(tankObject()); - setMaterial(qCreateFluid()); + + QGLMaterial *mat = qCreateFluid(); + m_texture = mat->texture(); + setMaterial(mat); +} + +Tank::~Tank() +{ + if (m_texture) + m_texture->cleanupResources(); } QGLSceneNode *Tank::tankObject() diff --git a/examples/qt3d/tank/tank.h b/examples/qt3d/tank/tank.h index ce8badb02..da939bdab 100644 --- a/examples/qt3d/tank/tank.h +++ b/examples/qt3d/tank/tank.h @@ -48,12 +48,15 @@ class Tank : public QGLSceneNode Q_OBJECT public: explicit Tank(QObject *parent = 0); + ~Tank(); signals: public slots: private: static QGLSceneNode *tankObject(); + + QGLTexture2D *m_texture; }; #endif // TANK_H |