8012af9cfc00f1931a68df9d2c4fc28310ef77ea
[profile/ivi/qtdeclarative.git] / src / quick / scenegraph / coreapi / qsgrendernode.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qsgrendernode_p.h"
43
44 QT_BEGIN_NAMESPACE
45
46 QSGRenderNode::QSGRenderNode()
47     : QSGNode(RenderNodeType)
48     , m_matrix(0)
49     , m_clip_list(0)
50     , m_opacity(1)
51 {
52 }
53
54 void QSGRenderNode::setInheritedOpacity(qreal opacity)
55 {
56     Q_ASSERT(opacity >= 0 && opacity <= 1);
57     m_opacity = opacity;
58 }
59
60 /*!
61     \fn QSGRenderNode::StateFlags QSGRenderNode::changedStates()
62
63     This function should return a mask where each bit represents OpenGL states changed by
64     the \l render() function:
65     \list
66     \li DepthState - depth write mask, depth test enabled, depth comparison function
67     \li StencilState - stencil write masks, stencil test enabled, stencil operations,
68                       stencil comparison functions
69     \li ScissorState - scissor enabled, scissor test enabled
70     \li ColorState - clear color, color write mask
71     \li BlendState - blend enabled, blend function
72     \li CullState - front face, cull face enabled
73     \li ViewportState - viewport
74     \endlist
75
76     The function is called by the renderer so it can reset the OpenGL states after rendering this
77     node.
78
79     \internal
80   */
81
82 /*!
83     \fn void QSGRenderNode::render(const RenderState &state)
84
85     This function is called by the renderer and should paint this node with OpenGL commands.
86
87     The states necessary for clipping has already been set before the function is called.
88     The clip is a combination of a stencil clip and scissor clip. Information about the clip is
89     found in \a state.
90
91     The effective opacity can be retrieved with \l inheritedOpacity().
92
93     The projection matrix is available through \a state, while the model-view matrix can be
94     fetched with \l matrix(). The combined matrix is then the projection matrix times the
95     model-view matrix.
96
97     The following states are set before this function is called:
98     \list
99     \li glDepthMask(false)
100     \li glDisable(GL_DEPTH_TEST)
101     \li glStencilMask(0)
102     \li glEnable(GL_STENCIL_TEST)/glDisable(GL_STENCIL_TEST) depending on clip
103     \li glStencilFunc(GL_EQUAL, state.stencilValue, 0xff) depending on clip
104     \li glEnable(GL_SCISSOR_TEST)/glDisable(GL_SCISSOR_TEST) depending on clip
105     \li glScissor(state.scissorRect.x(), state.scissorRect.y(),
106                  state.scissorRect.width(), state.scissorRect.height()) depending on clip
107     \li glEnable(GL_BLEND)
108     \li glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
109     \li glDisable(GL_CULL_FACE)
110     \endlist
111
112     States that are not listed above, but are included in \l StateFlags, can have arbitrary
113     values.
114
115     \l changedStates() should return which states this function has changed. If a state is not
116     covered by \l StateFlags, the state should be set to the default value according to the
117     OpenGL specification.
118
119     \internal
120   */
121
122 QT_END_NAMESPACE