summaryrefslogtreecommitdiffstats
path: root/src/runtimerender/Qt3DSRenderMesh.h
blob: d6959ec8b381bf1ac90b744d4f3f104e432ff8e0 (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
182
183
184
185
186
187
/****************************************************************************
**
** 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_MESH_H
#define QT3DS_RENDER_MESH_H
#include "Qt3DSRender.h"
#include "render/Qt3DSRenderVertexBuffer.h"
#include "render/Qt3DSRenderIndexBuffer.h"
#include "render/Qt3DSRenderInputAssembler.h"
#include "foundation/Qt3DSBounds3.h"
#include "foundation/StringTable.h"
#include "foundation/Qt3DSContainers.h"
#include "foundation/Qt3DSRefCounted.h"
#include "foundation/Qt3DSNoCopy.h"

namespace qt3ds {
namespace render {

    struct SRenderSubsetBase
    {
        QT3DSU32 m_Count;
        QT3DSU32 m_Offset;
        NVBounds3 m_Bounds; // Vertex buffer bounds
        SRenderSubsetBase() {}
        SRenderSubsetBase(const SRenderSubsetBase &inOther)
            : m_Count(inOther.m_Count)
            , m_Offset(inOther.m_Offset)
            , m_Bounds(inOther.m_Bounds)
        {
        }

        SRenderSubsetBase &operator=(const SRenderSubsetBase &inOther)
        {
            m_Count = inOther.m_Count;
            m_Offset = inOther.m_Offset;
            m_Bounds = inOther.m_Bounds;
            return *this;
        }
    };

    struct SRenderJoint
    {
        QT3DSI32 m_JointID;
        QT3DSI32 m_ParentID;
        QT3DSF32 m_invBindPose[16];
        QT3DSF32 m_localToGlobalBoneSpace[16];
    };

    struct SRenderSubset : public SRenderSubsetBase
    {
        NVRenderInputAssembler *m_InputAssembler;
        NVRenderInputAssembler *m_InputAssemblerDepth;
        NVRenderInputAssembler
            *m_InputAssemblerPoints; ///< similar to depth but ignores index buffer.
        NVRenderVertexBuffer *m_VertexBuffer;
        NVRenderVertexBuffer
            *m_PosVertexBuffer; ///< separate position buffer for fast depth path rendering
        NVRenderIndexBuffer *m_IndexBuffer;
        NVRenderDrawMode::Enum m_PrimitiveType; ///< primitive type used for drawing
        QT3DSF32 m_EdgeTessFactor; ///< edge tessellation amount used for tessellation shaders
        QT3DSF32 m_InnerTessFactor; ///< inner tessellation amount used for tessellation shaders
        bool m_WireframeMode; ///< true if we should draw the object as wireframe ( currently ony if
                              ///tessellation is enabled )
        NVConstDataRef<SRenderJoint> m_Joints;
        CRegisteredString m_Name;
        nvvector<SRenderSubsetBase> m_SubSubsets;

        SRenderSubset(NVAllocatorCallback &alloc)
            : m_InputAssembler(NULL)
            , m_InputAssemblerDepth(NULL)
            , m_InputAssemblerPoints(NULL)
            , m_VertexBuffer(NULL)
            , m_PosVertexBuffer(NULL)
            , m_IndexBuffer(NULL)
            , m_PrimitiveType(NVRenderDrawMode::Triangles)
            , m_EdgeTessFactor(1.0)
            , m_InnerTessFactor(1.0)
            , m_WireframeMode(false)
            , m_SubSubsets(alloc, "SRenderSubset::m_SubSubsets")
        {
        }
        SRenderSubset(const SRenderSubset &inOther)
            : SRenderSubsetBase(inOther)
            , m_InputAssembler(inOther.m_InputAssembler)
            , m_InputAssemblerDepth(inOther.m_InputAssemblerDepth)
            , m_InputAssemblerPoints(inOther.m_InputAssemblerPoints)
            , m_VertexBuffer(inOther.m_VertexBuffer)
            , m_PosVertexBuffer(inOther.m_PosVertexBuffer)
            , m_IndexBuffer(inOther.m_IndexBuffer)
            , m_PrimitiveType(inOther.m_PrimitiveType)
            , m_EdgeTessFactor(inOther.m_EdgeTessFactor)
            , m_InnerTessFactor(inOther.m_InnerTessFactor)
            , m_WireframeMode(inOther.m_WireframeMode)
            , m_Joints(inOther.m_Joints)
            , m_Name(inOther.m_Name)
            , m_SubSubsets(inOther.m_SubSubsets)
        {
        }
        // Note that subSubsets is *not* copied.
        SRenderSubset(NVAllocatorCallback &alloc, const SRenderSubset &inOther,
                      const SRenderSubsetBase &inBase)
            : SRenderSubsetBase(inBase)
            , m_InputAssembler(inOther.m_InputAssembler)
            , m_InputAssemblerDepth(inOther.m_InputAssemblerDepth)
            , m_InputAssemblerPoints(inOther.m_InputAssemblerPoints)
            , m_VertexBuffer(inOther.m_VertexBuffer)
            , m_PosVertexBuffer(inOther.m_PosVertexBuffer)
            , m_IndexBuffer(inOther.m_IndexBuffer)
            , m_PrimitiveType(inOther.m_PrimitiveType)
            , m_EdgeTessFactor(inOther.m_EdgeTessFactor)
            , m_InnerTessFactor(inOther.m_InnerTessFactor)
            , m_WireframeMode(inOther.m_WireframeMode)
            , m_Name(inOther.m_Name)
            , m_SubSubsets(alloc, "SRenderSubset::m_SubSubsets")
        {
        }

        SRenderSubset &operator=(const SRenderSubset &inOther)
        {
            if (this != &inOther) {
                SRenderSubsetBase::operator=(inOther);
                m_InputAssembler = inOther.m_InputAssembler;
                m_InputAssemblerDepth = inOther.m_InputAssemblerDepth;
                m_VertexBuffer = inOther.m_VertexBuffer;
                m_PosVertexBuffer = inOther.m_PosVertexBuffer;
                m_IndexBuffer = inOther.m_IndexBuffer;
                m_PrimitiveType = inOther.m_PrimitiveType;
                m_EdgeTessFactor = inOther.m_EdgeTessFactor;
                m_InnerTessFactor = inOther.m_InnerTessFactor;
                m_WireframeMode = inOther.m_WireframeMode;
                m_Joints = inOther.m_Joints;
                m_Name = inOther.m_Name;
                m_SubSubsets = inOther.m_SubSubsets;
            }
            return *this;
        }
    };

    struct SRenderMesh : public NoCopy
    {
        nvvector<SRenderSubset> m_Subsets;
        nvvector<SRenderJoint> m_Joints;
        NVRenderDrawMode::Enum m_DrawMode;
        NVRenderWinding::Enum m_Winding; // counterclockwise
        QT3DSU32 m_MeshId; // Id from the file of this mesh.

        SRenderMesh(NVRenderDrawMode::Enum inDrawMode, NVRenderWinding::Enum inWinding,
                    QT3DSU32 inMeshId, NVAllocatorCallback &alloc)
            : m_Subsets(alloc, "SRenderMesh::m_Subsets")
            , m_Joints(alloc, "SRenderMesh::Joints")
            , m_DrawMode(inDrawMode)
            , m_Winding(inWinding)
            , m_MeshId(inMeshId)
        {
        }
    };
}
}

#endif