summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/runtimerender/Qt3DSRenderWidgets.h
blob: 28cb33228ae944441201ad82ed97beebfdd7163c (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/****************************************************************************
**
** 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
#ifndef QT3DS_RENDER_WIDGETS_H
#define QT3DS_RENDER_WIDGETS_H
#include "Qt3DSRender.h"
#include "foundation/Qt3DSOption.h"
#include "foundation/Qt3DSMat44.h"
#include "foundation/Qt3DSMat33.h"
#include "foundation/Qt3DSBounds3.h"
#include "foundation/Qt3DSVec3.h"
#include "EASTL/utility.h"
#include "foundation/Qt3DSDataRef.h"
#include "render/Qt3DSRenderVertexBuffer.h"
#include "render/Qt3DSRenderIndexBuffer.h"
#include "Qt3DSRenderText.h"

namespace qt3ds {
namespace render {

    struct SWidgetRenderInformation
    {
        // Just the rotation component of the nodeparenttocamera.
        QT3DSMat33 m_NormalMatrix;
        // The node parent's global transform multiplied by the inverse camera global transfrom;
        // basically the MV from model-view-projection
        QT3DSMat44 m_NodeParentToCamera;
        // Projection that accounts for layer scaling
        QT3DSMat44 m_LayerProjection;
        // Pure camera projection without layer scaling
        QT3DSMat44 m_PureProjection;
        // A look at matrix that will rotate objects facing directly up
        // the Z axis such that the point to the camera.
        QT3DSMat33 m_LookAtMatrix;
        // Conversion from world to camera position so world points not in object
        // local space can be converted to camera space without going through the node's
        // inverse global transform
        QT3DSMat44 m_CameraGlobalInverse;
        // Offset to add to the node's world position in camera space to move to the ideal camera
        // location so that scale will work.  This offset should be added *after* translation into
        // camera space
        QT3DSVec3 m_WorldPosOffset;
        // Position in camera space to center the widget around
        QT3DSVec3 m_Position;
        // Scale factor to scale the widget by.
        QT3DSF32 m_Scale;

        // The camera used to render this object.
        SCamera *m_Camera;
        SWidgetRenderInformation(const QT3DSMat33 &inNormal, const QT3DSMat44 &inNodeParentToCamera,
                                 const QT3DSMat44 &inLayerProjection, const QT3DSMat44 &inProjection,
                                 const QT3DSMat33 &inLookAt, const QT3DSMat44 &inCameraGlobalInverse,
                                 const QT3DSVec3 &inWorldPosOffset, const QT3DSVec3 &inPos, QT3DSF32 inScale,
                                 SCamera &inCamera)
            : m_NormalMatrix(inNormal)
            , m_NodeParentToCamera(inNodeParentToCamera)
            , m_LayerProjection(inLayerProjection)
            , m_PureProjection(inProjection)
            , m_LookAtMatrix(inLookAt)
            , m_CameraGlobalInverse(inCameraGlobalInverse)
            , m_WorldPosOffset(inWorldPosOffset)
            , m_Position(inPos)
            , m_Scale(inScale)
            , m_Camera(&inCamera)
        {
        }
        SWidgetRenderInformation()
            : m_Camera(NULL)
        {
        }
    };
    typedef eastl::pair<SShaderVertexCodeGenerator &, SShaderFragmentCodeGenerator &>
        TShaderGeneratorPair;

    struct RenderWidgetModes
    {
        enum Enum {
            Local,
            Global,
        };
    };
    // Context used to get render data for the widget.
    class IRenderWidgetContext
    {
    protected:
        virtual ~IRenderWidgetContext() {}
    public:
        virtual NVRenderVertexBuffer &
        GetOrCreateVertexBuffer(CRegisteredString &inStr, QT3DSU32 stride,
                                NVConstDataRef<QT3DSU8> bufferData = NVConstDataRef<QT3DSU8>()) = 0;
        virtual NVRenderIndexBuffer &
        GetOrCreateIndexBuffer(CRegisteredString &inStr,
                               qt3ds::render::NVRenderComponentTypes::Enum componentType, size_t size,
                               NVConstDataRef<QT3DSU8> bufferData = NVConstDataRef<QT3DSU8>()) = 0;
        virtual NVRenderAttribLayout &
        CreateAttributeLayout(NVConstDataRef<qt3ds::render::NVRenderVertexBufferEntry> attribs) = 0;
        virtual NVRenderInputAssembler &
        GetOrCreateInputAssembler(CRegisteredString &inStr, NVRenderAttribLayout *attribLayout,
                                  NVConstDataRef<NVRenderVertexBuffer *> buffers,
                                  const NVRenderIndexBuffer *indexBuffer,
                                  NVConstDataRef<QT3DSU32> strides, NVConstDataRef<QT3DSU32> offsets) = 0;

        virtual NVRenderVertexBuffer *GetVertexBuffer(CRegisteredString &inStr) = 0;
        virtual NVRenderIndexBuffer *GetIndexBuffer(CRegisteredString &inStr) = 0;
        virtual NVRenderInputAssembler *GetInputAssembler(CRegisteredString &inStr) = 0;

        virtual NVRenderShaderProgram *GetShader(CRegisteredString inStr) = 0;
        virtual IShaderProgramGenerator &GetProgramGenerator() = 0;
        // calls compile on the program generator and stores result under this name.
        virtual NVRenderShaderProgram *CompileAndStoreShader(CRegisteredString inStr) = 0;
        virtual STextDimensions MeasureText(const STextRenderInfo &inText) = 0;
        // Render text using a specific MVP
        virtual void RenderText(const STextRenderInfo &inText, const QT3DSVec3 &inTextColor,
                                const QT3DSVec3 &inBackgroundColor, const QT3DSMat44 &inMVP) = 0;
        // Given a node and a point in the node's local space (most likely its pivot point), we
        // return
        // a normal matrix so you can get the axis out, a transformation from node to camera
        // a new position and a floating point scale factor so you can render in 1/2 perspective
        // mode
        // or orthographic mode if you would like to.
        virtual SWidgetRenderInformation
        GetWidgetRenderInformation(SNode &inNode, const QT3DSVec3 &inPos,
                                   RenderWidgetModes::Enum inWidgetMode) = 0;
    };

    class IRenderWidget
    {
    protected:
        virtual ~IRenderWidget() {}
        SNode *m_Node;

    public:
        IRenderWidget(SNode &inNode)
            : m_Node(&inNode)
        {
        }
        IRenderWidget()
            : m_Node(NULL)
        {
        }
        virtual void Render(IRenderWidgetContext &inWidgetContext,
                            NVRenderContext &inRenderContext) = 0;
        SNode &GetNode() { return *m_Node; }

        // Pure widgets.
        static IRenderWidget &CreateBoundingBoxWidget(SNode &inNode, const NVBounds3 &inBounds,
                                                      const QT3DSVec3 &inColor,
                                                      NVAllocatorCallback &inAlloc);
        static IRenderWidget &CreateAxisWidget(SNode &inNode, NVAllocatorCallback &inAlloc);
    };
}
}

#endif