1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include "qsgsimpletexturenode.h"
47 static void qsgsimpletexturenode_update(QSGGeometry *g,
54 QSize ts = texture->textureSize();
55 QRectF sourceRect(0, 0, ts.width(), ts.height());
56 QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect));
60 \class QSGSimpleTextureNode
61 \brief The QSGSimpleTextureNode class is provided for convenience to easily draw
62 textured content using the QML scene graph.
66 \warning The simple texture node class must have a texture before being
67 added to the scene graph to be rendered.
71 Constructs a new simple texture node
73 QSGSimpleTextureNode::QSGSimpleTextureNode()
74 : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
76 setGeometry(&m_geometry);
77 setMaterial(&m_material);
78 setOpaqueMaterial(&m_opaque_material);
82 Sets the filtering to be used for this texture node to \a filtering.
84 For smooth scaling, use QSGTexture::Linear; for normal scaling, use
87 void QSGSimpleTextureNode::setFiltering(QSGTexture::Filtering filtering)
89 if (m_material.filtering() == filtering)
92 m_material.setFiltering(filtering);
93 m_opaque_material.setFiltering(filtering);
94 markDirty(DirtyMaterial);
99 Returns the filtering currently set on this texture node
101 QSGTexture::Filtering QSGSimpleTextureNode::filtering() const
103 return m_material.filtering();
108 Sets the target rect of this texture node to \a r
110 void QSGSimpleTextureNode::setRect(const QRectF &r)
115 qsgsimpletexturenode_update(&m_geometry, texture(), m_rect);
116 markDirty(DirtyGeometry);
121 Returns the target rect of this texture node.
123 QRectF QSGSimpleTextureNode::rect() const
129 Sets the texture of this texture node to \a texture.
131 \warning A texture node must have a texture before being added
132 to the scenegraph to be rendered.
134 void QSGSimpleTextureNode::setTexture(QSGTexture *texture)
136 if (m_material.texture() == texture)
138 m_material.setTexture(texture);
139 m_opaque_material.setTexture(texture);
140 qsgsimpletexturenode_update(&m_geometry, texture, m_rect);
141 markDirty(DirtyMaterial);
147 Returns the texture for this texture node
149 QSGTexture *QSGSimpleTextureNode::texture() const
151 return m_material.texture();