1 /****************************************************************************
2 **
3 ** Copyright (C) 2008-2012 NVIDIA Corporation.
4 ** Copyright (C) 2019 The Qt Company Ltd.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of Qt Quick 3D.
8 **
9 ** $QT_BEGIN_LICENSE:GPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU
20 ** General Public License version 3 or (at your option) any later version
21 ** approved by the KDE Free Qt Foundation. The licenses are as published by
22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
23 ** included in the packaging of this file. Please review the following
24 ** information to ensure the GNU General Public License requirements will
25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26 **
27 ** $QT_END_LICENSE$
28 **
29 ****************************************************************************/
30 
31 #ifndef QSSG_RENDER_LAYER_HELPER_IMPL_H
32 #define QSSG_RENDER_LAYER_HELPER_IMPL_H
33 
34 //
35 //  W A R N I N G
36 //  -------------
37 //
38 // This file is not part of the Qt API.  It exists purely as an
39 // implementation detail.  This header file may change from version to
40 // version without notice, or even be removed.
41 //
42 // We mean it.
43 //
44 
45 #include <QtQuick3DRender/private/qssgrenderbasetypes_p.h>
46 #include <QtQuick3DRuntimeRender/private/qssgrendercamera_p.h>
47 #include <QtQuick3DRuntimeRender/private/qssgrendercontextcore_p.h>
48 
49 QT_BEGIN_NAMESPACE
50 
51 /**	An independent, testable entity to encapsulate taking at least:
52  *  layer, current viewport rect, current scissor rect, presentation design dimensions
53  *	and producing a set of rectangles:
54  *	layer viewport rect (inside viewport rect and calculated using outer viewport rect info)
55  *	layer scissor rect (inside current scissor rect)
56  *	layer camera rect (may be the viewport rect)
57  *
58  *  In the case where we have to render offscreen for this layer then we need to handle produce
59  *	a set of texture dimensions and the layer camera rect ends up being same size but with no
60  *offsets.
61  *
62  *  This object should handle part of any translation from screenspace to global space.
63  *	I am using language level access control on this object because it needs specific
64  *	interface design that will enable future modifications.
65  */
66 struct Q_AUTOTEST_EXPORT QSSGLayerRenderHelper
67 {
68 private:
69     QSSGRenderLayer *m_layer = nullptr;
70     QSSGRenderCamera *m_camera = nullptr;
71 
72     QRectF m_viewport;
73     QRectF m_scissor;
74 
75 public:
76     QSSGLayerRenderHelper() = default;
77 
78     QSSGLayerRenderHelper(const QRectF &inViewport,
79                             const QRectF &inScissor,
80                             QSSGRenderLayer &inLayer);
81 
layerQSSGLayerRenderHelper82     QSSGRenderLayer *layer() const { return m_layer; }
cameraQSSGLayerRenderHelper83     QSSGRenderCamera *camera() const { return m_camera; }
84 
85     // Does not differ whether offscreen or not, simply states how this layer maps to the
86     // presentation
viewportQSSGLayerRenderHelper87     QRectF viewport() const { return m_viewport; }
88     // Does not differ whether offscreen or not, scissor rect of how this layer maps to
89     // presentation.
scissorQSSGLayerRenderHelper90     QRectF scissor() const { return m_scissor; }
91 
92     QSize textureDimensions() const;
93 
94     QSSGCameraGlobalCalculationResult setupCameraForRender(QSSGRenderCamera &inCamera);
95 
96     static QSSGOption<QVector2D> layerMouseCoords(const QRectF &viewport, const QVector2D &inMouseCoords, const QVector2D &inWindowDimensions, bool inForceIntersect);
97     static QSSGOption<QSSGRenderRay> pickRay(const QSSGRenderCamera &camera, const QRectF &viewport, const QVector2D &inMouseCoords, const QVector2D &inWindowDimensions, bool inForceIntersect);
98 
99     // Checks the various viewports and determines if the layer is visible or not.
100     bool isLayerVisible() const;
101 
102 private:
103     // Viewport used when actually rendering.  In the case where this is an offscreen item then
104     // it may be different than the layer to presentation viewport.
105     QRectF layerRenderViewport() const;
106 };
107 QT_END_NAMESPACE
108 
109 #endif // QSSG_RENDER_LAYER_HELPER_IMPL_H
110