summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Render/StudioWidget.h
blob: 1287612e1a25cbfe766101a5f39083843854879d (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
141
142
/****************************************************************************
**
** Copyright (C) 2006 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-EXCEPT$
** 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 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** 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$
**
****************************************************************************/
#ifndef QT3DS_STUDIO_RENDERER_WIDGET_H
#define QT3DS_STUDIO_RENDERER_WIDGET_H
#pragma once
#include "Qt3DSRenderWidgets.h"
#include "foundation/Qt3DSRefCounted.h"
#include "StudioPickValues.h"

namespace qt3ds {
namespace widgets {
    using namespace qt3ds::render;

    struct StudioWidgetTypes
    {
        enum Enum {
            Unknown,
            Translation,
            Scale,
            Rotation
        };
    };

    // These are also the ids used as colors in the pick image.
    struct StudioWidgetComponentIds
    {
        enum Enum {
            NoId = 0,
            XAxis,
            YAxis,
            ZAxis,
            XPlane,
            YPlane,
            ZPlane,
            CameraPlane,
            LastId,
        };
    };

    // Functionality shared between the path widget and the various manipulation gadgets
    class IStudioWidgetBase : public IRenderWidget, public NVRefCounted
    {
    public:
        virtual void SetNode(SNode &inNode) = 0;
        virtual void RenderPick(const QT3DSMat44 &inProjPreMult, NVRenderContext &inRenderContext,
                                QSize inWinDimensions) = 0;
        virtual qt3ds::studio::SStudioPickValue PickIndexToPickValue(QT3DSU32 inPickIndex) = 0;
    };

    typedef nvvector<QT3DSVec4> TResultVecType;

    struct SWidgetRenderSetupResult
    {
        QT3DSMat44 m_TranslationScale;
        QT3DSMat44 m_CameraTranslationScale;
        QT3DSMat44 m_PureProjection;
        SWidgetRenderInformation m_WidgetInfo;
        QT3DSMat44 m_SetupResult;

        SWidgetRenderSetupResult() {}
        SWidgetRenderSetupResult(IRenderWidgetContext &inWidgetContext, SNode &inNode,
                                 RenderWidgetModes::Enum inWidgetMode);
    };

    class IStudioWidget : public IStudioWidgetBase
    {
    public:
        static CRegisteredString GetSharedShaderName(IStringTable &inStrTable);
        static CRegisteredString GetSharedPickShaderName(IStringTable &inStrTable);
        static NVRenderShaderProgram *CreateWidgetShader(IRenderWidgetContext &inWidgetContext,
                                                         NVRenderContext &inRenderContext);
        static NVRenderShaderProgram *CreateWidgetPickShader(IRenderWidgetContext &inWidgetContext,
                                                             NVRenderContext &inRenderContext);
        static NVConstDataRef<qt3ds::render::NVRenderVertexBufferEntry>
        GetVertexBufferAttributesAndStride(QT3DSU32 &stride);
        static NVRenderInputAssembler *
        CreateRingedDisc(NVAllocatorCallback &inAllocator, IRenderWidgetContext &inWidgetContext,
                         NVRenderContext &inRenderContext, QT3DSVec3 inDirection, QT3DSVec3 inCenterPt,
                         QT3DSF32 inInnerRadius, QT3DSF32 inOuterRadius, QT3DSF32 inDiscColor,
                         QT3DSF32 inRingColor, const char *inItemName);
        static NVRenderInputAssembler *
        CreateAxis(NVAllocatorCallback &inAllocator, IRenderWidgetContext &inWidgetContext,
                   NVRenderContext &inRenderContext, const QT3DSVec3 &inAxisDirection,
                   QT3DSF32 inAxisStartOffset, QT3DSF32 inAxisLength, QT3DSF32 inTriLength,
                   QT3DSF32 inAxisWidth, QT3DSF32 inTriWidth, const char *inAxisName);
        static void CreateRect(QT3DSVec3 rectStart, QT3DSVec3 rectEnd, QT3DSVec3 orth1, QT3DSF32 axisHalfWidth,
                               QT3DSF32 inColorIndex, TResultVecType &outResult);
        static void CreateTriangle(QT3DSVec3 triStart, QT3DSVec3 triEnd, QT3DSVec3 orth1, QT3DSF32 triHalfWidth,
                                   QT3DSF32 inColorIndex, TResultVecType &outResult);

        void SetNode(SNode &inNode) override = 0;
        virtual void setAsAxisHelper(bool isAxisWidget) = 0;

        virtual StudioWidgetTypes::Enum GetWidgetType() const = 0;
        virtual void SetSubComponentId(int inSubComponentId) = 0;
        virtual void SetRenderWidgetMode(RenderWidgetModes::Enum inSpace) = 0;
        virtual RenderWidgetModes::Enum GetRenderWidgetMode() const = 0;
        // When we render the axis, we can scale the axis item itself
        virtual void SetAxisScale(const QT3DSVec3 &inNewScale) = 0;
        // Set the start/end positions of the rotation arc so the rotation gadget can show
        // the angle and optionally display an angle readout.  The start direction should
        // be a normalized direction in world space, and the angle should be in radians
        // inRotationAxis is expected to be a normalized direction in world space.
        virtual void SetRotationEdges(const QT3DSVec3 &inStartDirection, const QT3DSVec3 &inRotationAxis,
                                      QT3DSF32 inAngleRad, QT3DSF32 inEndLineLen) = 0;
        virtual void ClearRotationEdges() = 0;
        virtual bool isNodeBehindCamera() const = 0;

        static IStudioWidget &CreateTranslationWidget(NVAllocatorCallback &inAlloc);
        static IStudioWidget &CreateRotationWidget(NVAllocatorCallback &inAlloc);
        static IStudioWidget &CreateScaleWidget(NVAllocatorCallback &inAlloc);
    };
}
}

#endif