/* * 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