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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*
* Copyright 2019-2021 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/
#pragma once
#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || (PLATFORM_WIN32 && !defined(_MSC_VER))
// https://gcc.gnu.org/wiki/Visibility
# define API_QUALIFIER __attribute__((visibility("default")))
#elif PLATFORM_WIN32
# define API_QUALIFIER
#else
# error Unsupported platform
#endif
DILIGENT_BEGIN_NAMESPACE(Diligent)
DILIGENT_BEGIN_NAMESPACE(GLTF)
#if DILIGENT_CPP_INTERFACE
class ResourceManager;
struct GLTF_Transform;
#else
struct ResourceManager;
typedef struct ResourceManager ResourceManager;
struct GLTF_Transform
{
float Translation[3];
float _pad0;
float Scale[3];
float _pad1;
float Rotation[4];
float Matrix[4*4];
};
typedef struct GLTF_Transform GLTF_Transform;
#endif
struct GLTF_ResourceCacheUseInfo
{
ResourceManager* pResourceMgr DEFAULT_INITIALIZER(nullptr);
Uint8 IndexBufferIdx DEFAULT_INITIALIZER(0);
Uint8 VertexBuffer0Idx DEFAULT_INITIALIZER(0);
Uint8 VertexBuffer1Idx DEFAULT_INITIALIZER(0);
/// Base color texture format.
TEXTURE_FORMAT BaseColorFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
/// Base color texture format for alpha-cut and alpha-blend materials.
TEXTURE_FORMAT BaseColorAlphaFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
/// Physical descriptor texture format.
TEXTURE_FORMAT PhysicalDescFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
/// Normal map format.
TEXTURE_FORMAT NormalFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
/// Occlusion texture format.
TEXTURE_FORMAT OcclusionFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
/// Emissive texture format.
TEXTURE_FORMAT EmissiveFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
};
typedef struct GLTF_ResourceCacheUseInfo GLTF_ResourceCacheUseInfo;
enum GLTF_MAT_ALPHA_MODE
{
GLTF_MAT_ALPHA_MODE_OPAQUE = 0,
GLTF_MAT_ALPHA_MODE_MASK,
GLTF_MAT_ALPHA_MODE_BLEND,
GLTF_MAT_ALPHA_MODE_NUM_MODES
};
typedef enum GLTF_MAT_ALPHA_MODE GLTF_MAT_ALPHA_MODE;
enum GLTF_BUFFER_ID
{
GLTF_BUFFER_ID_VERTEX_BASIC_ATTRIBS = 0,
GLTF_BUFFER_ID_VERTEX_SKIN_ATTRIBS,
GLTF_BUFFER_ID_INDEX,
GLTF_BUFFER_ID_NUM_BUFFERS
};
typedef enum GLTF_BUFFER_ID GLTF_BUFFER_ID;
struct GLTF_TextureCacheType;
typedef struct GLTF_TextureCacheType GLTF_TextureCacheType;
enum GLTF_FILE_TYPE
{
GLTF_FILE_TYPE_UNKNOWN = 0,
GLTF_FILE_TYPE_ASCII,
GLTF_FILE_TYPE_BINARY,
};
typedef enum GLTF_FILE_TYPE GLTF_FILE_TYPE;
/// Model create information
struct IGLTFModelCreateInfo
{
/// File name
/// If FileName is provided, Data member must be null
const char* FileName DEFAULT_INITIALIZER(nullptr);
/// In-memory GLTF Data
/// If Data is provided, FileName member must be null
const void* Data DEFAULT_INITIALIZER(nullptr);
/// In-memory GLTF Data length
/// Data size (in bytes) must be provided if Data is not null
size_t DataSize DEFAULT_INITIALIZER(0);
/// File type
/// If GLTF_FILE_TYPE_UNKNOWN and File name is provided, this
/// is detected based on the file extension (.gltf / .glb).
/// If Data is provided, this must not be GLTF_FILE_TYPE_UNKNOWN.
GLTF_FILE_TYPE FileType DEFAULT_INITIALIZER(GLTF_FILE_TYPE_UNKNOWN);
/// Optional texture cache to use when loading the model.
/// The loader will try to find all the textures in the cache
/// and add all new textures to the cache.
GLTF_TextureCacheType* pTextureCache DEFAULT_INITIALIZER(nullptr);
/// Optional resource cache usage info.
GLTF_ResourceCacheUseInfo* pCacheInfo DEFAULT_INITIALIZER(nullptr);
/// Whether to load animation and initialize skin attributes
/// buffer.
bool LoadAnimationAndSkin DEFAULT_INITIALIZER(true);
};
typedef struct IGLTFModelCreateInfo IGLTFModelCreateInfo;
#define DILIGENT_INTERFACE_NAME IGLTFModel
#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
#define IGLTFModelInclusiveMethods \
IGLTFModelMethods GLTF_Model
// clang-format off
DILIGENT_BEGIN_INTERFACE1(IGLTFModel)
{
VIRTUAL void METHOD(UpdateAnimation)(THIS_ Uint32 index, float time) PURE;
VIRTUAL void METHOD(PrepareGPUResources)(THIS_ IRenderDevice* pDevice, IDeviceContext* pCtx) PURE;
VIRTUAL bool METHOD(IsGPUDataInitialized)(THIS) CONST PURE;
VIRTUAL void METHOD(Transform)(THIS_ const float* Matrix) PURE;
VIRTUAL IBuffer* METHOD(GetBuffer)(THIS_ GLTF_BUFFER_ID BuffId) PURE;
VIRTUAL ITexture* METHOD(GetTexture)(THIS_ Uint32 Index) PURE;
VIRTUAL bool METHOD(GetNodeIndex)(THIS_ const char* Name, Uint32* Idx) CONST PURE;
VIRTUAL void METHOD(GetNodeTransform)(THIS_ Uint32 Idx, GLTF_Transform* Transform) PURE;
VIRTUAL void METHOD(SetNodeTransform)(THIS_ Uint32 Idx, GLTF_Transform* Transform) PURE;
VIRTUAL void METHOD(UpdateTransforms)(THIS) PURE;
VIRTUAL Uint32 METHOD(GetFirstIndexLocation)(THIS) CONST PURE;
VIRTUAL Uint32 METHOD(GetBaseVertex)(THIS) CONST PURE;
};
DILIGENT_END_INTERFACE
#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
#if DILIGENT_C_INTERFACE
# define IGLTFModel_UpdateAnimation(This, ...) CALL_IFACE_METHOD(GLTF_Model, UpdateAnimation, This, __VA_ARGS__)
# define IGLTFModel_PrepareGPUResources(This, ...) CALL_IFACE_METHOD(GLTF_Model, PrepareGPUResources, This, __VA_ARGS__)
# define IGLTFModel_IsGPUDataInitialized(This) CALL_IFACE_METHOD(GLTF_Model, IsGPUDataInitialized, This)
# define IGLTFModel_Transform(This, ...) CALL_IFACE_METHOD(GLTF_Model, Transform, This, __VA_ARGS__)
# define IGLTFModel_GetBuffer(This, ...) CALL_IFACE_METHOD(GLTF_Model, GetBuffer, This, __VA_ARGS__)
# define IGLTFModel_GetTexture(This, ...) CALL_IFACE_METHOD(GLTF_Model, GetTexture, This, __VA_ARGS__)
# define IGLTFModel_GetNodeIndex(This, ...) CALL_IFACE_METHOD(GLTF_Model, GetNodeIndex, This, __VA_ARGS__)
# define IGLTFModel_GetNodeTransform(This, ...) CALL_IFACE_METHOD(GLTF_Model, GetNodeTransform, This, __VA_ARGS__)
# define IGLTFModel_SetNodeTransform(This, ...) CALL_IFACE_METHOD(GLTF_Model, SetNodeTransform, This, __VA_ARGS__)
# define IGLTFModel_UpdateTransforms(This) CALL_IFACE_METHOD(GLTF_Model, UpdateTransforms, This)
# define IGLTFModel_GetFirstIndexLocation(This) CALL_IFACE_METHOD(GLTF_Model, GetFirstIndexLocation, This)
# define IGLTFModel_GetBaseVertex(This) CALL_IFACE_METHOD(GLTF_Model, GetBaseVertex, This)
// clang-format on
/// Initializes the renderer
API_QUALIFIER
struct IGLTFModel* DILIGENT_GLOBAL_FUNCTION(IGLTFModel_Create)(IRenderDevice* pDevice,
IDeviceContext* pCtx,
const IGLTFModelCreateInfo* CI);
API_QUALIFIER
void DILIGENT_GLOBAL_FUNCTION(IGLTFModel_Destroy)(struct IGLTFModel* model);
#endif
DILIGENT_END_NAMESPACE // namespace GLTF
DILIGENT_END_NAMESPACE // namespace Diligent
|