1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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();