summaryrefslogtreecommitdiffstats
path: root/src/runtimerender/rendererimpl/Qt3DSRendererImplLayerRenderHelper.h
blob: 7d2254a801775014bc0462a920fa724a8e284e34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/****************************************************************************
**
** Copyright (C) 2008-2012 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#pragma once
#include "Qt3DSRender.h"
#include "foundation/Qt3DSVec2.h"
#include "render/Qt3DSRenderBaseTypes.h"
#include "Qt3DSRenderCamera.h"
#include "Qt3DSRenderContextCore.h"

namespace qt3ds {
namespace render {

    /**	An independent, testable entity to encapsulate taking at least:
     *  layer, current viewport rect, current scissor rect, presentation design dimensions
     *	and producing a set of rectangles:
     *	layer viewport rect (inside viewport rect and calculated using outer viewport rect info)
     *	layer scissor rect (inside current scissor rect)
     *	layer camera rect (may be the viewport rect)
     *
     *  In the case where we have to render offscreen for this layer then we need to handle produce
     *	a set of texture dimensions and the layer camera rect ends up being same size but with no
     *offsets.
     *
     *  This object should handle part of any translation from screenspace to global space.
     *	I am using language level access control on this object because it needs specific
     *	interface design that will enable future modifications.
     */
    struct SLayerRenderHelper
    {
    private:
        NVRenderRectF m_PresentationViewport;
        NVRenderRectF m_PresentationScissor;
        QT3DSVec2 m_PresentationDesignDimensions;
        SLayer *m_Layer;
        SCamera *m_Camera;
        SCamera *m_CameraLeftEye;
        SCamera *m_CameraRightEye;
        bool m_Offscreen;

        NVRenderRectF m_originalViewport;
        NVRenderRectF m_Viewport;
        NVRenderRectF m_Scissor;

        ScaleModes::Enum m_ScaleMode;

        StereoModes::Enum m_StereoMode = StereoModes::Mono;
        StereoViews::Enum m_StereoView = StereoViews::Mono;
        QT3DSF32 m_StereoEyeSeparation = 0.4f;

        QT3DSVec2 m_ScaleFactor;

    public:
        SLayerRenderHelper();

        SLayerRenderHelper(const NVRenderRectF &inPresentationViewport,
                           const NVRenderRectF &inPresentationScissor,
                           const QT3DSVec2 &inPresentationDesignDimensions, SLayer &inLayer,
                           bool inOffscreen, qt3ds::render::ScaleModes::Enum inScaleMode,
                           qt3ds::render::StereoModes::Enum inStereoMode,
                           qt3ds::render::StereoViews::Enum inStereoView,
                           double inStereoEyeSeparation,
                           qt3ds::QT3DSVec2 inScaleFactor);

        NVRenderRectF GetPresentationViewport() const { return m_PresentationViewport; }
        NVRenderRectF GetPresentationScissor() const { return m_PresentationScissor; }
        QT3DSVec2 GetPresentationDesignDimensions() const { return m_PresentationDesignDimensions; }
        SLayer *GetLayer() const { return m_Layer; }
        // Return currently used camera
        SCamera *GetCamera();
        bool IsOffscreen() const { return m_Offscreen; }

        bool isStereoscopic() const;
        // Get/set current stereo mode. Default mode is Mono (no stereo)
        StereoModes::Enum getStereoMode() const { return m_StereoMode; }
        void setStereoMode(StereoModes::Enum mode) { m_StereoMode = mode; }
        // Get/set eye (camera) separation.
        QT3DSF32 getEyeSeparation() const { return m_StereoEyeSeparation; }
        void setEyeSeparation(QT3DSF32 separation) { m_StereoEyeSeparation = separation; }

        void setViewport(const NVRenderRectF &viewport);
        // Does not differ whether offscreen or not, simply states how this layer maps to the
        // presentation
        NVRenderRectF getOriginalLayerToPresentationViewport() const;
        NVRenderRectF GetLayerToPresentationViewport(bool noStereo = false) const;
        // Does not differ whether offscreen or not, scissor rect of how this layer maps to
        // presentation.
        NVRenderRectF GetLayerToPresentationScissorRect(bool noStereo = false) const;

        QSize GetTextureDimensions() const;

        SCameraGlobalCalculationResult SetupCameraForRender(SCamera &inCamera);

        Option<QT3DSVec2> GetLayerMouseCoords(const QT3DSVec2 &inMouseCoords,
                                           const QT3DSVec2 &inWindowDimensions,
                                           bool inForceIntersect) const;

        Option<SRay> GetPickRay(const QT3DSVec2 &inMouseCoords, const QT3DSVec2 &inWindowDimensions,
                                bool inForceIntersect, bool sceneCameraView = false) const;

        // Checks the various viewports and determines if the layer is visible or not.
        bool IsLayerVisible() const;

    private:
        // Viewport used when actually rendering.  In the case where this is an offscreen item then
        // it may be
        // different than the layer to presentation viewport.
        NVRenderRectF GetLayerRenderViewport() const;

        void copyCameraProperties(SCamera *sourceCamera, SCamera *destinationCamera);
        void adjustCameraStereoSeparation();
    };
}
}