diff options
-rw-r--r-- | plugins/plugins.pro | 2 | ||||
-rw-r--r-- | src/adaptationlayers/adaptationinterfaces.cpp | 21 | ||||
-rw-r--r-- | src/adaptationlayers/adaptationinterfaces.h | 22 | ||||
-rw-r--r-- | src/adaptationlayers/default/default_glyphnode_p.cpp | 10 | ||||
-rw-r--r-- | src/graphicsitems/nodes/qxninepatchnode.cpp | 156 | ||||
-rw-r--r-- | tests/image.qml | 7 |
6 files changed, 119 insertions, 99 deletions
diff --git a/plugins/plugins.pro b/plugins/plugins.pro index 2314692..ae75b31 100644 --- a/plugins/plugins.pro +++ b/plugins/plugins.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -!mac:contains(QT_CONFIG, phonon):SUBDIRS += phononvideo +#contains(QT_CONFIG, phonon):SUBDIRS += phononvideo diff --git a/src/adaptationlayers/adaptationinterfaces.cpp b/src/adaptationlayers/adaptationinterfaces.cpp index 024bc3c..2632f70 100644 --- a/src/adaptationlayers/adaptationinterfaces.cpp +++ b/src/adaptationlayers/adaptationinterfaces.cpp @@ -48,22 +48,17 @@ TextureReference::TextureReference() : m_status(Null) , m_texture_id(0) + , m_sub_rect(0, 0, 1, 1) , m_has_alpha(false) + , m_owns_texture(false) { } - -/*! - Constructs a new texture reference with texture set to - \a textureId and status set to Ready. \a textureRect specifies which - part of the texture to source from. \a hasAlpha indicates wether the - texture contains an alpha channel or not. - */ -TextureReference::TextureReference(int textureId, const QRectF &textureRect, bool hasAlpha) - : m_status(Ready) - , m_texture_id(textureId) - , m_texture_rect(textureRect) - , m_has_alpha(hasAlpha) +void TextureReference::setStatus(Status s) { -} + m_status = s; + + Q_ASSERT(s != Ready || (m_texture_id > 0 && !m_texture_size.isEmpty())); + emit statusChanged(s); +} diff --git a/src/adaptationlayers/adaptationinterfaces.h b/src/adaptationlayers/adaptationinterfaces.h index b5fa295..0e2eab1 100644 --- a/src/adaptationlayers/adaptationinterfaces.h +++ b/src/adaptationlayers/adaptationinterfaces.h @@ -138,24 +138,38 @@ public: }; TextureReference(); - TextureReference(int id, const QRectF &rect, bool hasAlpha); - virtual int textureId() const { return m_texture_id; } - virtual QRectF textureRect() const { return m_texture_rect; } + void setTextureId(int id) { m_texture_id = id; } + int textureId() const { return m_texture_id; } + void setTextureSize(const QSize &size) { m_texture_size = size; } + QSize textureSize() const { return m_texture_size; } + + void setSubRect(const QRectF &subrect) { m_sub_rect = subrect; } + QRectF subRect() const { return m_sub_rect; } + + void setAlphaChannel(bool hasAlpha) { m_has_alpha = hasAlpha; } bool hasAlphaChannel() const { return m_has_alpha; } + void setOwnsTexture(bool owns) { m_owns_texture = owns; } + bool ownsTexture() const { return m_owns_texture; } + + void setStatus(Status s); Status status() const { return m_status; } signals: void statusChanged(Status status); protected: + Status m_status; int m_texture_id; - QRectF m_texture_rect; + + QSize m_texture_size; + QRectF m_sub_rect; uint m_has_alpha : 1; + uint m_owns_texture : 1; }; class TextureManager diff --git a/src/adaptationlayers/default/default_glyphnode_p.cpp b/src/adaptationlayers/default/default_glyphnode_p.cpp index 5d2bdc6..8ea64c4 100644 --- a/src/adaptationlayers/default/default_glyphnode_p.cpp +++ b/src/adaptationlayers/default/default_glyphnode_p.cpp @@ -313,10 +313,12 @@ bool TextMaskMaterial::ensureUpToDate() { QSize glyphCacheSize(glyphCache()->width(), glyphCache()->height()); if (glyphCacheSize != m_size) { - // ### gunnar: port properly.. -// m_texture = QGLTexture2DPtr(QGLTexture2D::fromTextureId(glyphCache()->texture(), -// QSize(glyphCache()->width(), -// glyphCache()->height()))); + m_texture = new TextureReference; + m_texture->setTextureId(glyphCache()->texture()); + m_texture->setTextureSize(QSize(glyphCache()->width(), + glyphCache()->height())); + m_texture->setStatus(TextureReference::Ready); + m_size = glyphCacheSize; return true; diff --git a/src/graphicsitems/nodes/qxninepatchnode.cpp b/src/graphicsitems/nodes/qxninepatchnode.cpp index e7bbe11..d92cf1c 100644 --- a/src/graphicsitems/nodes/qxninepatchnode.cpp +++ b/src/graphicsitems/nodes/qxninepatchnode.cpp @@ -101,82 +101,84 @@ void QxNinePatchNode::setLinearFiltering(bool linearFiltering) void QxNinePatchNode::updateGeometry() { - Geometry *g = geometry(); - if (g->isNull()) { - QVector<QGLAttributeDescription> desc; - desc << QGLAttributeDescription(QGL::Position, 2, GL_FLOAT, 5 * sizeof(float)); - desc << QGLAttributeDescription(QGL::TextureCoord0, 2, GL_FLOAT, 5 * sizeof(float)); - updateGeometryDescription(desc, GL_UNSIGNED_SHORT); - g->setVertexCount(6 * 6); // Grid of 6x6 vertices. - g->setIndexCount(5 * 5 * 6); // Grid of 5x5 cells, 2 triangles per cell. - g->setDrawingMode(QGL::Triangles); - - ushort *indices = g->ushortIndexData(); - int count = 0; - for (int i = 0; i < 5; ++i) { - int i6 = i * 6; - for (int j = 0; j < 5; ++j) { - indices[count++] = i6 + j + 0; - indices[count++] = i6 + j + 6; - indices[count++] = i6 + j + 7; - indices[count++] = i6 + j + 7; - indices[count++] = i6 + j + 1; - indices[count++] = i6 + j + 0; - } - } - } - - struct V - { - V(float x, float y, float u, float v) : x(x), y(y), u(u), v(v) { } - float x, y, u, v; - }; - - V *vertices = (V *)g->vertexData(); - - qreal x[6], y[6], u[6], v[6]; - QRectF texRect = m_texture->textureRect(); - - x[0] = m_targetRect.x(); - x[1] = m_targetRect.x() + m_innerRect.x(); - x[2] = x[1] + 0.5; - x[3] = m_targetRect.x() + m_targetRect.width() - - (texRect.width() - (m_innerRect.x() + m_innerRect.width())); - x[4] = x[3] - 0.5; - x[5] = m_targetRect.x() + m_targetRect.width(); - - y[0] = m_targetRect.y(); - y[1] = m_targetRect.y() + m_innerRect.y(); - y[2] = y[1] + 0.5; - y[3] = m_targetRect.y() + m_targetRect.height() - - (texRect.height() - (m_innerRect.y() + m_innerRect.height())); - y[4] = y[3] - 0.5; - y[5] = m_targetRect.y() + m_targetRect.height(); - - qreal pw = texRect.width(); - qreal ph = texRect.height(); - - QRectF src = texRect; - u[0] = src.left(); - u[1] = src.left() + m_innerRect.x() / pw * src.width(); - u[2] = u[1] + 0.5 / pw * src.width(); - u[3] = src.left() + (m_innerRect.x() + m_innerRect.width()) / pw * src.width(); - u[4] = u[3] - 0.5 / pw * src.width(); - u[5] = src.right(); - - v[0] = src.top(); - v[1] = src.top() + m_innerRect.y() / ph * src.height(); - v[2] = v[1] + 0.5 / ph * src.height(); - v[3] = src.top() + (m_innerRect.y() + m_innerRect.height()) / ph * src.height(); - v[4] = v[3] - 0.5 / ph * src.height(); - v[5] = src.bottom(); - - for (int i = 0; i < 6; ++i) { - for (int j = 0; j < 6; ++j) - vertices[i * 6 + j] = V(x[j], y[i], u[j], v[i]); - } - - setBoundingRect(m_targetRect); - markDirty(Node::DirtyGeometry); + // ### Gunnar: port properly + +// Geometry *g = geometry(); +// if (g->isNull()) { +// QVector<QGLAttributeDescription> desc; +// desc << QGLAttributeDescription(QGL::Position, 2, GL_FLOAT, 5 * sizeof(float)); +// desc << QGLAttributeDescription(QGL::TextureCoord0, 2, GL_FLOAT, 5 * sizeof(float)); +// updateGeometryDescription(desc, GL_UNSIGNED_SHORT); +// g->setVertexCount(6 * 6); // Grid of 6x6 vertices. +// g->setIndexCount(5 * 5 * 6); // Grid of 5x5 cells, 2 triangles per cell. +// g->setDrawingMode(QGL::Triangles); + +// ushort *indices = g->ushortIndexData(); +// int count = 0; +// for (int i = 0; i < 5; ++i) { +// int i6 = i * 6; +// for (int j = 0; j < 5; ++j) { +// indices[count++] = i6 + j + 0; +// indices[count++] = i6 + j + 6; +// indices[count++] = i6 + j + 7; +// indices[count++] = i6 + j + 7; +// indices[count++] = i6 + j + 1; +// indices[count++] = i6 + j + 0; +// } +// } +// } + +// struct V +// { +// V(float x, float y, float u, float v) : x(x), y(y), u(u), v(v) { } +// float x, y, u, v; +// }; + +// V *vertices = (V *)g->vertexData(); + +// qreal x[6], y[6], u[6], v[6]; +// QRectF texRect = m_texture->textureRect(); + +// x[0] = m_targetRect.x(); +// x[1] = m_targetRect.x() + m_innerRect.x(); +// x[2] = x[1] + 0.5; +// x[3] = m_targetRect.x() + m_targetRect.width() - +// (texRect.width() - (m_innerRect.x() + m_innerRect.width())); +// x[4] = x[3] - 0.5; +// x[5] = m_targetRect.x() + m_targetRect.width(); + +// y[0] = m_targetRect.y(); +// y[1] = m_targetRect.y() + m_innerRect.y(); +// y[2] = y[1] + 0.5; +// y[3] = m_targetRect.y() + m_targetRect.height() - +// (texRect.height() - (m_innerRect.y() + m_innerRect.height())); +// y[4] = y[3] - 0.5; +// y[5] = m_targetRect.y() + m_targetRect.height(); + +// qreal pw = texRect.width(); +// qreal ph = texRect.height(); + +// QRectF src = texRect; +// u[0] = src.left(); +// u[1] = src.left() + m_innerRect.x() / pw * src.width(); +// u[2] = u[1] + 0.5 / pw * src.width(); +// u[3] = src.left() + (m_innerRect.x() + m_innerRect.width()) / pw * src.width(); +// u[4] = u[3] - 0.5 / pw * src.width(); +// u[5] = src.right(); + +// v[0] = src.top(); +// v[1] = src.top() + m_innerRect.y() / ph * src.height(); +// v[2] = v[1] + 0.5 / ph * src.height(); +// v[3] = src.top() + (m_innerRect.y() + m_innerRect.height()) / ph * src.height(); +// v[4] = v[3] - 0.5 / ph * src.height(); +// v[5] = src.bottom(); + +// for (int i = 0; i < 6; ++i) { +// for (int j = 0; j < 6; ++j) +// vertices[i * 6 + j] = V(x[j], y[i], u[j], v[i]); +// } + +// setBoundingRect(m_targetRect); +// markDirty(Node::DirtyGeometry); } diff --git a/tests/image.qml b/tests/image.qml new file mode 100644 index 0000000..d7b8cf9 --- /dev/null +++ b/tests/image.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +Image { + width: 500 + height: 400 + source: "img.png" +} |