summaryrefslogtreecommitdiffstats
path: root/AssetLoader/interface/GLTFLoader.h
diff options
context:
space:
mode:
Diffstat (limited to 'AssetLoader/interface/GLTFLoader.h')
-rw-r--r--AssetLoader/interface/GLTFLoader.h178
1 files changed, 178 insertions, 0 deletions
diff --git a/AssetLoader/interface/GLTFLoader.h b/AssetLoader/interface/GLTFLoader.h
new file mode 100644
index 0000000..810a7c4
--- /dev/null
+++ b/AssetLoader/interface/GLTFLoader.h
@@ -0,0 +1,178 @@
+/*
+ * 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;
+#else
+ struct ResourceManager;
+ typedef struct ResourceManager ResourceManager;
+#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;
+
+/// Model create information
+struct IGLTFModelCreateInfo
+{
+ /// File name
+ const char* FileName DEFAULT_INITIALIZER(nullptr);
+
+ /// 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 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_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