diff options
author | dpope <[email protected]> | 2012-02-03 15:45:25 +1000 |
---|---|---|
committer | Rohan McGovern <[email protected]> | 2012-02-10 07:24:48 +0100 |
commit | bc66ec0bc5f548a72d21557d529f2d03c7417f09 (patch) | |
tree | 53aa0444fc698cde712fb8e0486e3da1a56f853d /src/threed/scene | |
parent | 98451b5e136af38b00b008ae58ec8243c981eee4 (diff) |
Change-Id: I271146636615ab16f79ad3e66985076e2bd7a95c
Reviewed-by: Sarah Jane Smith <[email protected]>
Diffstat (limited to 'src/threed/scene')
-rw-r--r-- | src/threed/scene/qglabstractscene.cpp | 605 | ||||
-rw-r--r-- | src/threed/scene/qglabstractscene.h | 113 | ||||
-rw-r--r-- | src/threed/scene/qglpicknode.cpp | 215 | ||||
-rw-r--r-- | src/threed/scene/qglpicknode.h | 82 | ||||
-rw-r--r-- | src/threed/scene/qglrenderorder.cpp | 318 | ||||
-rw-r--r-- | src/threed/scene/qglrenderorder.h | 203 | ||||
-rw-r--r-- | src/threed/scene/qglrenderordercomparator.cpp | 164 | ||||
-rw-r--r-- | src/threed/scene/qglrenderordercomparator.h | 69 | ||||
-rw-r--r-- | src/threed/scene/qglrendersequencer.cpp | 369 | ||||
-rw-r--r-- | src/threed/scene/qglrendersequencer.h | 87 | ||||
-rw-r--r-- | src/threed/scene/qglrenderstate.cpp | 320 | ||||
-rw-r--r-- | src/threed/scene/qglrenderstate.h | 105 | ||||
-rw-r--r-- | src/threed/scene/qglsceneformatplugin.cpp | 316 | ||||
-rw-r--r-- | src/threed/scene/qglsceneformatplugin.h | 122 | ||||
-rw-r--r-- | src/threed/scene/qglscenenode.cpp | 1884 | ||||
-rw-r--r-- | src/threed/scene/qglscenenode.h | 205 | ||||
-rw-r--r-- | src/threed/scene/qglscenenode_p.h | 145 | ||||
-rw-r--r-- | src/threed/scene/scene.pri | 19 |
18 files changed, 0 insertions, 5341 deletions
diff --git a/src/threed/scene/qglabstractscene.cpp b/src/threed/scene/qglabstractscene.cpp deleted file mode 100644 index ee685e76..00000000 --- a/src/threed/scene/qglabstractscene.cpp +++ /dev/null @@ -1,605 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglabstractscene.h" -#include "qglsceneformatplugin.h" -#include "qglpicknode.h" - -// copied private header -#include "qfactoryloader_p.h" - -#include <QtCore/qfile.h> -#include <QtCore/qfileinfo.h> -#include <QtCore/qlibraryinfo.h> -#include <QtNetwork/qnetworkreply.h> -#include <QtCore/qcoreevent.h> -#include <QtCore/qdebug.h> -#include <QtCore/qcoreapplication.h> -#include <QtCore/qdir.h> -#include <QtCore/qpluginloader.h> -#include <QBuffer> - -QT_BEGIN_NAMESPACE - -/*! - \class QGLAbstractScene - \brief The QGLAbstractScene class represents a 3D scene consisting of zero or more QGLSceneNode instances. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - Scenes are typically created by 3D modelling packages and then loaded - into the application via a QGLSceneFormatPlugin; but they can also be - constructed programatically. The functions in this - class provide access to major scene objects so that they can be - applied or drawn whenever the application decides. - - QGLAbstractScene presents a very simple model of a 3D scene. Subclasses - implement the specific scene graph and object representations in a - manner specific to the package's format. Subclasses may also provide - functionality to create new objects at runtime, but this is not required. - - The scene is defined to consist of a number of important objects - of the following types: - - \list - \o Camera objects define a viewing position in world-coordinates and a - projection that maps 3D world co-ordinates to 2D screen co-ordinates. - Camera objects should inherit from QGLCamera. - \o Main objects designate the major elements of the scene besides - cameras, lights, and effects. Usually they inherit from QGLSceneNode. - \o Light objects define positions and parameters for lighting the scene. - Light objects should inherit from QGLLightParameters. - \o Effect objects define materials, shaders, and textures for use in - rendering the surface of objects. Normally effects are activated - automatically when main objects are drawn. But effects can be used - independently if the 3D format is acting as a library of effects. - \o Mesh objects define geometry information independently of effects. - Normally meshes are drawn automatically with an appropriate effect - when main objects are drawn. But meshes can be used independently - if the 3D format is acting as a library of meshes. Mesh objects - should inherit from QGLSceneNode. - \endlist - - Typically, the full scene represented by an external model format - is not interesting to the application. 3D modelling packages - regularly insert cameras, lights, effects, and other library - objects that are useful to the modelling package, but not the - application. The mainNode() is usually the most interesting - to applications. - - QGLAbstractScene makes it easy to access the major scene elements - with object(), objects(), and mainNode(). - - There are many other kinds of objects in the scene that may not - be accessible via QGLAbstractScene because they are not considered - "important" enough. For example, a file that contains the data - for a skateboard object would contain many objects for the board, - wheels, texturing effects, animations, and so on. The application - may only be interested in the skateboard as a whole, and not its - sub-components. The skateboard would be considered an important - main object in this case, which can be easily accessed and - incorporated into the application's logic. - - Each Subclass needs to provide its own policy for deciding which - objects are considered "important". - - \sa QGLSceneNode, QGLSceneFormatPlugin -*/ - -class QGLAbstractScenePrivate -{ -public: - QGLAbstractScenePrivate() - : picking(false), nextPickId(-1), pickNodesDirty(true) {} - bool picking; - int nextPickId; - QList<QGLPickNode*> pickNodes; - QSet<QGLSceneNode*> pickable; - bool pickNodesDirty; -}; - -/*! - Constructs a 3D scene and attaches it to \a parent. -*/ -QGLAbstractScene::QGLAbstractScene(QObject *parent) - : QObject(parent) - , d_ptr(new QGLAbstractScenePrivate) -{ -} - -/*! - Destroys this 3D scene. -*/ -QGLAbstractScene::~QGLAbstractScene() -{ -} - -/*! - \internal -*/ -void QGLAbstractScene::childEvent(QChildEvent *event) -{ - Q_D(QGLAbstractScene); - if (event->type() == QEvent::ChildAdded) - d->pickNodesDirty = true; -} - -/*! - Sets this scene to be pickable if \a enable is true, otherwise picking - is disabled. If the scene is set to be pickable, pick nodes are - generated by calling generatePickNodes(). - - \sa generatePickNodes(), pickable() -*/ -void QGLAbstractScene::setPickable(bool enable) -{ - Q_D(QGLAbstractScene); - if (enable != d->picking) - { - d->picking = enable; - if (d->picking) - generatePickNodes(); - } -} - -/*! - Returns true if this scene is pickable. - - \sa setPickable() -*/ -bool QGLAbstractScene::pickable() const -{ - Q_D(const QGLAbstractScene); - return d->picking; -} - -/*! - Generates QGLPickNode instances for important QGLSceneNode instances that are - pickable. Objects that are either not important or not pickable can - be omitted. The default implementation simply generates pick nodes - for every top level object of type QGLSceneNode. - - Sub-classes may implement different schemes for picking. When doing - so parent the QGLPickNode objects onto the scene, so that they will - appear in the list returned by pickNodes() - - \sa pickNodes(), setPickable() -*/ -void QGLAbstractScene::generatePickNodes() -{ - Q_D(QGLAbstractScene); - QList<QObject *> objs = objects(); - QList<QObject *>::iterator it = objs.begin(); - d->pickNodes.clear(); - for ( ; it != objs.end(); ++it) - { - QGLSceneNode *n = qobject_cast<QGLSceneNode *>(*it); - if (d) { - if (!d->pickable.contains(n)) { - n->setPickNode(new QGLPickNode(this)); - d->pickable.insert(n); - } - d->pickNodes.append(n->pickNode()); - } - } -} - -/*! - Increments and returns the next available pick id for this scene. -*/ -int QGLAbstractScene::nextPickId() -{ - return ++d_ptr->nextPickId; -} - -/*! - Returns a list of the pick nodes that have been parented onto this - scene. - - \sa generatePickNodes() -*/ -QList<QGLPickNode *> QGLAbstractScene::pickNodes() const -{ - if (d_ptr->pickNodesDirty) - { - const_cast<QGLAbstractScene*>(this)->generatePickNodes(); - d_ptr->pickNodesDirty = false; - } - return d_ptr->pickNodes; -} - -/*! - \fn QList<QObject *> QGLAbstractScene::objects() const - - Returns a list of all objects in the scene which are considered - important. - - Important objects will typically be the main mesh object, cameras, - lights, and other top-level objects. Sub-meshes and effects - are normally not considered important unless the scene is - acting as a library of meshes and effects. - - \sa objectNames(), object(), mainNode() -*/ - -/*! - Returns a list of the names of all objects in the scene which - are considered important, and which have non-empty names - associated with them. - - The default implementation calls objects() and then compiles a list - of all non-empty object names. - - \sa objects() -*/ -QStringList QGLAbstractScene::objectNames() const -{ - QList<QObject *> objs = objects(); - QStringList names; - for (int index = 0; index < objs.count(); ++index) { - QObject *object = objs.at(index); - if (object) { - QString name = object->objectName(); - if (!name.isEmpty()) - names += name; - } - } - return names; -} - -/*! - Returns the scene object that has the specified \a name; - or null if the object was not found. - - The default implementation searches objects() for an object that - matches \a name. - - \sa objects() -*/ -QObject *QGLAbstractScene::object(const QString& name) const -{ - if (name.isEmpty()) - return 0; - QList<QObject *> objs = objects(); - for (int index = 0; index < objs.count(); ++index) { - QObject *object = objs.at(index); - if (object && object->objectName() == name) - return object; - } - return 0; -} - - -/*! - \fn QGLSceneNode *QGLAbstractScene::mainNode() const - - Returns the main mesh node in the scene, or null if the scene - does not contain a main mesh node. - - \sa objects() -*/ - -#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QGLSceneFormatFactoryInterface_iid, QLatin1String("/sceneformats"))) -#endif - -/*! - Loads a scene from \a device in the specified \a format using - the registered scene format plugins. If \a format is an empty - string, then the format will be autodetected from the filename - extension of \a device. The \a url specifies the location of - the data in \a device so that relative resources can be located. - - The \a options string is passed to the underlying format loader - and its meaning and format depend on the loader. For example the - format string for the .3ds loader accepts the following options: - \list - \o ForceSmooth - average normals for a smooth appearance - \o ForceFaceted - per face normals for a faceted appearance - \o NativeIndices - map native indices for poorly smoothed models - \o CorrectNormals - fix inverted normals on models with bad windings - \o CorrectAcute - fix normals on models that smooth acute angles - \endlist - - The options may be specified globally for the whole model, or just - for a particular mesh. - - In this example smoothing is forced on globally, and native indices - are used on just the mesh called "BattCoverMesh". - - \code - QString op = "ForceSmooth BattCoverMesh=NativeIndices"; - QString file = "music-player.3ds"; - QGLAbstractScene *scene = QGLAbstractScene::loadScene(file, QString(), op); - \endcode - - Returns the scene object, or null if the scene could not be loaded - or the \a format was not supported by any of the plugins. - - \sa QGLSceneFormatPlugin -*/ -QGLAbstractScene *QGLAbstractScene::loadScene - (QIODevice *device, const QUrl& url, const QString& format, const QString &options) -{ -#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) - - QFactoryLoader *l = loader(); - QStringList keys = l->keys(); - - // If the format is not specified, then use the filename/url extension. - QString fmt = format; - if (fmt.isEmpty()) { - //First try to resolve a file io device - QFile *file = qobject_cast<QFile *>(device); - QString name; - if (file) { - name = file->fileName(); - } else { - //Next try to resolve a network io device - QNetworkReply *reply = qobject_cast<QNetworkReply *>(device); - if (reply) - name = reply->url().path(); - else { - //otherwise just use the url pathname. - name = url.path(); - } - } - int dot = name.lastIndexOf(QLatin1Char('.')); - QString suffix = name.mid(dot+1).toLower(); - int index = keys.indexOf(suffix); - if (index >= 0) - fmt = suffix; - } - - // Find the plugin that handles the format and ask it to create a handler. - if (QGLSceneFormatFactoryInterface *factory - = qobject_cast<QGLSceneFormatFactoryInterface*> - (l->instance(fmt))) { - QGLSceneFormatHandler *handler = factory->create(device, url, fmt); - if (handler) { - handler->setDevice(device); - handler->setUrl(url); - handler->setFormat(format); - - - if (!options.isEmpty()) - handler->decodeOptions(options); - - QGLAbstractScene *scene = 0; - if (!device) { - scene = handler->download(); - } else { - scene = handler->read(); - } - return scene; - } - } - - // If we get here, then the format is not supported by any of the plugins. -#ifndef QT_NO_DEBUG - qWarning("Could not create handler for format %s" - "- check plugins are installed correctly in %s", - qPrintable(fmt), - qPrintable(QLibraryInfo::location(QLibraryInfo::PluginsPath))); -#endif - return 0; -#else // QT_NO_LIBRARY || QT_NO_SETTINGS - Q_UNUSED(device); - Q_UNUSED(url); - Q_UNUSED(format); - return 0; -#endif // QT_NO_LIBRARY || QT_NO_SETTINGS -} - -/*! - Loads a scene from the internet in the specified \a format using - the registered scene format plugins. If \a format is an empty - string, then the format will be autodetected from the filename - extension of the \a url, which specifies the location of - the data online. - - The \a options string is passed to the underlying format loader - and its meaning and format depend on the loader. For example the - format string for the .3ds loader accepts the following options: - \list - \o ForceSmooth - average normals for a smooth appearance - \o ForceFaceted - per face normals for a faceted appearance - \o NativeIndices - map native indices for poorly smoothed models - \o CorrectNormals - fix inverted normals on models with bad windings - \o CorrectAcute - fix normals on models that smooth acute angles - \endlist - - The options may be specified globally for the whole model, or just - for a particular mesh. - - In this example smoothing is forced on globally, and native indices - are used on just the mesh called "BattCoverMesh". - - \code - QString op = "ForceSmooth BattCoverMesh=NativeIndices"; - QString url = "http://www.example.url.com/music-player.3ds"; - QGLAbstractScene *scene = QGLAbstractScene::loadScene(url, QString(), op); - \endcode - - Returns the scene object, or null if the scene could not be loaded - or the \a format was not supported by any of the plugins. - - The scene object returned by this will contain only a single stub - node at the root of the scenegraph, which will be filled out later - once the asynchronous download of the scene data is complete. - - \sa QGLSceneFormatPlugin -*/ -QGLAbstractScene *QGLAbstractScene::loadScene - (const QUrl& url, const QString& format, const QString &options) -{ - return QGLAbstractScene::loadScene(0, url, format, options); -} - -/*! - Loads a scene from \a fileName in the specified \a format, with the - supplied \a options, and using the registered scene format plugins. - - If \a format is an empty string, then the format will be autodetected - from the extension of \a fileName. - - The \a options string is passed to the underlying format loader - and its meaning and format depend on the loader. See the doc above - for loadScene() for details on the 3ds format options. - - Returns the scene object, or null if the scene could not be loaded - or the \a format was not supported by any of the plugins. - - \sa QGLSceneFormatPlugin -*/ -QGLAbstractScene *QGLAbstractScene::loadScene - (const QString& fileName, const QString& format, const QString &options) -{ - QUrl fileUrl(fileName); - - if (fileUrl.scheme()!="http" && fileUrl.scheme()!="ftp") { - QFile file(fileName); - if (!file.open(QIODevice::ReadOnly)) - { - if (options.contains(QLatin1String("ShowWarnings"))) - qWarning("Could not read %s", qPrintable(fileName)); - return 0; - } - QFileInfo fi(fileName); - QUrl url = QUrl::fromLocalFile(fi.absoluteFilePath()); - return loadScene(&file, url, format, options); - } else { - //the following call should initiate network loading on the correct - //downloader class. - return loadScene(QUrl(fileName), format, options); - } -} - -/*! - \enum QGLAbstractScene::FormatListType - This enum specifies the format of the list returned by the supportedFormats() function. - - \value AsFilter Return a format list that may be used as a filter. - \value AsSuffix Return a format list that is simply the filename suffixes. -*/ - -/*! - Returns a list of all supported formats known by currently available - sceneformat plugins, in the format type \a t. - - If \a t is QGLAbstractScene::AsFilter then the result may be passed - to QDir::setNameFilters(), or used in other filters. This is the default. - - For example to create a file dialog to load model files use this: - \code - QString modelsDir = QDir::toNativeSeperators(QDir::homePath()); - QString filter = tr("Models (%1)").arg(QAbstractScene::supportedFormats().join(" ")); - QString fileName = QFileDialog::getOpenFileName(this, - tr("Open File"), modelsDir, filter)); - \endcode - - Otherwise (when \a t is QGLAbstractScene::AsSuffix) it is simply a list - of file name suffixes. - - Note that this function may be expensive to - call since it scans for available plugins, and loads each one it - finds to get an accurate report of formats supported at run-time. -*/ -QStringList QGLAbstractScene::supportedFormats(QGLAbstractScene::FormatListType t) -{ - QStringList formats; - QSet<QString> formatSet; - QSet<QString> dirSet; - QStringList pluginPaths = QCoreApplication::libraryPaths(); - QStringList::const_iterator it = pluginPaths.constBegin(); - for ( ; it != pluginPaths.constEnd(); ++it) - { - QString path = *it; - QDir sceneformatDir(path + QLatin1String("/sceneformats")); - path = sceneformatDir.absolutePath(); - if (!sceneformatDir.exists() || dirSet.contains(path)) - continue; - dirSet.insert(path); - sceneformatDir.setFilter(QDir::Files); - QStringList entries = sceneformatDir.entryList(); - QStringList::const_iterator fit = entries.constBegin(); - for ( ; fit != entries.constEnd(); ++fit) - { - QString fi = *fit; - QPluginLoader loader(sceneformatDir.absoluteFilePath(fi)); - QObject *inst = loader.instance(); - QGLSceneFormatFactoryInterface *iface = qobject_cast<QGLSceneFormatFactoryInterface*>(inst); - if (iface) - { - QStringList formatKeys = iface->keys(); - QStringList::const_iterator kit = formatKeys.constBegin(); - for ( ; kit != formatKeys.constEnd(); ++kit) - { - QString k = *kit; - if (!formatSet.contains(k) && !k.contains("/")) // dont add mime-type keys - { - if (t == AsFilter) - k.prepend("*."); - formatSet.insert(k); - formats.append(k); - } - } - } - } - } - return formats; -} - -/*! - \fn QGLAbstractScene::sceneUpdated() - \internal - This signal should be emitted when a network download of a scene has - been completed. - - The user is left to implement the exact mechanism behind the scenes which - causes this signal to be emitted, and is responsible for the handling - of the signal. -*/ - - -QT_END_NAMESPACE diff --git a/src/threed/scene/qglabstractscene.h b/src/threed/scene/qglabstractscene.h deleted file mode 100644 index 8fc7a5fa..00000000 --- a/src/threed/scene/qglabstractscene.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLABSTRACTSCENE_H -#define QGLABSTRACTSCENE_H - -#include "qt3dglobal.h" -#include "qglscenenode.h" - -#include <QtCore/qstringlist.h> -#include <QtCore/qurl.h> -#include <QtCore/qscopedpointer.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt3D) - -class QGLAbstractScenePrivate; -class QIODevice; -class QGLPickNode; - -class Q_QT3D_EXPORT QGLAbstractScene : public QObject -{ - Q_OBJECT -public: - explicit QGLAbstractScene(QObject *parent = 0); - virtual ~QGLAbstractScene(); - - virtual void setPickable(bool enable); - virtual bool pickable() const; - virtual void generatePickNodes(); - QList<QGLPickNode *> pickNodes() const; - int nextPickId(); - - virtual QList<QObject *> objects() const = 0; - virtual QStringList objectNames() const; - virtual QObject *object(const QString& name) const; - virtual QGLSceneNode *mainNode() const = 0; - - static QGLAbstractScene *loadScene - (const QUrl& url, const QString& format = QString(), - const QString& options = QString()); - static QGLAbstractScene *loadScene - (QIODevice *device, const QUrl& url, const QString& format = QString(), - const QString& options = QString()); - static QGLAbstractScene *loadScene - (const QString& fileName, const QString& format = QString(), - const QString& options = QString()); - - enum FormatListType { - AsFilter, AsSuffix - }; - - static QStringList supportedFormats(FormatListType t = AsFilter); - -signals: - void sceneUpdated(); - -protected: - void childEvent(QChildEvent * event); - -private: - QScopedPointer<QGLAbstractScenePrivate> d_ptr; - - Q_DISABLE_COPY(QGLAbstractScene) - Q_DECLARE_PRIVATE(QGLAbstractScene) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/threed/scene/qglpicknode.cpp b/src/threed/scene/qglpicknode.cpp deleted file mode 100644 index 8275aacd..00000000 --- a/src/threed/scene/qglpicknode.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglpicknode.h" -#include "qglabstractscene.h" - -#include <QtGui/qevent.h> - -/*! - \class QGLPickNode - \brief The QGLPickNode class enables picking for objects in a 3D scene. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - QGLPickNode is a QObject sub-class, relatively light-weight, that can - shadow QSceneObject instances and provide picking capability. The - QGLPickNode instance receives events sent to it by picking views, such - as the QGLView class, and emits relevant signals in response. - - QGLSceneObjects wanting to support picking, should implement the methods - \list - \o QGLSceneNode::pickNode() - \o QGLSceneNode::setPickNode() - \endlist - and also implement rendering such that the QGLPainter has the relevant - \l{QGLPainter::setObjectPickId()}{pick id function} called. - - These functions are already implemented for the QGLSceneNode object type. - - Picking can then be simply enabled by calling the QGLAbstractScene function - setPickable() to turn on picking and generate pick nodes for the relevant - scene objects. - - In order to respond to picking, the view class should simply register the - picknodes, and connect a relevant slot to the pick nodes signal. - - For the QGLView class that code is simply: - \code - QList<QGLPickNode *>nodes = manager->pickNodes(); - foreach (QGLPickNode *node, nodes) - { - registerObject(node->id(), node); - connect(node, SIGNAL(clicked()), - this, SLOT(objectPicked())); - } - \endcode - - The pick nodes should be unregistered with similar code for the QGLView if - switching to a different scene. - - To be able to recover the relevant QGLSceneNode inside the called slot, - the object may be set onto the QGLPickNode with the setTarget() function, - and recovered with target() inside the slot, since the QGLPickNode will - be the sender() for the slot. - - QGLSceneNode already sets itself as the target during the pick enable step. - - \sa QGLSceneNode, QGLView -*/ - -/*! - Construct a new QGLPickNode object managed by and parented onto - the \a parent scene. The nextPickId() function will be called on - \a parent to assign a pick id to this new node. -*/ -QGLPickNode::QGLPickNode(QGLAbstractScene *parent) : - QObject(parent), m_id(-1), m_target(0) -{ - if (parent) - m_id = parent->nextPickId(); -} - -/*! - \fn int QGLPickNode::id() const - Returns the unique id for this node. This value is assigned by - the parent scene for this node and should be different for every - node in the scene. Returns -1 if the id has not been set yet. - - \sa setId() -*/ - -/*! - \fn void QGLPickNode::setId(int id) - Sets the unique \a id for this node. Generally this function should not - be needed, since the constructor causes a unique id to be obtained - from the parent scene. This function exists mainly for testing - purposes. - - \sa id() -*/ - -/*! - \fn QGLSceneNode *QGLPickNode::target() const - Returns the QGLSceneNode which is the target of this pick node; - null if the target has not been set yet. - - \sa setTarget() -*/ - -/*! - \fn void QGLPickNode::setTarget(QGLSceneNode *target) - Sets the \a target for this pick node. - - \sa target() -*/ - -/*! - \fn void QGLPickNode::pressed() - Signal emitted when the scene object for this node has the mouse pressed - while the cursor is on the object in the scene. -*/ - -/*! - \fn void QGLPickNode::released() - Signal emitted when the scene object for this node has the mouse released - while the cursor is on the object in the scene. -*/ - -/*! - \fn void QGLPickNode::clicked() - Signal emitted when the scene object for this node has the mouse pressed - and then released while the cursor is on the object in the scene. -*/ - -/*! - \fn void QGLPickNode::doubleClicked() - Signal emitted when the scene object for this node has the mouse clicked - twice in succession while the cursor is on the object in the scene. -*/ - -/*! - \fn void QGLPickNode::hoverChanged() - Signal emitted when the scene object for this node has the mouse moved - into or out of this object in the scene. -*/ - -/*! - \internal -*/ -bool QGLPickNode::event(QEvent *e) -{ - // ripped off from teaservice demo, but not before the same code - // was ripped off and put in item3d.cpp - those should probably all - // use this implementation here - if (e->type() == QEvent::MouseButtonPress) - { - QMouseEvent *me = (QMouseEvent *)e; - if (me->button() == Qt::LeftButton) - emit pressed(); - } - else if (e->type() == QEvent::MouseButtonRelease) - { - QMouseEvent *me = (QMouseEvent *)e; - if (me->button() == Qt::LeftButton) - { - emit released(); - if (me->x() >= 0) // Positive: inside object, Negative: outside. - emit clicked(); - } - } - else if (e->type() == QEvent::MouseButtonDblClick) - { - emit doubleClicked(); - } - else if (e->type() == QEvent::Enter) - { - //m_hovering = true; - emit hoverChanged(); - } - else if (e->type() == QEvent::Leave) - { - //m_hovering = false; - emit hoverChanged(); - } - return QObject::event(e); -} diff --git a/src/threed/scene/qglpicknode.h b/src/threed/scene/qglpicknode.h deleted file mode 100644 index 5b53d5ff..00000000 --- a/src/threed/scene/qglpicknode.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLPICKNODE_H -#define QGLPICKNODE_H - -#include <QtCore/qobject.h> -#include "qt3dglobal.h" - -QT_BEGIN_NAMESPACE - -class QGLAbstractScene; -class QGLSceneNode; -class QEvent; - -class Q_QT3D_EXPORT QGLPickNode : public QObject -{ - Q_OBJECT -public: - explicit QGLPickNode(QGLAbstractScene *parent = 0); - int id() const { return m_id; } - void setId(int id) { m_id = id; } - - QGLSceneNode *target() const { return m_target; } - void setTarget(QGLSceneNode *target) { m_target = target; } - -Q_SIGNALS: - void pressed(); - void released(); - void clicked(); - void doubleClicked(); - void hoverChanged(); - -public Q_SLOTS: - -protected: - bool event(QEvent *e); - int m_id; - QGLSceneNode *m_target; -}; - -QT_END_NAMESPACE - -#endif // QGLPICKNODE_H diff --git a/src/threed/scene/qglrenderorder.cpp b/src/threed/scene/qglrenderorder.cpp deleted file mode 100644 index adaa5883..00000000 --- a/src/threed/scene/qglrenderorder.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglrenderorder.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QGLRenderOrder - \brief The QGLRenderOrder class represents an order of a scene node during rendering. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - The QGLRenderOrder class works with the QGLRenderSequencer to optimize - the rendering order of scene nodes. - - The class encapsulates the ordering with which QGLSceneNodes appear in the - rendering of a scene. Every scene node that has the same rendering properties - maps to the same QGLRenderOrder. - - QGLRenderOrder instances are based on a scene node, and the path through - the scene graph by which the node was reached. This is necessary since the - same node may appear with different rendering properties in multiple - different places in the rendering graph. - - For example a node holding a model of a pawn chess piece may appear in - several different places on a board, some with a white material and some - with a black material. - - To capture this concept QGLRenderOrder instances are constructed from a - pointer to a QGLSceneNode, and a QGLRenderState instance. - - A render order then calculates the effective values of its various attributes - based on both the node, and the state. - - Custom render orders may be created by sub-classing QGLRenderOrderComparator - and reimplementing the following methods: - \list - \i isEqualTo() - \i isLessThan() - \endlist - - By default all nodes which have the same effect type are rendered together, - and then within that, those nodes which have the same material are - rendered together. - - \sa QGLRenderOrderComparator -*/ - -/*! - \fn QGLRenderOrder::QGLRenderOrder(const QGLSceneNode *node, const QGLRenderState &state) - Creates a new QGLRenderOrder instance that encapsulates the order in this - render pass represented by the given \a node and \a state. The \a node - defaults to NULL, and the \a state defaults to a default constructed - invalid QGLRenderState. -*/ - -/*! - \fn QGLRenderOrder::~QGLRenderOrder() - Destroys this QGLRenderOrder and recovers any resources. -*/ - -/*! - Returns a hash value representing the effect set onto the node for - this render order. -*/ -uint QGLRenderOrder::effectHash() const -{ - quint64 result = 0; - if (effectiveHasEffect()) - { - QGLAbstractEffect *eff = effectiveUserEffect(); - if (eff) - result = reinterpret_cast<quint64>(eff); - else - result = effectiveStandardEffect() + 1; - Q_ASSERT(result); - } - return qHash(result); -} - -/*! - Returns true if this QGLRenderOrder is equal to the \a rhs, otherwise - returns false. Reimplement this function when creating a sub-class of - QGLRenderOrder. - - \sa isLessThan() -*/ -bool QGLRenderOrder::isEqual(const QGLRenderOrder &rhs) const -{ - if (this == &rhs) - return true; - bool result = false; - bool thisHasEffect = effectiveHasEffect(); - bool thatHasEffect = rhs.effectiveHasEffect(); - if (thisHasEffect && thatHasEffect) - { - QGLAbstractEffect *eff = effectiveUserEffect(); - if (eff) - result = (eff == rhs.effectiveUserEffect()); - else - result = (effectiveStandardEffect() == rhs.effectiveStandardEffect()); - } - else - { - result = (thisHasEffect == thatHasEffect); - } - if (result) - { - result = (effectiveMaterial() == rhs.effectiveMaterial()); - } - if (result) - { - result = (effectiveBackMaterial() == rhs.effectiveBackMaterial()); - } - return result; -} - -/*! - Returns true if this QGLRenderOrder is less than the \a rhs, otherwise - returns false. Reimplement this function when creating a sub-class of - QGLRenderOrder. - - The default implementation sorts first by effect, second by material (front - then back). - - Sorting by material is ordered by pointer comparison. - - Sorting by effect is based on the following order, from lowest to - highest: - \list - \o No effect - hasEffect() == true - \o Standard effect - ordered by numerical value, eg QGL::FlatColor < QGL::LitMaterial - \o User effect - ordered by pointer comparison - \endlist - So a node with \c{hasEffect() == false} node is \i{less than} a node with - a custom user effect, for example. - - \sa isEqual() -*/ -bool QGLRenderOrder::isLessThan(const QGLRenderOrder &rhs) const -{ - bool result = false; - bool thisHasEffect = effectiveHasEffect(); - bool thatHasEffect = rhs.effectiveHasEffect(); - if (thisHasEffect && thatHasEffect) - { - QGLAbstractEffect *eff = effectiveUserEffect(); - if (eff) - result = (eff < rhs.effectiveUserEffect()); - else - result = !rhs.effectiveUserEffect() && - (effectiveStandardEffect() < rhs.effectiveStandardEffect()); - } - else - { - result = !thisHasEffect; - } - if (!result) - { - result = (effectiveMaterial() < rhs.effectiveMaterial()); - } - if (!result) - { - result = (effectiveBackMaterial() < rhs.effectiveBackMaterial()); - } - return result; -} - -/*! - \fn bool QGLRenderOrder::isValid() const - Returns true if this is a valid QGLRenderOrder, that is it was - initialized with a non-null QGLSceneNode. -*/ - -/*! - \fn bool QGLRenderOrder::operator!=(const QGLRenderOrder &rhs) const - Returns true if this QGLRenderOrder is not equal to the \a rhs, otherwise - returns false. This function simply returns \c{!isEqual(rhs)}. -*/ - -/*! - \fn bool QGLRenderOrder::bool operator==(const QGLRenderOrder &rhs) const - Returns true if this QGLRenderOrder is equal to the \a rhs, otherwise - returns false. This function simply returns \c{isEqual(rhs)}. -*/ - -/*! - \fn bool QGLRenderOrder::operator<(const QGLRenderOrder &rhs) const - Returns true if this QGLRenderOrder is less than to the \a rhs, otherwise - returns false. This function simply returns \c{isLessThan(rhs)}. -*/ - -/*! - \fn const QGLSceneNode *QGLRenderOrder::node() const - Returns a pointer to the scene node for which the render order is held by - this QGLRenderOrder instance. This is simply the value passed to the - constructor. -*/ - -/*! - \fn QGLRenderState QGLRenderOrder::state() const - Returns a pointer to the render state for this order. This is simply the - value passed to the constructor. -*/ - -/*! - \fn void QGLRenderOrder::setState(const QGLRenderState &state) - Sets the \a state for this order. -*/ - -/*! - \fn QGLAbstractEffect *QGLRenderOrder::effectiveUserEffect() const - Returns the effective user effect of the node set for this render - order, taking into account any effect inherited from parent nodes - as specified by the render state(). - - \sa state(), effectiveHasEffect() -*/ - -/*! - \fn QGL::StandardEffect QGLRenderOrder::effectiveStandardEffect() const - Returns the effective standard effect of the node set for this render - order, taking into account any effect inherited from parent nodes - as specified by the render state(). - - \sa state(), effectiveHasEffect() -*/ - -/*! - \fn QGLMaterial *QGLRenderOrder::effectiveMaterial() const - Returns the effective material of the node set for this render - order, taking into account any effect inherited from parent nodes - as specified by the render state(). - - \sa state(), effectiveBackMaterial() -*/ - -/*! - \fn QGLMaterial *QGLRenderOrder::effectiveBackMaterial() const - Returns the effective back material of the node set for this render - order, taking into account any effect inherited from parent nodes - as specified by the render state(). - - \sa state(), effectiveMaterial() -*/ - -/*! - \fn bool QGLRenderOrder::effectiveHasEffect() const - Returns the effective value of whether an effect is set on the node - set for this render order, taking into account any effect inherited - from parent nodes as specified by the render state(). - - \sa state() -*/ - -/*! - \fn uint qHash(const QGLRenderOrder &order) - \relates QGLRenderOrder - Returns a hash value representation of the \a order. -*/ - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QGLRenderOrder &order) -{ - if (order.isValid()) - dbg << "QGLRenderOrder for node:" << order.node() - << "-- effect hash:" << order.effectHash() - << "-- material:" << order.node()->material() - << "-- back material:" << order.node()->backMaterial(); - else - dbg << "QGLRenderOrder -- invalid"; - return dbg; -} - -#endif - - -QT_END_NAMESPACE diff --git a/src/threed/scene/qglrenderorder.h b/src/threed/scene/qglrenderorder.h deleted file mode 100644 index 272f62f8..00000000 --- a/src/threed/scene/qglrenderorder.h +++ /dev/null @@ -1,203 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGLRENDERORDER_H -#define QGLRENDERORDER_H - -#include "qglscenenode.h" -#include "qglrenderstate.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt3D) - -class Q_QT3D_EXPORT QGLRenderOrder -{ -public: - explicit QGLRenderOrder(const QGLSceneNode *node = 0, const QGLRenderState &state = QGLRenderState()) - : m_node(node) - , m_state(state) - { - } - ~QGLRenderOrder() {} - - uint effectHash() const; - bool isEqual(const QGLRenderOrder &rhs) const; - bool isLessThan(const QGLRenderOrder &rhs) const; - inline bool isValid() const; - - inline bool operator!=(const QGLRenderOrder &rhs) const; - inline bool operator==(const QGLRenderOrder &rhs) const; - inline bool operator<(const QGLRenderOrder &rhs) const; - - inline const QGLSceneNode *node() const; - inline void setState(const QGLRenderState &state); - inline QGLRenderState state() const; - inline QGLAbstractEffect *effectiveUserEffect() const; - inline QGL::StandardEffect effectiveStandardEffect() const; - inline QGLMaterial *effectiveMaterial() const; - inline QGLMaterial *effectiveBackMaterial() const; - inline bool effectiveHasEffect() const; -private: - const QGLSceneNode *m_node; - QGLRenderState m_state; -}; - - -inline bool QGLRenderOrder::isValid() const -{ - return m_node; -} - -inline bool QGLRenderOrder::operator!=(const QGLRenderOrder &rhs) const -{ - return !isEqual(rhs); -} - -inline bool QGLRenderOrder::operator==(const QGLRenderOrder &rhs) const -{ - return isEqual(rhs); -} - -inline bool QGLRenderOrder::operator<(const QGLRenderOrder &rhs) const -{ - return isLessThan(rhs); -} - -inline const QGLSceneNode *QGLRenderOrder::node() const -{ - return m_node; -} - -inline QGLRenderState QGLRenderOrder::state() const -{ - return m_state; -} - -inline void QGLRenderOrder::setState(const QGLRenderState &state) -{ - m_state = state; -} - -inline QGLAbstractEffect *QGLRenderOrder::effectiveUserEffect() const -{ - QGLAbstractEffect *result = 0; - if (m_node) - { - if (m_node->userEffect()) - result = m_node->userEffect(); - else if (m_state.userEffect()) - result = m_state.userEffect(); - } - return result; -} - -inline QGL::StandardEffect QGLRenderOrder::effectiveStandardEffect() const -{ - QGL::StandardEffect result = QGL::FlatColor; - if (m_node) - { - if (m_node->hasEffect()) - result = m_node->effect(); - else if (m_state.hasEffect()) - result = m_state.standardEffect(); - } - return result; -} - -inline QGLMaterial *QGLRenderOrder::effectiveMaterial() const -{ - QGLMaterial *result = 0; - if (m_node) - { - if (m_node->material()) - result = m_node->material(); - else if (m_state.material()) - result = m_state.material(); - } - return result; -} - -inline QGLMaterial *QGLRenderOrder::effectiveBackMaterial() const -{ - QGLMaterial *result = 0; - if (m_node) - { - if (m_node->backMaterial()) - result = m_node->backMaterial(); - else if (m_state.backMaterial()) - result = m_state.backMaterial(); - } - return result; -} - -inline bool QGLRenderOrder::effectiveHasEffect() const -{ - bool result = false; - if (m_node) - { - if (m_node->hasEffect()) - result = true; - else - result = m_state.hasEffect(); - } - return result; -} - -inline uint qHash(const QGLRenderOrder &order) -{ - quint64 result = order.effectHash(); - return result ^ reinterpret_cast<quint64>(order.effectiveMaterial()); -} - -#ifndef QT_NO_DEBUG_STREAM -#include <QtCore/qdebug.h> -Q_QT3D_EXPORT QDebug operator<<(QDebug dbg, const QGLRenderOrder &order); -#endif - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QGLRENDERORDER_H diff --git a/src/threed/scene/qglrenderordercomparator.cpp b/src/threed/scene/qglrenderordercomparator.cpp deleted file mode 100644 index 8d41e0a4..00000000 --- a/src/threed/scene/qglrenderordercomparator.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglrenderordercomparator.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QGLRenderOrderComparator - \brief The QGLRenderOrderComparator class compares QGLRenderOrder instances. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - The QGLRenderOrderComparator class works with the QGLRenderSequencer and - QGLRenderOrder classes to optimize the rendering order of scene nodes. - - This class is responsible for comparing QGLRenderOrder instances for - the QGLRenderSequencer. - - Custom render orders may be created by sub-classing QGLRenderOrderComparator - and reimplementing the following method: - \list - \i bool operator()(const QGLRenderOrder &lhs, const QGLRenderOrder &rhs) - \endlist - - Then set an instance of your class onto QGLPainter: - - \code - void MyView::initializeGL(QGLPainter *painter) - { - painter->renderSequencer()->setRenderOrderComparator(new MyRenderOrderComparator); - } - - void MyView::paintGL(QGLPainter *painter) - { - // draw uses QGLRenderOrder sub-class instances from m_renderOrderFactory - complexScene->draw(painter); - } - \endcode - - See the QGLRenderOrder class documentation for more details. - - \sa QGLRenderOrder -*/ - -/*! - \fn QGLRenderOrderComparator::QGLRenderOrderComparator() - Construct a new QGLRenderOrderComparator. -*/ - -/*! - \fn QGLRenderOrderComparator::~QGLRenderOrderComparator() - Destroys this QGLRenderOrderComparator, recovering any resources. -*/ - -/*! - Returns true if the \a lhs render order is less than the \a rhs; - otherwise returns false. - - Reimplement this function when creating custom render orders. -*/ -bool QGLRenderOrderComparator::isLessThan(const QGLRenderOrder &lhs, const QGLRenderOrder &rhs) -{ - bool result = false; - bool lhsHasEffect = lhs.effectiveHasEffect(); - bool rhsHasEffect = rhs.effectiveHasEffect(); - if (lhsHasEffect && rhsHasEffect) - { - QGLAbstractEffect *eff = lhs.effectiveUserEffect(); - if (eff) - result = (eff < rhs.effectiveUserEffect()); - else - result = !rhs.effectiveUserEffect() && - (lhs.effectiveStandardEffect() < rhs.effectiveStandardEffect()); - } - else - { - result = !lhsHasEffect; - } - if (!result) - { - result = (lhs.effectiveMaterial() < rhs.effectiveMaterial()); - } - if (!result) - { - result = (lhs.effectiveBackMaterial() < rhs.effectiveBackMaterial()); - } - return result; -} - -/*! - Returns true if the \a lhs render order is equal to the \a rhs; - otherwise returns false. - - Reimplement this function when creating custom render orders. -*/ -bool QGLRenderOrderComparator::isEqualTo(const QGLRenderOrder &lhs, const QGLRenderOrder &rhs) -{ - bool result = false; - bool lhsHasEffect = lhs.effectiveHasEffect(); - bool rhsHasEffect = rhs.effectiveHasEffect(); - if (lhsHasEffect && rhsHasEffect) - { - QGLAbstractEffect *eff = lhs.effectiveUserEffect(); - if (eff) - result = (eff == rhs.effectiveUserEffect()); - else - result = (lhs.effectiveStandardEffect() == rhs.effectiveStandardEffect()); - } - else - { - result = (lhsHasEffect == rhsHasEffect); - } - if (result) - { - result = (lhs.effectiveMaterial() == rhs.effectiveMaterial()); - } - if (result) - { - result = (lhs.effectiveBackMaterial() == rhs.effectiveBackMaterial()); - } - return result; -} - -QT_END_NAMESPACE diff --git a/src/threed/scene/qglrenderordercomparator.h b/src/threed/scene/qglrenderordercomparator.h deleted file mode 100644 index 4ede60e9..00000000 --- a/src/threed/scene/qglrenderordercomparator.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLRenderOrderComparator_H -#define QGLRenderOrderComparator_H - -#include "qglrenderorder.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt3D) - -class QGLSceneNode; - -class Q_QT3D_EXPORT QGLRenderOrderComparator -{ -public: - QGLRenderOrderComparator() {} - virtual ~QGLRenderOrderComparator() {} - - virtual bool isLessThan(const QGLRenderOrder &lhs, const QGLRenderOrder &rhs); - virtual bool isEqualTo(const QGLRenderOrder &lhs, const QGLRenderOrder &rhs); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QGLRenderOrderComparator_H diff --git a/src/threed/scene/qglrendersequencer.cpp b/src/threed/scene/qglrendersequencer.cpp deleted file mode 100644 index 0a739ed0..00000000 --- a/src/threed/scene/qglrendersequencer.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglrendersequencer.h" -#include "qglrenderorder.h" -#include "qglpainter.h" -#include "qglrenderordercomparator.h" -#include "qglrenderstate.h" - -#include <QtCore/qstack.h> - -QT_BEGIN_NAMESPACE - -/*! - \class QGLRenderSequencer - \brief The QGLRenderSequencer class orders the rendering of QGLSceneNode instances. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - The QGLRenderSequencer class works with the QGLRenderOrderComparator and - QGLRenderOrder classes to optimize the rendering order of scene nodes. - - In general instances of this class are managed by QGLPainter and it should - not be necessary to explicitly create or manipulate them. - - The render sequencer works by tracking instances of QGLRenderOrder objects - in a queue. As the scene graph is traversed during a call to a top-level - node's QGLSceneNode::draw() function, the sequencer adds one QGLRenderOrder - to the queue for each unique combination of rendering attributes. - - The top level scene graph node loops once for each unique combination - it - does this in QGLSceneNode::draw() by calling nextInSequence(). At - each iteration, a current QGLRenderOrder is maintained, and only nodes - matching that order - as determined by \l{QGLRenderOrder::operator==()} - - are rendered in that pass. Non-matching nodes are added to a queue in the - order specified by \l{QGLRenderOrder::operator<()}. - - - Once an iteration/pass of - the scene graph is done, the next order is pulled from the front of the queue - and the current QGLRenderOrder is set to it. - - Since the rendering attributes at a node are a function both of that node, - and attributes inherited from its parents, and since a given node may appear - multiple times at different places in the scene, it can thus have different - attributes and orders in each place. So there is no one-to-one mapping - between nodes and attributes. - - To deal with this, QGLRenderOrder mappings are discovered during rendering. - There is no discovery pass. First, the initial QGLRenderOrder is lazily set - when the first geometry is actually drawn to the GPU - latching in that order - as the first current order. From that point, orders discovered that are - distinct from the current one are skipped in this rendering pass - by returning - false from renderInSequence() - and are instead added to the queue for rendering - on a subsequent pass. - - When the final pass has been made, renderInSequence() returns false to the - top level QGLSceneNode, indicating that looping over passes is complete. - - \sa QGLRenderOrder -*/ - -class QGLRenderSequencerPrivate -{ -public: - QGLRenderSequencerPrivate(QGLPainter *painter); - ~QGLRenderSequencerPrivate(); - QGLSceneNode *top; - QLinkedList<QGLRenderOrder> queue; - QStack<QGLRenderState> stack; - QSet<QGLRenderOrder> exclude; - QGLRenderOrder current; - QGLPainter *painter; - QGLRenderOrderComparator *compare; - bool latched; -}; - -QGLRenderSequencerPrivate::QGLRenderSequencerPrivate(QGLPainter *painter) - : top(0) - , current(QGLRenderOrder()) - , painter(painter) - , compare(new QGLRenderOrderComparator) - , latched(false) -{ -} - -QGLRenderSequencerPrivate::~QGLRenderSequencerPrivate() -{ - delete compare; -} - -/*! - Construct a new QGLRenderSequencer for the \a painter. -*/ -QGLRenderSequencer::QGLRenderSequencer(QGLPainter *painter) - : d(new QGLRenderSequencerPrivate(painter)) -{ -} - -/*! - Sets the render sequencer to operate on \a painter. -*/ -void QGLRenderSequencer::setPainter(QGLPainter *painter) -{ - d->painter = painter; -} - -/*! - Returns the current top node of the rendering tree, or NULL if the - sequencer has been reset. -*/ -QGLSceneNode *QGLRenderSequencer::top() const -{ - return d->top; -} - -/*! - Sets the current top node of the rendering tree to \a top. -*/ -void QGLRenderSequencer::setTop(QGLSceneNode *top) -{ - d->top = top; -} - -/*! - Reset this sequencer to start from the top of the scene graph again. - After this call the top() function will return NULL, and any scene - node passed to the renderInSequence() function will be treated as the - top of the scene graph. Also effects and materials will be ignored - until latched in - QGLPainter::draw() will call latch() to achieve this. - - \sa top() -*/ -void QGLRenderSequencer::reset() -{ - d->top = 0; - d->latched = false; - d->exclude.clear(); - d->stack.clear(); - d->current = QGLRenderOrder(); -} - -/*! - Returns true if there is a next rendering state in the queue; and if there - is a new order will be pulled from the queue, and its rendering attributes - - materials, effects and so on - will be applied to the painter for this - sequencer. Returns false when no more rendering states are queued and - scene is completely rendered. -*/ -bool QGLRenderSequencer::nextInSequence() -{ - bool nextAvailable = true; - if (d->queue.size() > 0) - { - // process thru next render order - d->current = d->queue.takeFirst(); - } - else - { - // end top level loop - nextAvailable = false; - } - return nextAvailable; -} - -/*! - Returns true, when this \a node should be rendered, in the order dictated - by QGLRenderOrder objects generated by the current render order Comparator. - The \a node must be non-NULL. - - When this function returns false, indicating that rendering should be - skipped for the current pass, a check is made to ensure that a state object - for this nodes rendering attributes is queued up for a later pass. - - To customize the ordering, reimplement QGLRenderOrder and - QGLRenderOrderComparator; then set the custom Comparator onto the current - painter using setcompare(). - - \sa reset(), top(), nextInSequence() -*/ -bool QGLRenderSequencer::renderInSequence(QGLSceneNode *node) -{ - Q_ASSERT(node); - Q_ASSERT(d->top); - bool doRender = true; - QGLRenderState state; - if (!d->stack.empty()) - state = d->stack.top(); - QGLRenderOrder o(node, state); - if (!d->current.isValid()) - d->current = o; - if (d->latched && !d->compare->isEqualTo(o, d->current)) - { - if (!d->exclude.contains(o)) - insertNew(o); - doRender = false; - } - else - { - if (!d->latched) - d->exclude.insert(o); - } - return doRender; -} - -/*! - Marks the render state for the \a node as started for this rendering pass. Call - this before rendering \a node, or any child nodes of \a node. - - Once the rendering state is no longer valid, call endState(). - - To actually apply the effective state, as inherited from previous calls to - beginState() call the applyState() function. - - \sa endState(), applyState() -*/ -void QGLRenderSequencer::beginState(QGLSceneNode *node) -{ - QGLRenderState state; - if (!d->stack.empty()) - state = d->stack.top(); - state.updateFrom(node); - d->stack.push(state); -} - -/*! - Marks the render state for the \a node as done for this rendering pass. - - If a node has called beginState(), then this function must be called to maintain - the rendering stack. If this function call is not matched by a previous - beginState() call undefined behaviour may result. In debug mode it may assert. - - \sa beginState(), applyState() -*/ -void QGLRenderSequencer::endState(QGLSceneNode *node) -{ -#ifndef QT_NO_DEBUG_STREAM - const QGLSceneNode *n = d->stack.top().node(); - Q_UNUSED(n); - Q_UNUSED(node); - Q_ASSERT(n == node); -#endif - d->stack.pop(); -} - -/*! - Applies the current rendering state to the painter for this sequencer. - - \sa beginState(), endState() -*/ -void QGLRenderSequencer::applyState() -{ - d->latched = true; - QGLRenderState s = d->stack.top(); - if (s.hasEffect() && !d->painter->isPicking()) - { - if (s.userEffect()) - { - if (d->painter->userEffect() != s.userEffect()) - d->painter->setUserEffect(s.userEffect()); - } - else - { - if (d->painter->userEffect() || - d->painter->standardEffect() != s.standardEffect()) - d->painter->setStandardEffect(s.standardEffect()); - } - } - if (s.material() && !d->painter->isPicking()) - { - QGLMaterial *mat = s.material(); - if (1) //FIXME: d->painter->faceMaterial(QGL::FrontFaces) != mat) - { - d->painter->setFaceMaterial(QGL::FrontFaces, mat); - int texUnit = 0; - for (int i = 0; i < mat->textureLayerCount(); ++i) - { - QGLTexture2D *tex = mat->texture(i); - if (tex) - { - d->painter->glActiveTexture(GL_TEXTURE0 + texUnit); - tex->bind(); - ++texUnit; - } - } - } - } -} - -void QGLRenderSequencer::insertNew(const QGLRenderOrder &order) -{ - QLinkedList<QGLRenderOrder>::iterator it = d->queue.begin(); - for ( ; it != d->queue.end(); ++it) - { - const QGLRenderOrder o = *it; - if (d->compare->isLessThan(order, o)) - break; - } - d->queue.insert(it, order); - d->exclude.insert(order); -} - -/*! - Returns the current render order comparator. By default this is an - instance of the base class QGLRenderOrderComparator. - - \sa setComparator() -*/ -QGLRenderOrderComparator *QGLRenderSequencer::comparator() const -{ - return d->compare; -} - -/*! - Sets the current render order \a comparator. This is only needed if a - custom rendering order is to be created. The argument \a comparator - must be non-null, or undefined behaviour will result. - - Any existing current comparator is destroyed. - - \sa renderInSequence(), comparator() -*/ -void QGLRenderSequencer::setComparator(QGLRenderOrderComparator *comparator) -{ - Q_ASSERT(comparator); - delete d->compare; - d->compare = comparator; -} - -QT_END_NAMESPACE diff --git a/src/threed/scene/qglrendersequencer.h b/src/threed/scene/qglrendersequencer.h deleted file mode 100644 index 55e7f1d7..00000000 --- a/src/threed/scene/qglrendersequencer.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGLRENDERSEQUENCER_H -#define QGLRENDERSEQUENCER_H - -#include <QtCore/qlinkedlist.h> -#include <QtCore/qset.h> - -#include "qglrenderorder.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt3D) - -class QGLSceneNode; -class QGLPainter; -class QGLRenderOrderComparator; -class QGLRenderSequencerPrivate; - -class Q_QT3D_EXPORT QGLRenderSequencer -{ -public: - explicit QGLRenderSequencer(QGLPainter *painter); - void setPainter(QGLPainter *painter); - bool renderInSequence(QGLSceneNode *node); - bool nextInSequence(); - void beginState(QGLSceneNode *node); - void endState(QGLSceneNode *node); - void reset(); - QGLSceneNode *top() const; - void setTop(QGLSceneNode *top); - QGLRenderOrderComparator *comparator() const; - void setComparator(QGLRenderOrderComparator *comparator); - void applyState(); -private: - void insertNew(const QGLRenderOrder &order); - - QGLRenderSequencerPrivate *d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QGLRENDERSEQUENCER_H diff --git a/src/threed/scene/qglrenderstate.cpp b/src/threed/scene/qglrenderstate.cpp deleted file mode 100644 index 4414dbce..00000000 --- a/src/threed/scene/qglrenderstate.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglrenderstate.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QGLRenderState - \brief The QGLRenderState class encapsulates the states of a rendering pass. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - The QGLRenderState class works with the QGLRenderOrder class to optimize - the rendering order of scene nodes. - - In general instances of this class are managed by the render sequencer - and it should not be necessary to explicitly create or manipulate them. - - A QGLRenderState instance encapsulates rendering properties for a given - path through the rendering process. The state includes properties such as - effects, and materials; which may either be directly set on a scene node, - or inherited from its parents. - - QGLRenderState may be subclassed in advanced applications to provide a - different inheritance pattern for rendering properties - reimplement the - updateFrom() function to do this. The default implementation simply sets - an effect on the state if the argument node has an effect (found by - calling the QGLSceneNode::hasEffect() function), and sets a material on - the state if the node has a non-null material; otherwise the existing - state is left as it is. - - The render sequencer will ensure that the relevant render state is set - onto the painter at the beginning of the pass which renders all nodes - with that state. - - \sa QGLRenderOrder -*/ - -class QGLRenderStatePrivate : public QSharedData -{ -public: - QGLRenderStatePrivate(); - ~QGLRenderStatePrivate(); - QGLRenderStatePrivate *clone() const; - - QBasicAtomicInt ref; - - bool hasEffect; - QGLMaterial *material; - QGLMaterial *backMaterial; - QGL::StandardEffect standardEffect; - QGLAbstractEffect *userEffect; - const QGLSceneNode *node; -}; - -QGLRenderStatePrivate::QGLRenderStatePrivate() - : hasEffect(false) - , material(0) - , backMaterial(0) - , standardEffect(QGL::FlatColor) - , userEffect(0) - , node(0) -{ - ref = 0; -} - -QGLRenderStatePrivate::~QGLRenderStatePrivate() -{ -} - -QGLRenderStatePrivate *QGLRenderStatePrivate::clone() const -{ - QGLRenderStatePrivate *r = new QGLRenderStatePrivate; - r->hasEffect = hasEffect; - r->material = material; - r->backMaterial = backMaterial; - r->standardEffect = standardEffect; - r->userEffect = userEffect; - r->node = node; - return r; -} - -/*! - Creates a new QGLRenderState empty of any values. -*/ -QGLRenderState::QGLRenderState() - : d(0) -{ -} - -/*! - Creates a new QGLRenderState as a copy of \a other -*/ -QGLRenderState::QGLRenderState(const QGLRenderState &other) - : d(other.d) -{ - if (d) - d->ref.ref(); -} - -/*! - Destroys this QGLRenderState recovering and resources. -*/ -QGLRenderState::~QGLRenderState() -{ - if (d && !d->ref.deref()) - delete d; -} - -/*! - Assigns this QGLRenderState to be a copy of \a rhs. -*/ -QGLRenderState &QGLRenderState::operator=(const QGLRenderState &rhs) -{ - if (d != rhs.d) - { - if (d && !d->ref.deref()) - delete d; - d = rhs.d; - if (d) - d->ref.ref(); - } - return *this; -} - -/*! - Sets the values of this QGLRenderState from the \a node, where - the node has a value. For example if the \a node has an effect - but no material, then this state will have its effect changed to - that of the node, but this state's material will be unchanged. -*/ -void QGLRenderState::updateFrom(const QGLSceneNode *node) -{ - detach(); - if (node->hasEffect()) - { - d->hasEffect = true; - if (node->userEffect()) - d->userEffect = node->userEffect(); - else - d->standardEffect = node->effect(); - } - if (node->material()) - d->material = node->material(); - if (node->backMaterial()) - d->backMaterial = node->backMaterial(); - d->node = node; -} - -/*! - Returns the user effect stored on this QGLRenderState, or null if no - user effect has been set. The default value is null. -*/ -QGLAbstractEffect *QGLRenderState::userEffect() const -{ - QGLAbstractEffect *e = 0; - if (d) - e = d->userEffect; - return e; -} - -/*! - Returns the standard effect stored on this QGLRenderState. The - default value is QGL::FlatColor. To determine if an effect has - been specifically set call hasEffect(). -*/ -QGL::StandardEffect QGLRenderState::standardEffect() const -{ - QGL::StandardEffect e = QGL::FlatColor; - if (d) - e = d->standardEffect; - return e; -} - -/*! - Returns true is there is a valid effect on this QGLRenderState. The - default value is false. -*/ -bool QGLRenderState::hasEffect() const -{ - bool r = false; - if (d) - r = d->hasEffect; - return r; -} - -/*! - Returns the material stored on this QGLRenderState, or null if no - material has been set. The default value is null. -*/ -QGLMaterial *QGLRenderState::material() const -{ - QGLMaterial *m = 0; - if (d) - m = d->material; - return m; -} - -/*! - Returns the back material stored on this QGLRenderState, or null if no - back material has been set. The default value is null. -*/ -QGLMaterial *QGLRenderState::backMaterial() const -{ - QGLMaterial *m = 0; - if (d) - m = d->backMaterial; - return m; -} - -/*! - Returns the node used to populate this QGLRenderState. -*/ -const QGLSceneNode *QGLRenderState::node() const -{ - const QGLSceneNode *s = 0; - if (d) - s = d->node; - return s; -} - -/*! - Returns true if this is a valid representation of a render state, that - is if it has ever been updated from a node; and false otherwise. -*/ -bool QGLRenderState::isValid() const -{ - if (d && d->node) - return true; - return false; -} - -/*! - \fn bool QGLRenderState::operator==(const QGLRenderState &rhs) const - Returns true if this state is equal to \a rhs, that is if each of the - materials, effects and values are equal to those of \a rhs. -*/ -void QGLRenderState::detach() -{ - if (!d) // lazy creation of data block - { - d = new QGLRenderStatePrivate; - d->ref.ref(); - } - else - { - if (d->ref > 1) // being shared, must detach - { - QGLRenderStatePrivate *temp = d->clone(); - d->ref.deref(); - d = temp; - d->ref.ref(); - } - } -} - -/*! - Returns a hash value representing this state. -*/ -uint QGLRenderState::hash() const -{ - const QByteArray bytes((const char *)d, sizeof(d)); - return qHash(bytes); -} - -#ifndef QT_NO_DEBUG_STREAM -Q_QT3D_EXPORT QDebug operator<<(QDebug dbg, const QGLRenderState &order) -{ - dbg << "QGLRenderState" << &order << "-- user effect:" << order.userEffect() - << "-- standardEffect:" << order.standardEffect() - << "-- hasEffect:" << order.hasEffect() - << "-- material:" << order.material() - << "-- back material:" << order.backMaterial() - << "-- node:" << order.node(); - return dbg; -} - -#endif - -QT_END_NAMESPACE diff --git a/src/threed/scene/qglrenderstate.h b/src/threed/scene/qglrenderstate.h deleted file mode 100644 index 2007f19b..00000000 --- a/src/threed/scene/qglrenderstate.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGLRENDERSTATE_H -#define QGLRENDERSTATE_H - -#include "qglnamespace.h" -#include "qglscenenode.h" - -#include <QtCore/qshareddata.h> - -QT_BEGIN_NAMESPACE - -class QGLAbstractEffect; -class QGLMaterial; - -class QGLRenderStatePrivate; - -class Q_QT3D_EXPORT QGLRenderState -{ -public: - QGLRenderState(); - QGLRenderState(const QGLRenderState &other); - virtual ~QGLRenderState(); - QGLRenderState &operator=(const QGLRenderState &rhs); - virtual void updateFrom(const QGLSceneNode *node); - QGLAbstractEffect *userEffect() const; - QGL::StandardEffect standardEffect() const; - bool hasEffect() const; - QGLMaterial *material() const; - QGLMaterial *backMaterial() const; - const QGLSceneNode *node() const; - uint hash() const; - bool operator==(const QGLRenderState &rhs) const - { - if (userEffect() != rhs.userEffect()) - return false; - if (standardEffect() != rhs.standardEffect()) - return false; - if (hasEffect() != rhs.hasEffect()) - return false; - if (material() != rhs.material()) - return false; - if (backMaterial() != rhs.backMaterial()) - return false; - return true; - } - bool isValid() const; -private: - void detach(); - QGLRenderStatePrivate *d; -}; - -inline uint qHash(const QGLRenderState &s) -{ - return s.hash(); -} - -#ifndef QT_NO_DEBUG_STREAM -#include <QtCore/qdebug.h> -Q_QT3D_EXPORT QDebug operator<<(QDebug dbg, const QGLRenderState &order); -#endif - -QT_END_NAMESPACE - -#endif // QGLRENDERSTATE_H diff --git a/src/threed/scene/qglsceneformatplugin.cpp b/src/threed/scene/qglsceneformatplugin.cpp deleted file mode 100644 index 787d3e45..00000000 --- a/src/threed/scene/qglsceneformatplugin.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglsceneformatplugin.h" -#include "qdownloadmanager.h" -#include "qabstractdownloadmanager.h" -#include "qthreadeddownloadmanager.h" -#include <QDebug> - -QT_BEGIN_NAMESPACE - -/*! - \class QGLSceneFormatHandler - \brief The QGLSceneFormatHandler class defines the common format I/O interface for loading 3D scene formats. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - \sa QGLSceneFormatPlugin -*/ - -class QGLSceneFormatHandlerPrivate -{ -public: - QGLSceneFormatHandlerPrivate() - { - device = 0; - m_scene = 0; - } - - QIODevice *device; - QString format; - QUrl url; - QGLAbstractScene *m_scene; -}; - -/*! - Constructs a 3D scene format handler. -*/ -QGLSceneFormatHandler::QGLSceneFormatHandler() -{ - d_ptr = new QGLSceneFormatHandlerPrivate(); - m_downloadManager = 0; -} - -/*! - Destroys this 3D scene format handler. -*/ -QGLSceneFormatHandler::~QGLSceneFormatHandler() -{ - delete d_ptr; -} - -/*! - Returns the device currently assigned to the 3D scene format handler. - Returns null if no device has been assigned. - - \sa setDevice() -*/ -QIODevice *QGLSceneFormatHandler::device() const -{ - return d_ptr->device; -} - -/*! - Sets the device for this 3D scene format handler to \a device. - The handler will use this device when reading 3D scenes. - - The device can only be set once and must be set before calling - read(). If you need to read multiple files, construct multiple - instances of the appropriate QGLSceneFormatHandler subclass. - - \sa device() -*/ -void QGLSceneFormatHandler::setDevice(QIODevice *device) -{ - d_ptr->device = device; -} - -/*! - Returns the format that is currently assigned to this 3D scene - format handler. Returns an empty string if no format has been assigned. - - \sa setFormat() -*/ -QString QGLSceneFormatHandler::format() const -{ - return d_ptr->format; -} - -/*! - Sets the format of this 3D scene format handler to \a format. - - \sa format() -*/ -void QGLSceneFormatHandler::setFormat(const QString& format) -{ - d_ptr->format = format; -} - -/*! - Returns the url of the data provided by device(). This is - typically used when the data in device() refers to additional - files that need to be located relative to the original - directory. - - \sa setUrl() -*/ -QUrl QGLSceneFormatHandler::url() const -{ - return d_ptr->url; -} - -/*! - Sets the \a url of the data provided by device(). - - \sa url() -*/ -void QGLSceneFormatHandler::setUrl(const QUrl& url) -{ - d_ptr->url = url; -} - -/*! - Decodes and applies \a options to this handler. Generally this will be - called by the QGLAbstractScene::loadScene() method prior to reading - the model data with read() or download(). Exactly what the string value may contain - and the meaning of the encoded options depends on each individual plugin. - - This default implementation simply does nothing. -*/ -void QGLSceneFormatHandler::decodeOptions(const QString &options) -{ - Q_UNUSED(options); -} - -/*! - \fn QGLAbstractScene *QGLSceneFormatHandler::read() - - Reads a 3D scene from device() and returns it. Returns null if - the format of device() is invalid and a scene could not be read. -*/ - -/*! - \fn QGLAbstractScene *QGLSceneFormatHandler::download() - - Reads a 3D scene from a url and returns a stub to it which can be used - the application, and will be updated with the full scene later. - - Returns NULL if the scene could not be created. -*/ - -/*! - \class QGLSceneFormatFactoryInterface - \brief The QGLSceneFormatFactoryInterface class provides the factory interface for QGLSceneFormatPlugin. - \internal -*/ - -/*! - \class QGLSceneFormatPlugin - \brief The QGLSceneFormatPlugin class defines an interface for loading 3D object and scene formats. - \ingroup qt3d - \ingroup qt3d::scene - - \sa QGLSceneFormatHandler -*/ - -/*! - Constructs a 3D scene format plugin with the given \a parent. This is - invoked automatically by the Q_EXPORT_PLUGIN2() macro. -*/ -QGLSceneFormatPlugin::QGLSceneFormatPlugin(QObject *parent) - : QObject(parent) -{ - //do nothing -} - -/*! - Destroys this 3D scene format plugin. This is invoked automatically - when the plugin is unloaded. -*/ -QGLSceneFormatPlugin::~QGLSceneFormatPlugin() -{ - //do nothing -} - -/*! - Initiates download of the specified scene. The scene must have been - previously specified with URL, options, format, and so on. This - function will then create a QGLAbstractDownloadManager instance and - submit the network request for the scene. - - The resultant data will be handled by the downloadComplete() slot. -*/ -void QGLSceneFormatHandler::downloadScene() -{ - if (!m_downloadManager) { - if (getenv(QT3D_MULTITHREAD)) { - //Download in a multithreaded environment - m_downloadManager = new QThreadedDownloadManager(); - } else { - //Download in a single threaded environment - m_downloadManager = new QDownloadManager(); - } - connect(m_downloadManager,SIGNAL(downloadComplete(QByteArray)), this, SLOT(downloadComplete(QByteArray))); - } - - if (!m_downloadManager->beginDownload(QUrl(url().toString()))) { - qWarning("Unable to issue asset download request."); - } -} - -/*! - Set the pointer for the scene \a theScene currently being processed. - This is specifically used during network loading. -*/ -void QGLSceneFormatHandler::setScene(QGLAbstractScene *theScene) -{ - d_ptr->m_scene = theScene; -} - -/*! - Get the pointer for the scene currently being processed. This is - specifically used during network loading. -*/ -QGLAbstractScene * QGLSceneFormatHandler::getScene() const -{ - return d_ptr->m_scene; -} - -/*! - This function should be called when the download of a remotely hosted - scene is complete. The \a sceneData will contain the relevant data for - the scene. - - The user is required to reimplement this if they intend to support network - loading of scenes in their plugin. -*/ -void QGLSceneFormatHandler::downloadComplete(QByteArray sceneData) -{ - Q_UNUSED(sceneData); - //unused - re-implement if you intend to support network - //loading of model files. -} - -/*! - Called at the end of the read() and download() functions, this function - completes any extra cleanup required, and sets the QGLSceneFormatHandler - it belongs to as being ready for deletion when the main event loop is next - processed. -*/ -void QGLSceneFormatHandler::finalize() - { - deleteLater(); - } - -/*! - \fn QStringList QGLSceneFormatPlugin::keys() const - - Returns the list of format keys this plugin supports. These keys - are usually the names of the 3D scene formats that are implemented in - the plugin (e.g., "3ds", "obj", etc). The returned elements must - be in lower case. - - \sa create() -*/ - -/*! - \fn QGLSceneFormatHandler *QGLSceneFormatPlugin::create(QIODevice *device, const QUrl& url, const QString &format) const - - Creates and returns a QGLSceneFormatHandler for handling the data in - \a device according to \a format. The \a url specifies the original - location of the data for resolving relative resource references. - - \sa keys() -*/ - -QT_END_NAMESPACE diff --git a/src/threed/scene/qglsceneformatplugin.h b/src/threed/scene/qglsceneformatplugin.h deleted file mode 100644 index 13ac067d..00000000 --- a/src/threed/scene/qglsceneformatplugin.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLSCENEFORMATPLUGIN_H -#define QGLSCENEFORMATPLUGIN_H - -#include "qt3dglobal.h" -#include <QObject> -#include <QtCore/qplugin.h> -#include <QtCore/qfactoryinterface.h> -#include <QtCore/qurl.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt3D) - -class QGLAbstractScene; -class QGLSceneFormatHandlerPrivate; -class QAbstractDownloadManager; - -class Q_QT3D_EXPORT QGLSceneFormatHandler : public QObject -{ - Q_OBJECT -public: - QGLSceneFormatHandler(); - virtual ~QGLSceneFormatHandler(); - - QIODevice *device() const; - void setDevice(QIODevice *device); - - QString format() const; - void setFormat(const QString& format); - - QUrl url() const; - void setUrl(const QUrl& url); - - virtual QGLAbstractScene *read() = 0; - virtual QGLAbstractScene *download() = 0; - - virtual void decodeOptions(const QString &options); - - void finalize(); - - void downloadScene(); - -public slots: - virtual void downloadComplete(QByteArray sceneData); -protected: - void setScene(QGLAbstractScene *theScene); - QGLAbstractScene * getScene() const; - - QAbstractDownloadManager *m_downloadManager; -private: - QGLSceneFormatHandlerPrivate *d_ptr; -}; - -struct Q_QT3D_EXPORT QGLSceneFormatFactoryInterface : public QFactoryInterface -{ - virtual QGLSceneFormatHandler *create(QIODevice *device, const QUrl& url, const QString &format = QString()) const = 0; -}; - -#define QGLSceneFormatFactoryInterface_iid \ - "com.trolltech.Qt.QGLSceneFormatFactoryInterface" -Q_DECLARE_INTERFACE(QGLSceneFormatFactoryInterface, QGLSceneFormatFactoryInterface_iid) - -class Q_QT3D_EXPORT QGLSceneFormatPlugin : public QObject, public QGLSceneFormatFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QGLSceneFormatFactoryInterface:QFactoryInterface) -public: - explicit QGLSceneFormatPlugin(QObject *parent = 0); - virtual ~QGLSceneFormatPlugin(); - - virtual QStringList keys() const = 0; - virtual QGLSceneFormatHandler *create(QIODevice *device, const QUrl& url, const QString &format = QString()) const = 0; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/threed/scene/qglscenenode.cpp b/src/threed/scene/qglscenenode.cpp deleted file mode 100644 index 545793fb..00000000 --- a/src/threed/scene/qglscenenode.cpp +++ /dev/null @@ -1,1884 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglabstractscene.h" -#include "qglscenenode.h" -#include "qglscenenode_p.h" -#include "qglpicknode.h" -#include "qglpainter.h" -#include "qgeometrydata.h" -#include "qglmaterialcollection.h" -#include "qglrendersequencer.h" -#include "qglabstracteffect.h" -#include "qgraphicstransform3d.h" - -#ifndef QT_NO_DEBUG_STREAM -#include "qglmaterialcollection.h" -#include "qgltexture2d.h" -#endif - -#include <QtGui/qmatrix4x4.h> -#if !defined(QT_NO_THREAD) -#include <QtCore/qthread.h> -#include <QtGui/qapplication.h> -#endif - -QT_BEGIN_NAMESPACE - -/*! - \class QGLSceneNode - \brief The QGLSceneNode class defines a node in a 3D scene. - \since 4.8 - \ingroup qt3d - \ingroup qt3d::scene - - QGLSceneNode represents one component of a scene. The QGLSceneNode - class manages materials, effects and transformations for itself and - for its child nodes. - - As a general approach to 3D applications, a tree of QGLSceneNodes may - be constructed, geometry added to them, materials and transformations - applied, all during application initialization; and then by simply - calling the draw() function the scene is easily rendered for each frame. - - \section1 Geometry - - Multiple QGLSceneNodes can reference the same geometry, whilst - applying different transformations and treatments to it. Since - QGLSceneNode is a QObject sub class it cannot be copied directly, so - instead use the clone() function for this purpose. - - A scene node allows referencing into sub-parts of geometry, via the start - and count properties. - - The start index is an offset into the geometry at which drawing will start. - The default start index is 0, so that drawing will start from the beginning - of the geometry. The count dictates how many vertices will be drawn. The - default count is 0, which instructs the underlying geometry to draw all - vertices. - - A node may have no geometry, that is \c{geometry().count() == 0}. This is - useful for example to have one node controlling or collecting together - several child nodes to be manipulated as a unit. - - \section1 Materials - - Also a node may have a local material. This allows drawing the same geometry - with different materials (which includes different textures). - - When accessing a QGLSceneNode via QML, or for simple applications, the - pointer based material functions are convenient and intuitive, saving the - trouble of adding the material pointer to the correct palette: - \list - \i material() - \i setMaterial() - \i backMaterial() - \i setBackMaterial() - \endlist - - For more complex applications; for example building model loaders, or for - larger scenes; where you need to explicitly manage materials via a palette, - use the index based functions: - \list - \i materialIndex() - \i setMaterialIndex() - \i backMaterialIndex() - \i setBackMaterialIndex() - \endlist - - The behaviour of both with respect to faces is the same - if a material() - is specified but no backMaterial() is specified, then the material() is - applied to both faces; if both material() and backMaterial() are non-null - then they are applied to their specific faces. - - \section1 Transformations - - Typically the local transformation matrix is set by the process that - constructed the node: in the case of an imported model, it is likely - to have been specified by the model file. To make individual changes - to the location or orientation of this node, use the position() and - transforms() properties. - - \section1 Scene Graph - - Use childNodes() to obtain the list of child nodes, and add and remove - child nodes by the addNode() and removeNode() methods. If a QGLSceneNode - is constructed with a QGLSceneNode parent, then addNode() will be - called implicitly on the parent. - - A child may be a child multiple times, a child may be under more than one - parent, and several parents may reference the same child. There is however - no protection against cycles, so a child must not be a parent of itself, - even if indirectly. - - A child node for the purposes of rendering means a child added via the - addNode() method. The default QGLSceneNode constructor will check to - see if its parent is a QGLSceneNode and add itself via the addNode() - function if it is. - - To help debug a scene, use the qDumpScene() function to get a printout - on stderr of the entire structure of the scene below the argument node. - - \section1 Debugging Lighting Normals - - The ViewNormals option is an advanced feature for use when inspecting - and debugging models or geometry in a scene. The lighting normals - are displayed as a straight line from the vertex pointing in - the direction of the lighting normal. This is useful for - example to show where normals are inverted or wrongly - calculated. - - The setting of the ViewNormals flag is not propagated to child nodes, - instead set the flag to true for the node or nodes where its - needed. To set the flag on all child nodes use code like: - - \code - foreach (QGLSceneNode *node, scene.allChildren()) - node->setNormalViewEnabled(true); - \endcode - - \image spiky-teapot.png - - \sa QGLAbstractScene -*/ - -/*! - \enum QGLSceneNode::Option - This enum defines option flags for QGLSceneNode. By default the none of the flags - are set, so the options() function returns QGLSceneNode::NoOptions - - \value NoOptions Do not enable any QGLSceneNode options. - \value CullBoundingBox Perform a cull using boundingBox() before - attempting to draw the geometry(). - \value ViewNormals Enables the display of lighting normals for - debugging purposes. - \value ReportCulling Send a signal when an object is displayed or culled. - \value HideNode Hide this node so it, and all its children, are excluded from rendering. - \sa setOptions() -*/ - -/*! - Constructs a new scene node and attaches it to \a parent. If parent is - a QGLSceneNode then this node is added to it as a child. -*/ -QGLSceneNode::QGLSceneNode(QObject *parent) - : QObject(parent) - , d_ptr(new QGLSceneNodePrivate()) -{ - QGLSceneNode *sceneParent = qobject_cast<QGLSceneNode*>(parent); - if (sceneParent) - sceneParent->addNode(this); -} - -/*! - \internal - Used by clone(). -*/ -QGLSceneNode::QGLSceneNode(QGLSceneNodePrivate *d, QObject *parent) - : QObject(parent) - , d_ptr(d) -{ - QGLSceneNode *sceneParent = qobject_cast<QGLSceneNode*>(parent); - if (sceneParent) - sceneParent->addNode(this); -} - -/*! - Constructs a new scene node referencing \a geometry and attaches it to - \a parent. If parent is a QGLSceneNode then this node is added to it - as a child. -*/ -QGLSceneNode::QGLSceneNode(const QGeometryData &geometry, QObject *parent) - : QObject(parent) - , d_ptr(new QGLSceneNodePrivate()) -{ - Q_D(QGLSceneNode); - d->geometry = geometry; - QGLSceneNode *sceneParent = qobject_cast<QGLSceneNode*>(parent); - if (sceneParent) - sceneParent->addNode(this); -} - -/*! - Destroys this scene node. -*/ -QGLSceneNode::~QGLSceneNode() -{ - Q_D(QGLSceneNode); - - // Detach ourselves from our children. The children will be - // deleted separately when their QObject::parent() deletes them. - for (int index = 0; index < d->childNodes.count(); ++index) - d->childNodes.at(index)->d_ptr->parentNodes.removeOne(this); - - // Detach ourselves from our remaining parents, and notify them - // to update their bounding boxes. This won't be needed if we - // are recursively destroying a tree of nodes because the parent - // already detached from this node above. - for (int index = 0; index < d->parentNodes.count(); ++index) { - QGLSceneNode *parent = d->parentNodes.at(index); - parent->d_ptr->childNodes.removeOne(this); - parent->invalidateBoundingBox(); - } -} - -/*! - Returns the drawing options associated with this node. - The default is 0 (no options set). - - \sa setOptions(), setOption() -*/ -QGLSceneNode::Options QGLSceneNode::options() const -{ - Q_D(const QGLSceneNode); - return d->options; -} - -/*! - \qmlproperty enumeration QGLSceneNode::options - - Defines the settings of various options configurabled on - nodes in the mesh. - - \list - \o NoOptions Use no options. This is the default. - \o CullBoundingBox Use the camera position to cull the whole node if possible. - \o ViewNormals Turn on normals debugging mode visually depict lighting normals. - \o ReportCulling Send a signal when an object is displayed or culled. - \endlist -*/ - -/*! - Sets the drawing \a options associated with this node. - - \sa options(), setOption() -*/ -void QGLSceneNode::setOptions(QGLSceneNode::Options options) -{ - Q_D(QGLSceneNode); - if (d->options != options) { - d->options = options; - emit updated(); - } -} - -/*! - Enables or disables \a option according to \a value. - - \sa options(), setOptions() -*/ -void QGLSceneNode::setOption(QGLSceneNode::Option option, bool value) -{ - Q_D(QGLSceneNode); - QGLSceneNode::Options opts = d->options; - if (value) - opts |= option; - else - opts &= ~option; - if (d->options != opts) { - d->options = opts; - emit updated(); - } -} - -/*! - Returns the geometry associated with this node, or a null QGeometryData - if no geometry has been associated with it. - - \sa setGeometry() -*/ -QGeometryData QGLSceneNode::geometry() const -{ - Q_D(const QGLSceneNode); - return d->geometry; -} - -/*! - Sets the geometry associated with this node to be \a geometry. - Typically the \a geometry will be some type of mesh object. The - default implementation of the QGLSceneNode::draw() method will call - the geometry's draw() method. - - \sa geometry() -*/ -void QGLSceneNode::setGeometry(QGeometryData geometry) -{ - Q_D(QGLSceneNode); - d->geometry = geometry; - emit updated(); -} - -/*! - Returns a bounding box for the portion of the geometry referenced by - this scene node. If the value of start() is 0, and count() is the same - as geometry()->size() then the bounding box will be the same as - geometry()->boundingBox(). However if the scene node only references - some part of the geometry, a bounding box for this section is calculated. - - If this scene node has child nodes then the bounding box will be the - calculated union of the bounding box for this nodes geometry (if any) and - the bounding boxes of the children. - - The calculated value is cached and returned on subsequent calls, but - could be expensive to calculate initially. -*/ -QBox3D QGLSceneNode::boundingBox() const -{ - Q_D(const QGLSceneNode); - if (d->boxValid) - return d->bb; - d->bb = QBox3D(); - if (d->geometry.count() > 0) - { - if (d->start == 0 && (d->count == d->geometry.count() || d->count == 0)) - { - d->bb = d->geometry.boundingBox(); - } - else - { - QGL::IndexArray indices = d->geometry.indices(); - for (int i = d->start; i < (d->start + d->count); ++i) - { - int ix = indices.at(i); - d->bb.unite(d->geometry.vertexAt(ix)); - } - } - } - QList<QGLSceneNode*>::const_iterator it = d->childNodes.constBegin(); - for ( ; it != d->childNodes.constEnd(); ++it) - { - QGLSceneNode *n = *it; - QBox3D b = n->boundingBox(); - d->bb.unite(b); - } - d->bb.transform(transform()); - d->boxValid = true; - return d->bb; -} - -// Calculate the resulting matrix from the position, local transform, -// and list of transforms. -QMatrix4x4 QGLSceneNode::transform() const -{ - Q_D(const QGLSceneNode); - QMatrix4x4 m; - if (!d->translate.isNull()) - m.translate(d->translate); - if (!d->localTransform.isIdentity()) - m *= d->localTransform; - for (int index = d->transforms.size() - 1; index >= 0; --index) - d->transforms.at(index)->applyTo(&m); - return m; -} - -/*! - Returns the local transform associated with this node. If no - local transform has been explicitly set, this method returns a - QMatrix4x4 set to the identity matrix. - - The local transform is typically set during model loading or - geometry construction, and is a feature of the geometry. - - In general to change the location or orientation of the node - use the position() or transforms() properties instead. - - \sa setLocalTransform(), position(), transforms() -*/ -QMatrix4x4 QGLSceneNode::localTransform() const -{ - Q_D(const QGLSceneNode); - return d->localTransform; -} - -/*! - Sets the local transform associated with this node to be \a transform. - The default implementation of the QGLSceneNode::draw() method will - apply this transform to the QGLPainter before drawing any geometry. - - \sa localTransform() -*/ -void QGLSceneNode::setLocalTransform(const QMatrix4x4 &transform) -{ - Q_D(QGLSceneNode); - if (d->localTransform != transform) - { - d->localTransform = transform; - emit updated(); - invalidateTransform(); - } -} - -/*! - \property QGLSceneNode::position - \brief The amounts of x, y and z axis translation for this node. - - Since most nodes are situated relative to \c{(0, 0, 0)} when imported as - part of a model or constructed programatically, the translation is - effectively the position of the model in the scene. - - The x, y and z axis translations can also be specified individually as - separate properties \l x, \l y, and \l z - - \sa x(), y(), z() -*/ -QVector3D QGLSceneNode::position() const -{ - Q_D(const QGLSceneNode); - return d->translate; -} - -void QGLSceneNode::setPosition(const QVector3D &p) -{ - Q_D(QGLSceneNode); - if (p != d->translate) - { - d->translate = p; - emit updated(); - invalidateTransform(); - } -} - -/*! - \property QGLSceneNode::x - \brief The amount of x axis translation for this node. - - \sa position() -*/ -qreal QGLSceneNode::x() const -{ - Q_D(const QGLSceneNode); - return d->translate.x(); -} - -void QGLSceneNode::setX(qreal x) -{ - Q_D(QGLSceneNode); - if (x != d->translate.x()) - { - d->translate.setX(x); - emit updated(); - invalidateTransform(); - } -} - -/*! - \property QGLSceneNode::y - \brief The amount of y axis translation for this node. - - \sa position() -*/ -qreal QGLSceneNode::y() const -{ - Q_D(const QGLSceneNode); - return d->translate.y(); -} - -void QGLSceneNode::setY(qreal y) -{ - Q_D(QGLSceneNode); - if (y != d->translate.y()) - { - d->translate.setY(y); - emit updated(); - invalidateTransform(); - } -} - -/*! - \property QGLSceneNode::z - \brief The amount of z axis translation for this node. - - \sa position() -*/ -qreal QGLSceneNode::z() const -{ - Q_D(const QGLSceneNode); - return d->translate.z(); -} - -void QGLSceneNode::setZ(qreal z) -{ - Q_D(QGLSceneNode); - if (z != d->translate.z()) - { - d->translate.setZ(z); - emit updated(); - invalidateTransform(); - } -} - -/*! - Returns the list of transformations to apply to this node. - The default is the empty list. - - The transformations are applied to the node itself, so a - QGraphicsScale3D followed by a QGraphicsTranslation3D will - first scale the node in its local co-ordinate system, - and then translate the node a new location. - - In the mathematical sense, the transformations are applied to - the modelview matrix in the reverse order in which they appear - in this list. - - The position() is applied after all other transformations - have been applied. - - \sa setTransforms(), addTransform(), position() -*/ -QList<QGraphicsTransform3D *> QGLSceneNode::transforms() const -{ - Q_D(const QGLSceneNode); - return d->transforms; -} - -/*! - Sets the list of transformations to apply to this node to \a transforms. - - The transformations are applied to the node itself, so a - QGraphicsScale3D followed by a QGraphicsTranslation3D will - first scale the node in its local co-ordinate system, - and then translate the node a new location. - - In the mathematical sense, the transformations are applied to - the modelview matrix in the reverse order in which they appear - in \a transforms. - - The position() is applied after all other transformations - have been applied. - - \sa transforms(), addTransform(), position() -*/ -void QGLSceneNode::setTransforms(const QList<QGraphicsTransform3D *> &transforms) -{ - Q_D(QGLSceneNode); - for (int index = 0; index < d->transforms.size(); ++index) { - QGraphicsTransform3D *transform = d->transforms.at(index); - disconnect(transform, SIGNAL(transformChanged()), this, SLOT(transformChanged())); - } - d->transforms.clear(); - for (int index = 0; index < transforms.size(); ++index) { - QGraphicsTransform3D *transform = transforms.at(index); - if (transform) { - connect(transform, SIGNAL(transformChanged()), this, SLOT(transformChanged())); - d->transforms.append(transform); - } - } - emit updated(); - invalidateTransform(); -} - -/*! - Adds a single \a transform to this node, to be applied to the - node after all current members of transformations() have been applied. - - In the mathematical sense, \a transform is applied to the modelview - matrix before the current members of transformations() are applied - in reverse order. - - \sa transforms(), setTransforms() -*/ -void QGLSceneNode::addTransform(QGraphicsTransform3D *transform) -{ - Q_D(QGLSceneNode); - if (!transform) - return; // Avoid nulls getting into the transform list. - connect(transform, SIGNAL(transformChanged()), this, SLOT(transformChanged())); - d->transforms.append(transform); - emit updated(); - invalidateTransform(); -} - -/*! - \internal -*/ -void QGLSceneNode::transformChanged() -{ - invalidateTransform(); - emit updated(); -} - -/*! - Returns the drawing mode to use to render geometry(). The default - is QGL::Triangles. - - \sa setDrawingMode() -*/ -QGL::DrawingMode QGLSceneNode::drawingMode() const -{ - Q_D(const QGLSceneNode); - return d->drawingMode; -} - -/*! - Sets the drawing \a mode to use to render geometry(). - - Note: this function changes the drawing mode, but the underlying - geometry() still consists of the triangles that were added. - Thus, this function is only useful for converting the drawing mode - into QGL::Points to display the geometry() as a point cloud - instead of a triangle mesh. The other enums from QGL::DrawingMode - will give unpredictable results. - - \sa drawingMode() -*/ -void QGLSceneNode::setDrawingMode(QGL::DrawingMode mode) -{ - Q_D(QGLSceneNode); - if (d->drawingMode != mode) - { - d->drawingMode = mode; - emit updated(); - } -} - -/*! - Returns the drawing width for this node. - - Drawing width is used only when drawing lines or points (ie. when - the drawing mode is points, lines, line-strips, etc). - - \sa drawingMode() -*/ -qreal QGLSceneNode::drawingWidth() const -{ - Q_D(const QGLSceneNode); - return d->drawingWidth; -} - -/*! - Sets the drawing \a width to the given value. - - Drawing width is used only when drawing lines or points (ie. when - the drawing mode is points, lines, line-strips, etc). - - \sa drawingMode() -*/ -void QGLSceneNode::setDrawingWidth(qreal width) -{ - Q_D(QGLSceneNode); - d->drawingWidth = width; -} - - -/*! - Returns the local effect associated with this node. The default value - is QGL::FlatColor. If the value of hasEffect() is false, then this - the value of effect() is ignored. - - \sa setEffect(), hasEffect() -*/ -QGL::StandardEffect QGLSceneNode::effect() const -{ - Q_D(const QGLSceneNode); - return d->localEffect; -} - -/*! - Sets the local effect associated with this node to be \a effect. hasEffect() - will return true after calling this method. - - The QGLSceneNode::draw() function will ensure that \a effect is applied to the - QGLPainter before drawing any geometry. - - \sa effect(), hasEffect() -*/ -void QGLSceneNode::setEffect(QGL::StandardEffect effect) -{ - Q_D(QGLSceneNode); - if (d->localEffect != effect || !d->hasEffect) { - d->localEffect = effect; - d->hasEffect = true; - emit updated(); - } -} - -/*! - Returns the user effect associated with this node, or NULL if one is not - set. The default value is NULL. If the value of hasEffect() is false, - then this effect is ignored. - - \sa setUserEffect(), hasEffect() -*/ -QGLAbstractEffect *QGLSceneNode::userEffect() const -{ - Q_D(const QGLSceneNode); - return d->customEffect; -} - -/*! - Sets the local effect associated with this node to be the custom - \a effect. hasEffect() will return true after calling this method. - - This custom effect will supersede any standard effect. - - The default implementation of QGLSceneNode::apply() will set this effect - during initialization of the model. - - The default implementation of the QGLSceneNode::draw() method will - ensure that \a effect is applied to the QGLPainter before drawing - any geometry. - - \sa userEffect(), hasEffect() -*/ -void QGLSceneNode::setUserEffect(QGLAbstractEffect *effect) -{ - Q_D(QGLSceneNode); - if (d->customEffect != effect || !d->hasEffect) { - d->customEffect = effect; - d->hasEffect = true; - emit updated(); - } -} - - - /*! - Returns true if the local effect on this node is enabled, otherwise - returns false. - - \sa setEffectEnabled(), setEffect() - */ -bool QGLSceneNode::hasEffect() const -{ - Q_D(const QGLSceneNode); - return d->hasEffect; -} - -/*! - Sets whether the current value of effect() or userEffect() will be - applied to the QGLPainter prior to drawing. If \a enabled is true, - then the effect is applied, otherwise it is not. - - \sa setEffect(), effect(), hasEffect() -*/ -void QGLSceneNode::setEffectEnabled(bool enabled) -{ - Q_D(QGLSceneNode); - if (d->hasEffect != enabled) { - d->hasEffect = enabled; - emit updated(); - } -} - -/*! - Returns the starting index within geometry() that should be used - to render fragments for this scene node. The default value is 0, - indicating that the 0'th logical vertex in geometry() is the start. - - \sa setStart(), count() -*/ -int QGLSceneNode::start() const -{ - Q_D(const QGLSceneNode); - return d->start; -} - -/*! - Sets the \a start index within geometry() that should be used - to render fragments for this scene node. - - \sa start(), setCount() -*/ -void QGLSceneNode::setStart(int start) -{ - Q_D(QGLSceneNode); - if (start != d->start) - { - d->start = start; - emit updated(); - invalidateBoundingBox(); - } -} - -/*! - Returns the count of the vertices to render from geometry() - for this scene node. The default is zero, meaning that this node - uses all vertices from start() up to the last logical vertex - in the underlying geometry(). - - \sa setCount(), start() -*/ -int QGLSceneNode::count() const -{ - Q_D(const QGLSceneNode); - return d->count; -} - -/*! - Sets the \a count of the vertices to render from geometry() - for this scene node. - - \sa count(), setStart() -*/ -void QGLSceneNode::setCount(int count) -{ - Q_D(QGLSceneNode); - if (count != d->count) - { - d->count = count; - emit updated(); - invalidateBoundingBox(); - } -} - -/*! - Returns the material index for this scene node. - - \sa setMaterialIndex() -*/ -int QGLSceneNode::materialIndex() const -{ - Q_D(const QGLSceneNode); - return d->material; -} - -/*! - Sets the material index for this scene node to \a material. - - \sa materialIndex() -*/ -void QGLSceneNode::setMaterialIndex(int material) -{ - Q_D(QGLSceneNode); - if (d->material != material) { - d->material = material; - emit updated(); - } -} - -/*! - Returns the back material index for this scene node. - - \sa setBackMaterialIndex() -*/ -int QGLSceneNode::backMaterialIndex() const -{ - Q_D(const QGLSceneNode); - return d->backMaterial; -} - -/*! - Sets the back material index for this scene node to \a material. - - \sa materialIndex() -*/ -void QGLSceneNode::setBackMaterialIndex(int material) -{ - Q_D(QGLSceneNode); - if (d->backMaterial != material) { - d->backMaterial = material; - emit updated(); - } -} - -/*! - \property QGLSceneNode::material - \brief This property is a pointer to a QGLMaterial instance for this node. - - This material is applied to all faces if the backMaterial() property - is set to null, which is the default. If the backMaterial() property is non-null - then this material is only applied to the front faces. - - To apply a material to the back faces use the backMaterial() property. - - Getting this property is exactly equivalent to - \c{palette()->material(materialIndex())}. - - Setting this property causes the material if not already in this nodes palette to be - added, and then the corresponding index to be set for this scene node. - - Setting this property is equivalent to: - \code - int index = d->palette->indexOf(material); - if (index == -1) - index = d->palette->addMaterial(material); - setMaterialIndex(index); - \endcode - - If setting this property, when no palette exists one is created, as a - convenience - but this is suitable only for experimental code and for - \bold{very small numbers of nodes}. In debug mode a warning is - printed in this case. - - Generally one common palette should be created, and set on each node. This - also allows nodes to share materials and their textures. - - \sa materialIndex(), setMaterialIndex() -*/ -QGLMaterial *QGLSceneNode::material() const -{ - Q_D(const QGLSceneNode); - if (d->palette) - return d->palette->material(d->material); - return 0; -} - -void QGLSceneNode::setMaterial(QGLMaterial *material) -{ - Q_D(QGLSceneNode); - if (!d->palette) - d->palette = new QGLMaterialCollection(this); - int ix = d->palette->indexOf(material); - if (ix == -1) - ix = d->palette->addMaterial(material); - setMaterialIndex(ix); -} - -/*! - \property QGLSceneNode::backMaterial - \brief This property is a pointer to any QGLMaterial instance for this node's back faces. - - This material is applied to the back faces, if non-null. The default value - of this property is null. When this property is null, any non-null material - set on the material() property will be applied to front and back faces. - - To apply a material to the front faces use the material() property. - - Getting this property is exactly equivalent to - \c{palette()->material(backMaterialIndex())}. - - Setting this property causes the material if not already in this nodes palette to be - added, and then the corresponding index to be set for this scene node. - - Setting this property is exactly equivalent to: - \code - int index = d->palette->indexOf(material); - if (index == -1) - index = d->palette->addMaterial(material); - setBackMaterialIndex(index); - \endcode -*/ -QGLMaterial *QGLSceneNode::backMaterial() const -{ - Q_D(const QGLSceneNode); - if (d->palette) - return d->palette->material(d->backMaterial); - return 0; -} - -void QGLSceneNode::setBackMaterial(QGLMaterial *material) -{ - Q_D(QGLSceneNode); - if (!d->palette) - d->palette = new QGLMaterialCollection(this); - int ix = d->palette->indexOf(material); - if (ix == -1) - ix = d->palette->addMaterial(material); - setBackMaterialIndex(ix); -} -/*! - Returns the palette of materials used by this scene node, or NULL - if no palette has been set. - - \sa setPalette() -*/ -QGLMaterialCollection *QGLSceneNode::palette() const -{ - Q_D(const QGLSceneNode); - return d->palette; -} - -/*! - Sets the palette of materials for this scene node to \a palette. - - \sa palette() -*/ -void QGLSceneNode::setPalette(QGLMaterialCollection *palette) -{ - Q_D(QGLSceneNode); - if (d->palette != palette) { - d->palette = palette; - emit updated(); - } -} - -/*! - Returns a list of the child nodes for this node. This list is not - recursively generated, it includes only the nodes which are - immediate children of this node. - - \sa allChildren() -*/ -QList<QGLSceneNode*> QGLSceneNode::children() const -{ - Q_D(const QGLSceneNode); - return d->childNodes; -} - -/*! - Returns a list including recursively all child nodes under - this node. Each child node only appears once, even if it is included - multiple times in the scene graph. - - \sa children() -*/ -QList<QGLSceneNode*> QGLSceneNode::allChildren() const -{ - Q_D(const QGLSceneNode); - QList<QGLSceneNode*> allSceneNodes; - QList<QGLSceneNode*> gather; - QList<QGLSceneNode*>::const_iterator it = d->childNodes.constBegin(); - for ( ; it != d->childNodes.constEnd(); ++it) - if (!gather.contains(*it)) - gather.append(*it); - while (gather.count() > 0) - { - QGLSceneNode *node = gather.takeFirst(); - if (!allSceneNodes.contains(node)) - { - allSceneNodes.append(node); - gather.append(node->children()); - } - } - return allSceneNodes; -} - -/*! - Adds the \a node to the list of child nodes for this node. - - This function does nothing if \a node is null or is already a child - of this node. If the \a node is the node itself, a warning about an - attempt to add a node to itself is printed, and no add takes place. - - If the aim is to have the same geometry displayed several times under a - given node, each time with different transformations, use the clone() - call to create copies of the node and then apply the transformations to - the copies. - - Alternatively, create modifier nodes with the transformations and add the - geometry bearing node to each with addNode(): - \code - QGLBuilder builder; - builder << CarWheel(5.0f); // some car wheel geometry - QGLSceneNode wheel = builder.finalizedSceneNode(); - QGLSceneNode frontLeft = new QGLSceneNode(m_sceneRoot); - frontLeft->addNode(wheel); - frontLeft->setPosition(QVector3D(1.0f, 2.0f, 0.0f)); - QGLSceneNode frontRight = new QGLSceneNode(m_sceneRoot); - frontRight->addNode(wheel); - frontRight->setPosition(QVector3D(-1.0f, 2.0f, 0.0f)); - QGLSceneNode backLeft = new QGLSceneNode(m_sceneRoot); - backLeft->addNode(wheel); - backLeft->setPosition(QVector3D(1.0f, -2.0f, 0.0f)); - QGLSceneNode backRight = new QGLSceneNode(m_sceneRoot); - backRight->addNode(wheel); - backRight->setPosition(QVector3D(-1.0f, -2.0f, 0.0f)); - \endcode - - Because a child node can be validly added to many different nodes, - calling addNode() does not normally affect the QObject::parent() - ownership. However, if \a node does not currently have a - QObject::parent(), the parent will be set to this node. - - \sa removeNode(), clone(), addNodes() -*/ -void QGLSceneNode::addNode(QGLSceneNode *node) -{ - Q_D(QGLSceneNode); - bool alreadyAdded = node && node->d_ptr->parentNodes.contains(this); - if (!node || node == this || alreadyAdded) - return; // Invalid node, or already under this parent. - invalidateBoundingBox(); - d->childNodes.append(node); - node->d_ptr->parentNodes.append(this); - if (!node->parent()) - node->setParent(this); - connect(node, SIGNAL(updated()), this, SIGNAL(updated())); - emit updated(); -} - -/*! - Adds the members of \a nodes to the list of child nodes - for this node. - - \sa addNode(), removeNodes() -*/ -void QGLSceneNode::addNodes(const QList<QGLSceneNode *> &nodes) -{ - Q_D(QGLSceneNode); - for (int index = 0; index < nodes.count(); ++index) { - QGLSceneNode *node = nodes.at(index); - if (!node || node->d_ptr->parentNodes.contains(this)) - continue; // Invalid node, or already under this parent. - d->childNodes.append(node); - node->d_ptr->parentNodes.append(this); - if (!node->parent()) - node->setParent(this); - connect(node, SIGNAL(updated()), this, SIGNAL(updated())); - } - invalidateBoundingBox(); - emit updated(); -} - -/*! - Removes the child node matching \a node from this node. - - If the QObject::parent() ownership of \a node was set to this - node, then its parent will be changed to another parent node if it - had multiple parents. - - If \a node had only a single parent, then its parent will be set to null, - effectively detaching it from the QObject ownership rules of the scene - graph. The caller is then responsible for deleting \a node. - - If the QObject::parent() of \a node was not a scene node parent, - then it will be left unmodified. - - \sa addNode(), removeNodes() -*/ -void QGLSceneNode::removeNode(QGLSceneNode *node) -{ - Q_D(QGLSceneNode); - if (!node || !node->d_ptr->parentNodes.contains(this)) - return; // Invalid node or not attached to this parent. - d->childNodes.removeOne(node); - node->d_ptr->parentNodes.removeOne(this); - if (node->parent() == this) { - // Transfer QObject ownership to another parent, or null. - if (!node->d_ptr->parentNodes.isEmpty()) - node->setParent(node->d_ptr->parentNodes[0]); - else - node->setParent(0); - } - disconnect(node, SIGNAL(updated()), this, SIGNAL(updated())); - invalidateBoundingBox(); - emit updated(); -} - -/*! - Removes the members of \a nodes from the list of child nodes - for this node. - - \sa removeNode(), addNodes() -*/ -void QGLSceneNode::removeNodes(const QList<QGLSceneNode *> &nodes) -{ - Q_D(QGLSceneNode); - for (int index = 0; index < nodes.count(); ++index) { - QGLSceneNode *node = nodes.at(index); - if (!node || !node->d_ptr->parentNodes.contains(this)) - continue; // Invalid node or not attached to this parent. - d->childNodes.removeOne(node); - node->d_ptr->parentNodes.removeOne(this); - if (node->parent() == this) { - // Transfer QObject ownership to another parent, or null. - if (!node->d_ptr->parentNodes.isEmpty()) - node->setParent(node->d_ptr->parentNodes[0]); - else - node->setParent(0); - } - disconnect(node, SIGNAL(updated()), this, SIGNAL(updated())); - } - invalidateBoundingBox(); - emit updated(); -} - -void QGLSceneNode::invalidateBoundingBox() const -{ - Q_D(const QGLSceneNode); - d->boxValid = false; - d->invalidateParentBoundingBox(); -} - -void QGLSceneNode::invalidateTransform() const -{ - invalidateBoundingBox(); -} - -void QGLSceneNode::drawNormalIndicators(QGLPainter *painter) -{ - Q_D(QGLSceneNode); - QVector3DArray verts; - QGL::IndexArray indices = d->geometry.indices(); - for (int i = d->start; i < (d->start + d->count); ++i) - { - int ix = indices[i]; - QVector3D a = d->geometry.vertexAt(ix); - QVector3D b = a + d->geometry.normalAt(ix); - verts.append(a, b); - } - painter->setVertexAttribute(QGL::Position, QGLAttributeValue(verts)); - glLineWidth(2.0f); - painter->draw(QGL::Lines, verts.size()); -} - -const QGLMaterial *QGLSceneNode::setPainterMaterial(int material, QGLPainter *painter, - QGL::Face faces, bool &changedTex) -{ - Q_D(QGLSceneNode); - QGLMaterial *mat = d->palette->material(material); - const QGLMaterial *saveMat = 0; - if (painter->faceMaterial(faces) != mat) - { - saveMat = painter->faceMaterial(faces); - painter->setFaceMaterial(faces, mat); - int texUnit = 0; - for (int i = 0; i < mat->textureLayerCount(); ++i) - { - QGLTexture2D *tex = mat->texture(i); - if (tex) - { - painter->glActiveTexture(GL_TEXTURE0 + texUnit); - tex->bind(); - changedTex = true; - ++texUnit; - } - } - } - return saveMat; -} - -/*! - Draws the geometry of the node onto the \a painter. - - This is the function which performs the actual drawing step in the - draw function below. - - \list - \o calls draw(start, count) on this nodes geometry object (if any) - \endlist - - Override this function to perform special processing on this node, - after transformation & culling are applied and before sequencing of - materials & effects are done; but just before (or after) the - actual draw step. - - This default implementation simply draws the nodes geometry onto - the painter. - - Example: - \code - void MySpecialNode::geometryDraw(QGLPainter *painter) - { - // at this point the node has survived culling, the model-view - // matrix is transformed into this nodes frame of reference, - // materials & effects have been applied as this node appears - // in its place in the render sequence - - doMySpecialProcessing(); - - // call parent implementation to do actual draw - QGLSceneNode::geometryDraw(painter); - } - \endcode -*/ -void QGLSceneNode::drawGeometry(QGLPainter *painter) -{ - Q_D(QGLSceneNode); - if (d->count && d->geometry.count() > 0) - d->geometry.draw(painter, d->start, d->count, d->drawingMode, d->drawingWidth); -} - -/*! - Draws this scene node and its children on the \a painter. - - In detail this function: - \list - \o ensures the effect specified by effect() is current on the painter - \o sets the nodes materials onto the painter, if valid materials are present - \o moves the model-view to the x, y, z position - \o applies any local transforms() that may be set for this node - \o calls draw() for all the child nodes - \o calls draw(start, count) on this nodes geometry object (if any) - \o restores the geometry's original materials if they were changed - \o restores the model-view matrix if any local transform was applied - \endlist - - Note that the draw() method does \bold not restore the effect. If the first - step above results in a change to the current QGL::Standard effect then it - will remain set to that effect. In general any painting method should - ensure the effect it requires is current. - - The way draw is implemented ensures that this nodes effects, materials and - transformations will apply by default to its child nodes. Transformations - are cumulative, but effects and materials override those of any parent node. - - Note that if the HideNode option is set for this node, neither it nor its - children will be drawn. -*/ -void QGLSceneNode::draw(QGLPainter *painter) -{ - Q_D(QGLSceneNode); - if (d->options & HideNode) - return; - bool wasTransformed = false; - - QGLRenderSequencer *seq = painter->renderSequencer(); - - if (seq->top() != this) - { - QMatrix4x4 m = transform(); - - if (!m.isIdentity()) - { - painter->modelViewMatrix().push(); - painter->modelViewMatrix() *= m; - wasTransformed = true; - } - - if (d->options & CullBoundingBox) - { - QBox3D bb = boundingBox(); - if (bb.isFinite() && !bb.isNull() && painter->isCullable(bb)) - { - if (!d->culled && d->options & ReportCulling) - { - d->culled = true; - emit culled(); - } - if (wasTransformed) - painter->modelViewMatrix().pop(); - return; - } - else - { - if (d->culled && d->options & ReportCulling) - { - d->culled = false; - emit displayed(); - } - } - } - } - - if (seq->top() == NULL) - { - seq->setTop(this); - while (true) - { - draw(painter); // recursively draw myself for each state - if (!seq->nextInSequence()) - break; - } - seq->reset(); - } - else - { - bool stateEntered = false; - if (d->childNodes.size() > 0) - { - seq->beginState(this); - stateEntered = true; - QList<QGLSceneNode*>::iterator cit = d->childNodes.begin(); - for ( ; cit != d->childNodes.end(); ++cit) - (*cit)->draw(painter); - } - - if (d->count && (d->geometry.count() > 0) && seq->renderInSequence(this)) - { - bool idSaved = false; - int id = -1; - if (d->pickNode && painter->isPicking()) - { - idSaved = true; - id = painter->objectPickId(); - painter->setObjectPickId(d->pickNode->id()); - } - - if (!stateEntered) - { - stateEntered = true; - seq->beginState(this); - } - seq->applyState(); - - drawGeometry(painter); - - if (idSaved) - painter->setObjectPickId(id); - - if (d->options & ViewNormals) - drawNormalIndicators(painter); - } - if (stateEntered) - seq->endState(this); - } - if (wasTransformed) - painter->modelViewMatrix().pop(); -} - -/*! - Returns the pick node for this scene node, if one was set; otherwise - NULL (0) is returned. - - \sa setPickNode() -*/ -QGLPickNode *QGLSceneNode::pickNode() const -{ - Q_D(const QGLSceneNode); - return d->pickNode; -} - -/*! - Sets the pick node for this scene node to \a node. - - \sa pickNode() -*/ -void QGLSceneNode::setPickNode(QGLPickNode *node) -{ - Q_D(QGLSceneNode); - // TODO - resolve recursive picking - not supported by - // color based pick AFAICT - d->pickNode = node; - if (node) - node->setTarget(this); -} - -/*! - Creates a new QGLSceneNode that is a copy of this scene node, with - \a parent as the parent of the new copy. If parent is NULL then parent - is set to this nodes parent. - - The copy will reference the same underlying geometry, child nodes, and - have all effects, transforms and other properties copied from this node. - The only property that is not copied is pickNode(). - - \sa cloneNoChildren() -*/ -QGLSceneNode *QGLSceneNode::clone(QObject *parent) const -{ - Q_D(const QGLSceneNode); - QGLSceneNode *node = new QGLSceneNode - (new QGLSceneNodePrivate(d), parent ? parent : this->parent()); - for (int index = 0; index < d->transforms.size(); ++index) - node->addTransform(d->transforms.at(index)->clone(node)); - node->addNodes(d->childNodes); - return node; -} - -/*! - Creates a new QGLSceneNode that is a copy of this scene node, with - \a parent as the parent of the new copy. If parent is NULL then parent - is set to this nodes parent. - - The copy will reference the same underlying geometry, and - have all effects, transforms and other properties copied from this node. - The children() and pickNodes() are not cloned. - - \sa clone() -*/ -QGLSceneNode *QGLSceneNode::cloneNoChildren(QObject *parent) const -{ - Q_D(const QGLSceneNode); - QGLSceneNode *node = new QGLSceneNode - (new QGLSceneNodePrivate(d), parent ? parent : this->parent()); - for (int index = 0; index < d->transforms.size(); ++index) - node->addTransform(d->transforms.at(index)->clone(node)); - return node; -} - -/*! - Creates a new QGLSceneNode that is a copy of this scene node, with - \a parent as the parent of the new copy. If parent is NULL then parent - is set to this nodes parent. - - The copy will reference the same underlying geometry and - have all effects, transforms and other properties copied from this node. - - The copy returned will have the same child nodes, except all child nodes - whose objectName() is equal to \a name. - - \sa clone(), only() -*/ -QGLSceneNode *QGLSceneNode::allExcept(const QString &name, QObject *parent) const -{ - Q_D(const QGLSceneNode); - QGLSceneNode *node = cloneNoChildren(parent); - for (int index = 0; index < d->childNodes.count(); ++index) { - QGLSceneNode *child = d->childNodes.at(index); - if (child->objectName() != name) - node->addNode(child); - } - return node; -} - -/*! - Creates a new QGLSceneNode that is a copy of this scene node, with - \a parent as the parent of the new copy. If parent is NULL then parent - is set to this nodes parent. - - The copy will reference the same underlying geometry and - have all effects, transforms and other properties copied from this node. - - The copy returned will have only one child node. This child node will be - the first child node of this one which has its objectName() equal to \a name. - - \sa clone(), allExcept() -*/ -QGLSceneNode *QGLSceneNode::only(const QString &name, QObject *parent) const -{ - Q_D(const QGLSceneNode); - QGLSceneNode *node = cloneNoChildren(parent); - for (int index = 0; index < d->childNodes.count(); ++index) { - QGLSceneNode *child = d->childNodes.at(index); - if (child->objectName() == name) { - node->addNode(child); - break; - } - } - return node; -} - -/*! - Creates a new QGLSceneNode that is a copy of this scene node, with - \a parent as the parent of the new copy. If parent is NULL then parent - is set to this nodes parent. - - The copy will reference the same underlying geometry and - have all effects, transforms and other properties copied from this node. - - The copy returned will have the same child nodes, except all child nodes - whose objectName() is in the list of \a names. - - \sa clone(), only() -*/ -QGLSceneNode *QGLSceneNode::allExcept(const QStringList &names, QObject *parent) const -{ - Q_D(const QGLSceneNode); - QGLSceneNode *node = cloneNoChildren(parent); - QSet<QString> chk = QSet<QString>::fromList(names); - for (int index = 0; index < d->childNodes.count(); ++index) { - QGLSceneNode *child = d->childNodes.at(index); - if (!chk.contains(child->objectName())) - node->addNode(child); - } - return node; -} - -/*! - Creates a new QGLSceneNode that is a copy of this scene node, with - \a parent as the parent of the new copy. If parent is NULL then parent - is set to this nodes parent. - - The copy will reference the same underlying geometry and - have all effects, transforms and other properties copied from this node. - - The copy returned will have only the child nodes from this - whose objectName() is in the list of \a names. - - \sa clone(), allExcept() -*/ -QGLSceneNode *QGLSceneNode::only(const QStringList &names, QObject *parent) const -{ - Q_D(const QGLSceneNode); - QGLSceneNode *node = cloneNoChildren(parent); - QSet<QString> chk = QSet<QString>::fromList(names); - for (int index = 0; index < d->childNodes.count(); ++index) { - QGLSceneNode *child = d->childNodes.at(index); - if (chk.contains(child->objectName())) - node->addNode(child); - } - return node; -} - -/*! - \fn QGLSceneNode::updated() - Signals that some property of this scene node, or one of its children, - has changed in a manner that will require that the node be redrawn. -*/ - -/*! - \fn QGLSceneNode::culled() - Signals that the node was culled due to falling wholly outside the view - frustum. This signal can only fire if both QGLSceneNode::CullBoundingBox - and QGLSceneNode::ReportCulling options are both set. -*/ - -/*! - \fn QGLSceneNode::displayed() - Signals that the node was displayed - or at least its geometry was sent - to the GPU for rendering, since the GPU might still clip or occlude the - node. This signal can only fire if both QGLSceneNode::CullBoundingBox - and QGLSceneNode::ReportCulling options are both set. -*/ - -/*! - \relates QGLSceneNode - Print a description of \a node, and all its descendants, to the console. - This function uses qDebug for its output, so in the case of Windows the - output will go to the debug window. If QT_NO_DEBUG_OUTPUT or QT_NO_DEBUG - has been defined, (as in release mode) this function will exit without - doing anything. - - If \a detailed is true (which it is by default) then all the properties - of each node are printed, including materials, geometry and transforms. - - If \a detailed is false, then just one line is printed with the name and - some identifying information including a unique id for the node. - - The \a indent and \a loop parameters are used internally. -*/ -void qDumpScene(QGLSceneNode *node, bool detailed, int indent, const QSet<QGLSceneNode *> &loop) -{ -#if defined(QT_NO_DEBUG_STREAM) || defined(QT_NO_DEBUG) || defined(QT_NO_DEBUG_OUTPUT) - Q_UNUSED(node); - Q_UNUSED(detailed); - Q_UNUSED(indent); - Q_UNUSED(loop); -#else -#if !defined(QT_NO_THREAD) - QCoreApplication *app = QApplication::instance(); - QThread *appThread = 0; - if (app) - appThread = QApplication::instance()->thread(); -#endif - QSet<QGLSceneNode *> lp = loop; - lp.insert(node); - QString ind; - ind.fill(QLatin1Char(' '), indent * 4); - if (detailed) - { - qDebug("\n%s ======== Node: %p - %s =========", qPrintable(ind), node, - qPrintable(node->objectName())); - } - else - { - qDebug("\n%s Node: %p - %s", qPrintable(ind), node, - qPrintable(node->objectName())); - return; - } -#if !defined(QT_NO_THREAD) - if (appThread && appThread != node->thread()) - qDebug("\n%s from thread: %p", qPrintable(ind), node->thread()); -#endif - qDebug("%s start: %d count: %d children:", qPrintable(ind), node->start(), node->count()); - { - QList<QGLSceneNode*> children = node->children(); - QList<QGLSceneNode*>::const_iterator it = children.constBegin(); - for (int i = 0; it != children.constEnd(); ++it, ++i) - qDebug("%s %d: %p ", qPrintable(ind), i, *it); - } - if (!node->position().isNull()) - { - QVector3D p = node->position(); - qDebug("%s position: (%0.4f, %0.4f, %0.4f)", qPrintable(ind), - p.x(), p.y(), p.z()); - } - if (node->localTransform().isIdentity()) - { - qDebug("%s local transform: identity", qPrintable(ind)); - } - else - { - qDebug("%s local transform:", qPrintable(ind)); - QMatrix4x4 m = node->localTransform(); - for (int i = 0; i < 4; ++i) - qDebug("%s %0.4f %0.4f %0.4f %0.4f", - qPrintable(ind), m(i, 0), m(i, 1), m(i, 2), m(i, 3)); - } - QList<QGraphicsTransform3D*> tx = node->transforms(); - if (tx.size() > 0) - qDebug("%s transforms list:", qPrintable(ind)); - for (int i = 0; i < tx.size(); ++i) - { - const QMetaObject *obj = tx.at(i)->metaObject(); - qDebug("%s %s", qPrintable(ind), obj->className()); - } - if (!node->geometry().isEmpty()) - { - qDebug("%s geometry: %d indexes, %d vertices", - qPrintable(ind), node->geometry().count(), node->geometry().count(QGL::Position)); - } - else - { - qDebug("%s geometry: NULL", qPrintable(ind)); - } - if (node->materialIndex() != -1) - { - qDebug("%s material: %d", qPrintable(ind), node->materialIndex()); - QGLMaterial *mat = node->material(); - QGLMaterialCollection *pal = node->palette(); - if (pal) - qDebug("%s palette: %p", qPrintable(ind), pal); - else - qDebug("%s no palette", qPrintable(ind)); - if (pal) - { - mat = pal->material(node->materialIndex()); - if (mat) - qDebug("%s mat name from pal: %s ", qPrintable(ind), - qPrintable(pal->material(node->materialIndex())->objectName())); - else - qDebug("%s indexed material %d does not exist in palette!", - qPrintable(ind), node->materialIndex()); - } - if (mat) - { - QString mat_spx = QString(QLatin1String(" Amb: %1 - Diff: %2 - Spec: %3 - Shin: %4")) - .arg((mat->ambientColor().name())) - .arg(mat->diffuseColor().name()) - .arg(mat->specularColor().name()) - .arg(mat->shininess()); - if (mat->objectName().isEmpty()) - qDebug("%s material pointer %p: %s", qPrintable(ind), mat, qPrintable(mat_spx)); - else - qDebug("%s \"%s\": %s", qPrintable(ind), - qPrintable(mat->objectName()), qPrintable(mat_spx)); - for (int i = 0; i < mat->textureLayerCount(); ++i) - { - if (mat->texture(i) != 0) - { - QGLTexture2D *tex = mat->texture(i); - if (tex->objectName().isEmpty()) - qDebug("%s texture %p", qPrintable(ind), tex); - else - qDebug("%s texture %s", qPrintable(ind), - qPrintable(tex->objectName())); - QSize sz = tex->size(); - qDebug(" - size: %d (w) x %d (h)", sz.width(), sz.height()); - } - } - } - else - { - qDebug("%s - could not find indexed material!!", qPrintable(ind)); - } - } - else - { - qDebug("%s material: NONE", qPrintable(ind)); - } - - if (node->hasEffect()) - { - if (node->userEffect()) - { - qDebug("%s user effect %p", qPrintable(ind), - node->userEffect()); - } - else - { - switch (node->effect()) - { - case QGL::FlatColor: - qDebug("%s flat color effect", qPrintable(ind)); break; - case QGL::FlatPerVertexColor: - qDebug("%s flat per vertex color effect", qPrintable(ind)); break; - case QGL::FlatReplaceTexture2D: - qDebug("%s flat replace texture 2D effect", qPrintable(ind)); break; - case QGL::FlatDecalTexture2D: - qDebug("%s flat decal texture 2D effect", qPrintable(ind)); break; - case QGL::LitMaterial: - qDebug("%s lit material effect", qPrintable(ind)); break; - case QGL::LitDecalTexture2D: - qDebug("%s lit decal texture 2D effect", qPrintable(ind)); break; - case QGL::LitModulateTexture2D: - qDebug("%s lit modulate texture 2D effect", qPrintable(ind)); break; - } - } - } - else - { - qDebug("%s no effect set", qPrintable(ind)); - } - QList<QGLSceneNode*> children = node->children(); - QList<QGLSceneNode*>::const_iterator it = children.constBegin(); - for ( ; it != children.constEnd(); ++it) - if (!lp.contains(*it)) - qDumpScene(*it, indent + 1); -#endif -} - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QGLSceneNode &node) -{ - dbg << &node << "\n start:" << node.start() << " count:" << node.count(); - QList<QGLSceneNode*> children = node.children(); - QList<QGLSceneNode*>::const_iterator it = children.constBegin(); - for ( ; it != children.constEnd(); ++it) - dbg << "\n child:" << *it; - - if (node.localTransform().isIdentity()) - dbg << "\n local transform: identity"; - else - dbg << "\n local transform:\n" << node.localTransform(); - - if (node.geometry().count() > 0) - { - QGLMaterial *mat = node.material(); - QString mdesc; - if (mat) - mdesc = mat->objectName(); - dbg << "\n geometry:" << node.geometry(); - dbg << "\n material" << node.material() << ": " << mat << mdesc; - } - else - { - dbg << "\n geometry: NULL"; - dbg << "\n material" << node.material(); - } - - if (node.hasEffect()) - { - if (node.userEffect()) - { - dbg << "\n user effect"; - } - else - { - switch (node.effect()) - { - case QGL::FlatColor: - dbg << "\n flat color effect"; break; - case QGL::FlatPerVertexColor: - dbg << "\n flat per vertex color effect"; break; - case QGL::FlatReplaceTexture2D: - dbg << "\n flat replace texture 2D effect"; break; - case QGL::FlatDecalTexture2D: - dbg << "\n flat decal texture 2D effect"; break; - case QGL::LitMaterial: - dbg << "\n lit material effect"; break; - case QGL::LitDecalTexture2D: - dbg << "\n lit decal texture 2D effect"; break; - case QGL::LitModulateTexture2D: - dbg << "\n lit modulate texture 2D effect"; break; - } - } - } - else - { - dbg << "\n no effect set"; - } - return dbg; -} - -#endif // QT_NO_DEBUG_STREAM - -QT_END_NAMESPACE diff --git a/src/threed/scene/qglscenenode.h b/src/threed/scene/qglscenenode.h deleted file mode 100644 index edf08874..00000000 --- a/src/threed/scene/qglscenenode.h +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLSCENENODE_H -#define QGLSCENENODE_H - -#include <QtCore/qobject.h> - -#include "qgeometrydata.h" -#include "qglmaterialcollection.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt3D) - -class QGLSceneNodePrivate; -class QGLAbstractEffect; -class QGLPickNode; -class QGraphicsTransform3D; - -class Q_QT3D_EXPORT QGLSceneNode : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QGLSceneNode) - Q_ENUMS(Option) - Q_FLAGS(Options) - Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY updated) - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY updated) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY updated) - Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY updated) - Q_PROPERTY(QGLMaterial *material READ material WRITE setMaterial NOTIFY updated) - Q_PROPERTY(QGLMaterial *backMaterial READ backMaterial WRITE setBackMaterial NOTIFY updated) - Q_PROPERTY(Options options READ options WRITE setOptions NOTIFY updated) -public: - explicit QGLSceneNode(QObject *parent = 0); - explicit QGLSceneNode(const QGeometryData &geometry, QObject *parent = 0); - virtual ~QGLSceneNode(); - - enum Option - { - NoOptions = 0x0000, - CullBoundingBox = 0x0001, - ViewNormals = 0x0002, - ReportCulling = 0x0004, - HideNode = 0x0008 - }; - Q_DECLARE_FLAGS(Options, Option) - - QGLSceneNode::Options options() const; - void setOptions(QGLSceneNode::Options options); - void setOption(QGLSceneNode::Option option, bool value); - - QGeometryData geometry() const; - void setGeometry(QGeometryData); - - QBox3D boundingBox() const; - - QMatrix4x4 localTransform() const; - void setLocalTransform(const QMatrix4x4 &); - QVector3D position() const; - void setPosition(const QVector3D &p); - qreal x() const; - void setX(qreal x); - qreal y() const; - void setY(qreal y); - qreal z() const; - void setZ(qreal z); - - QList<QGraphicsTransform3D *> transforms() const; - void setTransforms(const QList<QGraphicsTransform3D *> &transforms); - void addTransform(QGraphicsTransform3D *transform); - - QGL::DrawingMode drawingMode() const; - void setDrawingMode(QGL::DrawingMode mode); - - qreal drawingWidth() const; - void setDrawingWidth(qreal width); - - QGL::StandardEffect effect() const; - void setEffect(QGL::StandardEffect); - - QGLAbstractEffect *userEffect() const; - void setUserEffect(QGLAbstractEffect *effect); - - bool hasEffect() const; - void setEffectEnabled(bool); - - int start() const; - void setStart(int start); - - int count() const; - void setCount(int count); - - int materialIndex() const; - void setMaterialIndex(int material); - int backMaterialIndex() const; - void setBackMaterialIndex(int material); - - QGLMaterial *material() const; - void setMaterial(QGLMaterial *material); - QGLMaterial *backMaterial() const; - void setBackMaterial(QGLMaterial *material); - - QGLMaterialCollection *palette() const; - void setPalette(QGLMaterialCollection *palette); - - QList<QGLSceneNode*> allChildren() const; - QList<QGLSceneNode *> children() const; - - void addNode(QGLSceneNode *node); - void addNodes(const QList<QGLSceneNode *> &nodes); - void removeNode(QGLSceneNode *node); - void removeNodes(const QList<QGLSceneNode *> &nodes); - - virtual void draw(QGLPainter *painter); - - QGLPickNode *pickNode() const; - void setPickNode(QGLPickNode *node); - - Q_INVOKABLE QGLSceneNode *clone(QObject *parent = 0) const; - Q_INVOKABLE QGLSceneNode *cloneNoChildren(QObject *parent = 0) const; - Q_INVOKABLE QGLSceneNode *allExcept(const QString &name, QObject *parent = 0) const; - Q_INVOKABLE QGLSceneNode *only(const QString &name, QObject *parent = 0) const; - Q_INVOKABLE QGLSceneNode *allExcept(const QStringList &names, QObject *parent = 0) const; - Q_INVOKABLE QGLSceneNode *only(const QStringList &names, QObject *parent = 0) const; - -Q_SIGNALS: - void updated(); - void culled(); - void displayed(); - -protected: - virtual void drawGeometry(QGLPainter *painter); - -private Q_SLOTS: - void transformChanged(); - -private: - QMatrix4x4 transform() const; - void invalidateBoundingBox() const; - void invalidateTransform() const; - void drawNormalIndicators(QGLPainter *painter); - const QGLMaterial *setPainterMaterial(int material, QGLPainter *painter, - QGL::Face faces, bool &changedTex); - - Q_DISABLE_COPY(QGLSceneNode) - - QScopedPointer<QGLSceneNodePrivate> d_ptr; - - QGLSceneNode(QGLSceneNodePrivate *d, QObject *parent); -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QGLSceneNode::Options) - -Q_QT3D_EXPORT void qDumpScene(QGLSceneNode *, bool detailed = true, int indent = 0, const QSet<QGLSceneNode*> &loop = QSet<QGLSceneNode*>()); - -#ifndef QT_NO_DEBUG_STREAM -Q_QT3D_EXPORT QDebug operator<<(QDebug dbg, const QGLSceneNode &node); -#endif - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/threed/scene/qglscenenode_p.h b/src/threed/scene/qglscenenode_p.h deleted file mode 100644 index 21028ddb..00000000 --- a/src/threed/scene/qglscenenode_p.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation ([email protected]) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLSCENENODE_P_H -#define QGLSCENENODE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qglnamespace.h" -#include "qglscenenode.h" -#include "qgraphicstransform3d.h" - -#include <QtGui/qmatrix4x4.h> -#include <QtCore/qlist.h> -#include <QtCore/qstringlist.h> -#include <QtCore/qset.h> - -QT_BEGIN_NAMESPACE - -class QGLAbstractEffect; -class QGLPickNode; - -class QGLSceneNodePrivate -{ -public: - QGLSceneNodePrivate() - : palette(0) - , localEffect(QGL::FlatColor) // 0 - zero - , customEffect(0) - , hasEffect(false) - , material(-1) - , backMaterial(-1) - , start(0) - , count(0) - , options(0) - , pickNode(0) - , boxValid(false) - , drawingMode(QGL::Triangles) - , culled(false) - { - } - - // This constructor is used by QGLSceneNode::clone(). - QGLSceneNodePrivate(const QGLSceneNodePrivate *other) - : geometry(other->geometry) - , palette(other->palette) - , localTransform(other->localTransform) - , translate(other->translate) - , localEffect(other->localEffect) - , customEffect(other->customEffect) - , hasEffect(other->hasEffect) - , material(other->material) - , backMaterial(other->backMaterial) - , start(other->start) - , count(other->count) - , options(other->options) - , pickNode(0) // Explicitly not cloned. - , bb(other->bb) - , boxValid(other->boxValid) - , drawingMode(other->drawingMode) - , drawingWidth(1.0) - , culled(other->culled) - { - } - - inline void invalidateParentBoundingBox() const - { - QList<QGLSceneNode*>::const_iterator it = parentNodes.constBegin(); - for ( ; it != parentNodes.constEnd(); ++it) - (*it)->invalidateBoundingBox(); - } - - QGeometryData geometry; - QGLMaterialCollection *palette; - QMatrix4x4 localTransform; - QVector3D translate; - QList<QGraphicsTransform3D *> transforms; - QGL::StandardEffect localEffect; - QGLAbstractEffect *customEffect; - QList<QGLSceneNode*> childNodes; - QList<QGLSceneNode*> parentNodes; - bool hasEffect; - int material; - int backMaterial; - int start; - int count; - QGLSceneNode::Options options; - QGLPickNode *pickNode; - mutable QBox3D bb; - mutable bool boxValid; - QGL::DrawingMode drawingMode; - qreal drawingWidth; - bool culled; -}; - -QT_END_NAMESPACE - -#endif // QGLSCENENODE_P_H diff --git a/src/threed/scene/scene.pri b/src/threed/scene/scene.pri deleted file mode 100644 index 289f6b9c..00000000 --- a/src/threed/scene/scene.pri +++ /dev/null @@ -1,19 +0,0 @@ -INCLUDEPATH += $$PWD -VPATH += $$PWD -HEADERS += scene/qglabstractscene.h \ - scene/qglsceneformatplugin.h \ - scene/qglscenenode.h \ - scene/qglpicknode.h \ - scene/qglrendersequencer.h \ - scene/qglrenderorder.h \ - scene/qglrenderordercomparator.h \ - scene/qglrenderstate.h -SOURCES += qglabstractscene.cpp \ - qglsceneformatplugin.cpp \ - qglscenenode.cpp \ - qglpicknode.cpp \ - qglrendersequencer.cpp \ - qglrenderorder.cpp \ - qglrenderordercomparator.cpp \ - qglrenderstate.cpp -PRIVATE_HEADERS += qglscenenode_p.h |