summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-11-21 08:26:47 +0100
committerFabian Bumberger <fbumberger@rim.com>2014-01-28 16:57:25 +0100
commit3a4e145e5eb7a21cf4432bf64940306954921026 (patch)
treefee23be10c6800aaf0df137c7e964f09accc324a
parent40523fde410adf74d021bec4869e9bf6a7aef39c (diff)
Implement textures ansd geometry creation for the SG renderer
Change-Id: Ia91e8b7220c333b9fa6d718eec4a950f3f1fc583 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/location/maps/qgeomapscene_p_p.h11
-rw-r--r--src/location/maps/qgeomapscene_sg.cpp26
-rw-r--r--src/location/maps/qgeomapsscene_qt3d.cpp70
-rw-r--r--src/location/maps/qgeotilecache.cpp9
-rw-r--r--src/location/maps/qgeotilecache_p.h6
5 files changed, 87 insertions, 35 deletions
diff --git a/src/location/maps/qgeomapscene_p_p.h b/src/location/maps/qgeomapscene_p_p.h
index f1fb6c48..692211dd 100644
--- a/src/location/maps/qgeomapscene_p_p.h
+++ b/src/location/maps/qgeomapscene_p_p.h
@@ -54,6 +54,8 @@
#ifndef NO_QT3D_RENDERER
class QGLLightParameters;
+#else
+class QSGSimpleTextureNode;
#endif
class QGeoMapScenePrivate
@@ -86,9 +88,9 @@ public:
int sideLength_;
#ifndef NO_QT3D_RENDERER
- QHash<QGeoTileSpec, QGLSceneNode *> nodes_;
+ QHash<QGeoTileSpec, QGLSceneNode*> nodes_;
#else
- QHash<QGeoTileSpec, QSGNode *> nodes_;
+ QHash<QGeoTileSpec, QSGSimpleTextureNode*> nodes_;
#endif
QHash<QGeoTileSpec, QSharedPointer<QGeoTileTexture> > textures_;
QList<QSharedPointer<QGeoTileTexture> > newUploads_;
@@ -126,8 +128,11 @@ public:
void setVisibleTiles(const QSet<QGeoTileSpec> &tiles);
void removeTiles(const QSet<QGeoTileSpec> &oldTiles);
void updateTiles(const QSet<QGeoTileSpec> &tiles);
+
+ QRectF buildGeometry(const QGeoTileSpec &spec); //The return value might be a problem
+ //when qreal is float
#ifndef NO_QT3D_RENDERER
- QGeometryData buildGeometry(const QGeoTileSpec &spec);
+ QGeometryData buildGeometryData(const QGeoTileSpec &spec);
QGLSceneNode *buildSceneNodeFromGeometry(const QGeometryData &geom);
void paintGL(QGLPainter *painter);
#endif
diff --git a/src/location/maps/qgeomapscene_sg.cpp b/src/location/maps/qgeomapscene_sg.cpp
index 1b0b5a35..33072bd5 100644
--- a/src/location/maps/qgeomapscene_sg.cpp
+++ b/src/location/maps/qgeomapscene_sg.cpp
@@ -41,6 +41,11 @@
#include "qgeomapscene_p_p.h"
+#include "qgeotilespec_p.h"
+#include "qgeotilecache_p.h"
+
+#include <QSGSimpleTextureNode>
+
QT_BEGIN_NAMESPACE
@@ -54,6 +59,27 @@ void QGeoMapScenePrivate::setScalingOnTextures()
void QGeoMapScenePrivate::addTile(const QGeoTileSpec &spec, QSharedPointer<QGeoTileTexture> texture)
{
+ if (!visibleTiles_.contains(spec)) // Don't add the geometry if it isn't visible
+ return;
+
+ const QRectF &rect = buildGeometry(spec);
+ if (rect.isNull())
+ return;
+
+ QSGSimpleTextureNode *node = new QSGSimpleTextureNode();
+
+ if (linearScaling_) {
+ node->setFiltering(QSGTexture::Linear);
+ } else {
+ node->setFiltering(QSGTexture::Nearest);
+ }
+
+ node->setRect(rect);
+ node->setTexture(texture->texture);
+
+ nodes_.insert(spec, node);
+ textures_.insert(spec, texture);
+ newUploads_ << texture;
}
// return true if new tiles introduced in [tiles]
diff --git a/src/location/maps/qgeomapsscene_qt3d.cpp b/src/location/maps/qgeomapsscene_qt3d.cpp
index 9ef66398..fa15001f 100644
--- a/src/location/maps/qgeomapsscene_qt3d.cpp
+++ b/src/location/maps/qgeomapsscene_qt3d.cpp
@@ -23,52 +23,30 @@ QGeoMapScenePrivate::~QGeoMapScenePrivate()
delete light_;
}
-QGeometryData QGeoMapScenePrivate::buildGeometry(const QGeoTileSpec &spec)
+QGeometryData QGeoMapScenePrivate::buildGeometryData(const QGeoTileSpec &spec)
{
- int x = spec.x();
-
- if (x < tileXWrapsBelow_)
- x += sideLength_;
-
- if ((x < minTileX_)
- || (maxTileX_ < x)
- || (spec.y() < minTileY_)
- || (maxTileY_ < spec.y())
- || (spec.zoom() != tileZ_)) {
+ const QRectF &rect = buildGeometry(spec);
+ if (rect.isNull())
return 0;
- }
-
- double edge = scaleFactor_ * tileSize_;
-
- double x1 = (x - minTileX_);
- double x2 = x1 + 1.0;
-
- double y1 = (minTileY_ - spec.y());
- double y2 = y1 - 1.0;
-
- x1 *= edge;
- x2 *= edge;
- y1 *= edge;
- y2 *= edge;
QGeometryData g;
QDoubleVector3D n = QDoubleVector3D(0, 0, 1);
//Texture coordinate order for veritcal flip of texture
- g.appendVertex(QVector3D(x1, y1, 0.0));
+ g.appendVertex(QVector3D(rect.x(), rect.y(), 0.0));
g.appendNormal(n);
g.appendTexCoord(QVector2D(0.0, 0.0));
- g.appendVertex(QVector3D(x1, y2, 0.0));
+ g.appendVertex(QVector3D(rect.x(), rect.y() + rect.height(), 0.0));
g.appendNormal(n);
g.appendTexCoord(QVector2D(0.0, 1.0));
- g.appendVertex(QVector3D(x2, y2, 0.0));
+ g.appendVertex(QVector3D(rect.x() + rect.width(), rect.y()+rect.height(), 0.0));
g.appendNormal(n);
g.appendTexCoord(QVector2D(1.0, 1.0));
- g.appendVertex(QVector3D(x2, y1, 0.0));
+ g.appendVertex(QVector3D(rect.x() + rect.width(), rect.y(), 0.0));
g.appendNormal(n);
g.appendTexCoord(QVector2D(1.0, 0.0));
@@ -124,7 +102,7 @@ void QGeoMapScenePrivate::addTile(const QGeoTileSpec &spec, QSharedPointer<QGeoT
QGLSceneNode *node = nodes_.value(spec, 0);
if (!node) {
- QGeometryData geom = buildGeometry(spec);
+ QGeometryData geom = buildGeometryData(spec);
node = buildSceneNodeFromGeometry(geom);
if (!node)
return;
@@ -187,7 +165,7 @@ void QGeoMapScenePrivate::updateTiles(const QSet<QGeoTileSpec> &tiles)
QGLSceneNode *node = nodes_.value(tile, 0);
if (node) {
- QGeometryData geom = buildGeometry(tile);
+ QGeometryData geom = buildGeometryData(tile);
// if the new geometry (after wrapping) is the same as the old one,
// it can be reused
if ( node->children().size() > 0) {
@@ -213,6 +191,36 @@ void QGeoMapScenePrivate::updateTiles(const QSet<QGeoTileSpec> &tiles)
}
}
+QRectF QGeoMapScenePrivate::buildGeometry(const QGeoTileSpec &spec)
+{
+ int x = spec.x();
+
+ if (x < tileXWrapsBelow_)
+ x += sideLength_;
+
+ if ((x < minTileX_)
+ || (maxTileX_ < x)
+ || (spec.y() < minTileY_)
+ || (maxTileY_ < spec.y())
+ || (spec.zoom() != tileZ_)) {
+ return QRectF();
+ }
+
+ double edge = scaleFactor_ * tileSize_;
+
+ double x1 = (x - minTileX_);
+ double x2 = x1 + 1.0;
+
+ double y1 = (minTileY_ - spec.y());
+ double y2 = y1 - 1.0;
+
+ x1 *= edge;
+ x2 *= edge;
+ y1 *= edge;
+ y2 *= edge;
+ return QRectF(x1, y1, x2-x1, y2-y1);
+}
+
void QGeoMapScenePrivate::removeTiles(const QSet<QGeoTileSpec> &oldTiles)
{
typedef QSet<QGeoTileSpec>::const_iterator iter;
diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp
index a1852490..a79e29e7 100644
--- a/src/location/maps/qgeotilecache.cpp
+++ b/src/location/maps/qgeotilecache.cpp
@@ -50,6 +50,11 @@
#include <QPixmap>
#include <QDebug>
+#ifdef NO_QT3D_RENDERER
+#include <QSGTexture>
+#include <QQuickWindow>
+#endif
+
#include <Qt3D/qgltexture2d.h>
Q_DECLARE_METATYPE(QList<QGeoTileSpec>)
@@ -414,6 +419,10 @@ QSharedPointer<QGeoTileTexture> QGeoTileCache::addToTextureCache(const QGeoTileS
tt->texture->setPixmap(pixmap);
tt->texture->setHorizontalWrap(QGL::ClampToEdge);
tt->texture->setVerticalWrap(QGL::ClampToEdge);
+#else
+ //tt->texture = QQuickWindow::createTextureFromImage(pixmap.toImage());
+ tt->texture->setHorizontalWrapMode(QSGTexture::ClampToEdge);
+ tt->texture->setVerticalWrapMode(QSGTexture::ClampToEdge);
#endif
/* Do not bind/cleanImage on the texture here -- it needs to be done
diff --git a/src/location/maps/qgeotilecache_p.h b/src/location/maps/qgeotilecache_p.h
index 9e51860d..1dbb0363 100644
--- a/src/location/maps/qgeotilecache_p.h
+++ b/src/location/maps/qgeotilecache_p.h
@@ -71,7 +71,11 @@ class QGeoMappingManager;
class QGeoTile;
class QGeoCachedTileMemory;
class QGeoTileCache;
+#ifndef NO_QT3D_RENDERER
class QGLTexture2D;
+#else
+class QSGTexture;
+#endif
class QPixmap;
class QThread;
@@ -101,7 +105,7 @@ public:
#ifndef NO_QT3D_RENDERER
QGLTexture2D *texture;
#else
- void *texture; //need a custom texture class here
+ QSGTexture *texture; //need a custom texture class here
#endif
bool textureBound;
};