diff --git a/GLTFSceneKit.xcodeproj/project.pbxproj b/GLTFSceneKit.xcodeproj/project.pbxproj index ce081700..cc56f4c0 100644 --- a/GLTFSceneKit.xcodeproj/project.pbxproj +++ b/GLTFSceneKit.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 48; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -43,6 +43,21 @@ 49FBB51227670C3200674883 /* GLTFShaderModifierSurface_pbrSpecularGlossiness_texture_doubleSidedWorkaround.shader in Resources */ = {isa = PBXBuildFile; fileRef = 49D5C8B42767081E0076FB22 /* GLTFShaderModifierSurface_pbrSpecularGlossiness_texture_doubleSidedWorkaround.shader */; }; 49FBB51327670C3200674883 /* GLTFShaderModifierFragment_alphaCutoff.shader in Resources */ = {isa = PBXBuildFile; fileRef = 49D5C8B52767081E0076FB22 /* GLTFShaderModifierFragment_alphaCutoff.shader */; }; 49FBB51427670C3200674883 /* GLTFShaderModifierSurface_doubleSidedWorkaround.shader in Resources */ = {isa = PBXBuildFile; fileRef = 49D5C8B62767081E0076FB22 /* GLTFShaderModifierSurface_doubleSidedWorkaround.shader */; }; + 5988D75B2B182A4300CAE98E /* KTXLoader.docc in Sources */ = {isa = PBXBuildFile; fileRef = 5988D75A2B182A4300CAE98E /* KTXLoader.docc */; }; + 5988D7612B182A4400CAE98E /* KTXLoader.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5988D7572B182A4300CAE98E /* KTXLoader.framework */; }; + 5988D7682B182A4400CAE98E /* KTXLoaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5988D7672B182A4400CAE98E /* KTXLoaderTests.swift */; }; + 5988D7692B182A4400CAE98E /* KTXLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 5988D7592B182A4300CAE98E /* KTXLoader.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5988D7742B182AA500CAE98E /* KTXLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5988D7462B170D1000CAE98E /* KTXLoader.mm */; }; + 5988D77C2B182F0000CAE98E /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5988D77B2B182F0000CAE98E /* Metal.framework */; }; + 59EF3D022B1DABAF00002972 /* GLTFKTX2Support.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EF3D002B1DABAF00002972 /* GLTFKTX2Support.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 59EF3D052B1DB13F00002972 /* GLTFKTX2Support.mm in Sources */ = {isa = PBXBuildFile; fileRef = 59EF3D042B1DB13F00002972 /* GLTFKTX2Support.mm */; }; + 59EF3D0B2B1F0CF100002972 /* KTXLoader.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5988D7572B182A4300CAE98E /* KTXLoader.framework */; platformFilter = ios; }; + 59EF3D0C2B1F0CF100002972 /* KTXLoader.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5988D7572B182A4300CAE98E /* KTXLoader.framework */; platformFilter = ios; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 59EF3D0E2B1F0CF400002972 /* KTXLoader.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5988D7572B182A4300CAE98E /* KTXLoader.framework */; }; + 59EF3D0F2B1F0CF400002972 /* KTXLoader.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5988D7572B182A4300CAE98E /* KTXLoader.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 59EF3D112B1F0EEB00002972 /* ktx.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59EF3D082B1EFA8000002972 /* ktx.xcframework */; }; + 59EF3D122B1F0EEB00002972 /* ktx.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 59EF3D082B1EFA8000002972 /* ktx.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 59EF3D142B1F114400002972 /* art.scnassets in Resources */ = {isa = PBXBuildFile; fileRef = DDE6FDA61F46716500CB11D6 /* art.scnassets */; }; DD10459A1F47723D004B20CE /* GLTFTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1045991F47723D004B20CE /* GLTFTypes.swift */; }; DD10459C1F4772E3004B20CE /* GLTFErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD10459B1F4772E3004B20CE /* GLTFErrors.swift */; }; DD2E982E1F4CF5B800D47C89 /* ExtensionList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E982D1F4CF5B800D47C89 /* ExtensionList.swift */; }; @@ -143,6 +158,34 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 5988D7622B182A4400CAE98E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DD8392431F466C2D006A1CAC /* Project object */; + proxyType = 1; + remoteGlobalIDString = 5988D7562B182A4300CAE98E; + remoteInfo = KTXLoader; + }; + 5988D7642B182A4400CAE98E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DD8392431F466C2D006A1CAC /* Project object */; + proxyType = 1; + remoteGlobalIDString = DDB221D91F525D6E002CFA4D; + remoteInfo = GLTFSceneKitSample_iOS; + }; + 5988D7792B182C7600CAE98E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DD8392431F466C2D006A1CAC /* Project object */; + proxyType = 1; + remoteGlobalIDString = 5988D7562B182A4300CAE98E; + remoteInfo = KTXLoader; + }; + 59A97D722B22FC6D00E3745B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DD8392431F466C2D006A1CAC /* Project object */; + proxyType = 1; + remoteGlobalIDString = 5988D7562B182A4300CAE98E; + remoteInfo = KTXLoader; + }; DDC376C61F5286FD0015764C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = DD8392431F466C2D006A1CAC /* Project object */; @@ -160,6 +203,39 @@ /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ + 59EF3D0D2B1F0CF100002972 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 59EF3D0C2B1F0CF100002972 /* KTXLoader.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; + 59EF3D102B1F0CF400002972 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 59EF3D0F2B1F0CF400002972 /* KTXLoader.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; + 59EF3D132B1F0EEB00002972 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 59EF3D122B1F0EEB00002972 /* ktx.xcframework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; DDC376C81F5286FD0015764C /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -204,6 +280,17 @@ 49DFA9BD26A45A710009965E /* GLTFSceneKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLTFSceneKit.h; sourceTree = ""; }; 49DFA9C026A47D520009965E /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 49DFAA2F26A4FC9F0009965E /* GLTFVRM_VRM.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GLTFVRM_VRM.swift; sourceTree = ""; }; + 5988D7462B170D1000CAE98E /* KTXLoader.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KTXLoader.mm; sourceTree = ""; }; + 5988D7482B170F7C00CAE98E /* KTX-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KTX-Bridging-Header.h"; sourceTree = ""; }; + 5988D7572B182A4300CAE98E /* KTXLoader.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KTXLoader.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 5988D7592B182A4300CAE98E /* KTXLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KTXLoader.h; sourceTree = ""; }; + 5988D75A2B182A4300CAE98E /* KTXLoader.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = KTXLoader.docc; sourceTree = ""; }; + 5988D7602B182A4300CAE98E /* KTXLoaderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KTXLoaderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 5988D7672B182A4400CAE98E /* KTXLoaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KTXLoaderTests.swift; sourceTree = ""; }; + 5988D77B2B182F0000CAE98E /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; + 59EF3D002B1DABAF00002972 /* GLTFKTX2Support.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLTFKTX2Support.h; sourceTree = ""; }; + 59EF3D042B1DB13F00002972 /* GLTFKTX2Support.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GLTFKTX2Support.mm; sourceTree = ""; }; + 59EF3D082B1EFA8000002972 /* ktx.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = ktx.xcframework; sourceTree = ""; }; DD1045991F47723D004B20CE /* GLTFTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLTFTypes.swift; sourceTree = ""; }; DD10459B1F4772E3004B20CE /* GLTFErrors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLTFErrors.swift; sourceTree = ""; }; DD2E982D1F4CF5B800D47C89 /* ExtensionList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionList.swift; sourceTree = ""; }; @@ -267,10 +354,28 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 5988D7542B182A4300CAE98E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5988D77C2B182F0000CAE98E /* Metal.framework in Frameworks */, + 59EF3D112B1F0EEB00002972 /* ktx.xcframework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5988D75D2B182A4300CAE98E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5988D7612B182A4400CAE98E /* KTXLoader.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD3EB06D1F52476B009F32D2 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 59EF3D0B2B1F0CF100002972 /* KTXLoader.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -278,6 +383,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 59EF3D0E2B1F0CF400002972 /* KTXLoader.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -345,6 +451,43 @@ path = KHR_materials_pbrSpecularGlossiness; sourceTree = ""; }; + 5988D7442B170CA900CAE98E /* libktx */ = { + isa = PBXGroup; + children = ( + 59EF3D082B1EFA8000002972 /* ktx.xcframework */, + ); + path = libktx; + sourceTree = ""; + }; + 5988D7582B182A4300CAE98E /* KTXLoader */ = { + isa = PBXGroup; + children = ( + 5988D7442B170CA900CAE98E /* libktx */, + 5988D7592B182A4300CAE98E /* KTXLoader.h */, + 5988D7462B170D1000CAE98E /* KTXLoader.mm */, + 59EF3D002B1DABAF00002972 /* GLTFKTX2Support.h */, + 59EF3D042B1DB13F00002972 /* GLTFKTX2Support.mm */, + 5988D75A2B182A4300CAE98E /* KTXLoader.docc */, + ); + path = KTXLoader; + sourceTree = ""; + }; + 5988D7662B182A4400CAE98E /* KTXLoaderTests */ = { + isa = PBXGroup; + children = ( + 5988D7672B182A4400CAE98E /* KTXLoaderTests.swift */, + ); + path = KTXLoaderTests; + sourceTree = ""; + }; + 5988D7762B182C3400CAE98E /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5988D77B2B182F0000CAE98E /* Metal.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; DD2E982B1F4CF55400D47C89 /* extensions */ = { isa = PBXGroup; children = ( @@ -369,8 +512,11 @@ children = ( 49DFA9C026A47D520009965E /* Package.swift */, DD83924E1F466C2D006A1CAC /* Sources */, + 5988D7582B182A4300CAE98E /* KTXLoader */, + 5988D7662B182A4400CAE98E /* KTXLoaderTests */, DD83924D1F466C2D006A1CAC /* Products */, DDE6FD831F46708100CB11D6 /* Sample */, + 5988D7762B182C3400CAE98E /* Frameworks */, ); sourceTree = ""; }; @@ -381,6 +527,8 @@ DDE6FDB41F4671B000CB11D6 /* GLTFSceneKitSample.app */, DD3EB0711F52476B009F32D2 /* GLTFSceneKit.framework */, DDB221DA1F525D6E002CFA4D /* GLTFSceneKitSample.app */, + 5988D7572B182A4300CAE98E /* KTXLoader.framework */, + 5988D7602B182A4300CAE98E /* KTXLoaderTests.xctest */, ); name = Products; sourceTree = ""; @@ -404,6 +552,7 @@ DDB221EF1F525E93002CFA4D /* iOS */ = { isa = PBXGroup; children = ( + 5988D7482B170F7C00CAE98E /* KTX-Bridging-Header.h */, DDB221F01F525E93002CFA4D /* AppDelegate.swift */, DDB221F11F525E93002CFA4D /* Assets.xcassets */, DDB221F21F525E93002CFA4D /* LaunchScreen.storyboard */, @@ -516,6 +665,15 @@ /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ + 5988D7522B182A4300CAE98E /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 59EF3D022B1DABAF00002972 /* GLTFKTX2Support.h in Headers */, + 5988D7692B182A4400CAE98E /* KTXLoader.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD3EB06E1F52476B009F32D2 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -535,18 +693,58 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 5988D7562B182A4300CAE98E /* KTXLoader */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5988D76E2B182A4500CAE98E /* Build configuration list for PBXNativeTarget "KTXLoader" */; + buildPhases = ( + 5988D7522B182A4300CAE98E /* Headers */, + 5988D7532B182A4300CAE98E /* Sources */, + 5988D7542B182A4300CAE98E /* Frameworks */, + 5988D7552B182A4300CAE98E /* Resources */, + 59EF3D132B1F0EEB00002972 /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = KTXLoader; + productName = KTXLoader; + productReference = 5988D7572B182A4300CAE98E /* KTXLoader.framework */; + productType = "com.apple.product-type.framework"; + }; + 5988D75F2B182A4300CAE98E /* KTXLoaderTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5988D7712B182A4500CAE98E /* Build configuration list for PBXNativeTarget "KTXLoaderTests" */; + buildPhases = ( + 5988D75C2B182A4300CAE98E /* Sources */, + 5988D75D2B182A4300CAE98E /* Frameworks */, + 5988D75E2B182A4300CAE98E /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 5988D7632B182A4400CAE98E /* PBXTargetDependency */, + 5988D7652B182A4400CAE98E /* PBXTargetDependency */, + ); + name = KTXLoaderTests; + productName = KTXLoaderTests; + productReference = 5988D7602B182A4300CAE98E /* KTXLoaderTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; DD3EB0701F52476B009F32D2 /* GLTFSceneKit_iOS */ = { isa = PBXNativeTarget; buildConfigurationList = DD3EB0781F52476C009F32D2 /* Build configuration list for PBXNativeTarget "GLTFSceneKit_iOS" */; buildPhases = ( + DD3EB06E1F52476B009F32D2 /* Headers */, DD3EB06C1F52476B009F32D2 /* Sources */, DD3EB06D1F52476B009F32D2 /* Frameworks */, - DD3EB06E1F52476B009F32D2 /* Headers */, DD3EB06F1F52476B009F32D2 /* Resources */, + 59EF3D0D2B1F0CF100002972 /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( + 5988D77A2B182C7600CAE98E /* PBXTargetDependency */, ); name = GLTFSceneKit_iOS; productName = GLTFSceneKit_iOS; @@ -561,10 +759,12 @@ DD8392481F466C2D006A1CAC /* Frameworks */, DD8392491F466C2D006A1CAC /* Headers */, DD83924A1F466C2D006A1CAC /* Resources */, + 59EF3D102B1F0CF400002972 /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( + 59A97D732B22FC6D00E3745B /* PBXTargetDependency */, ); name = GLTFSceneKit_macOS; productName = GLTFSceneKit; @@ -615,13 +815,20 @@ DD8392431F466C2D006A1CAC /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0900; + LastSwiftUpdateCheck = 1510; LastUpgradeCheck = 1000; ORGANIZATIONNAME = DarkHorse; TargetAttributes = { + 5988D7562B182A4300CAE98E = { + CreatedOnToolsVersion = 15.1; + }; + 5988D75F2B182A4300CAE98E = { + CreatedOnToolsVersion = 15.1; + TestTargetID = DDB221D91F525D6E002CFA4D; + }; DD3EB0701F52476B009F32D2 = { CreatedOnToolsVersion = 9.0; - LastSwiftMigration = 1000; + LastSwiftMigration = 1510; }; DD83924B1F466C2D006A1CAC = { CreatedOnToolsVersion = 9.0; @@ -657,11 +864,28 @@ DD3EB0701F52476B009F32D2 /* GLTFSceneKit_iOS */, DDE6FDB31F4671B000CB11D6 /* GLTFSceneKitSample_macOS */, DDB221D91F525D6E002CFA4D /* GLTFSceneKitSample_iOS */, + 5988D7562B182A4300CAE98E /* KTXLoader */, + 5988D75F2B182A4300CAE98E /* KTXLoaderTests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 5988D7552B182A4300CAE98E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5988D75E2B182A4300CAE98E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 59EF3D142B1F114400002972 /* art.scnassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD3EB06F1F52476B009F32D2 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -719,6 +943,24 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 5988D7532B182A4300CAE98E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5988D7742B182AA500CAE98E /* KTXLoader.mm in Sources */, + 59EF3D052B1DB13F00002972 /* GLTFKTX2Support.mm in Sources */, + 5988D75B2B182A4300CAE98E /* KTXLoader.docc in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5988D75C2B182A4300CAE98E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5988D7682B182A4400CAE98E /* KTXLoaderTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD3EB06C1F52476B009F32D2 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -851,6 +1093,27 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 5988D7632B182A4400CAE98E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 5988D7562B182A4300CAE98E /* KTXLoader */; + targetProxy = 5988D7622B182A4400CAE98E /* PBXContainerItemProxy */; + }; + 5988D7652B182A4400CAE98E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = DDB221D91F525D6E002CFA4D /* GLTFSceneKitSample_iOS */; + targetProxy = 5988D7642B182A4400CAE98E /* PBXContainerItemProxy */; + }; + 5988D77A2B182C7600CAE98E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + platformFilter = ios; + target = 5988D7562B182A4300CAE98E /* KTXLoader */; + targetProxy = 5988D7792B182C7600CAE98E /* PBXContainerItemProxy */; + }; + 59A97D732B22FC6D00E3745B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 5988D7562B182A4300CAE98E /* KTXLoader */; + targetProxy = 59A97D722B22FC6D00E3745B /* PBXContainerItemProxy */; + }; DDC376C71F5286FD0015764C /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = DD3EB0701F52476B009F32D2 /* GLTFSceneKit_iOS */; @@ -891,13 +1154,184 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ - DD3EB0761F52476C009F32D2 /* Debug */ = { + 5988D76F2B182A4500CAE98E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = EF37D6UQZ9; + DEVELOPMENT_TEAM = ""; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/KTXLoader/libktx", + ); + GCC_C_LANGUAGE_STANDARD = c17; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/KTXLoader"; + INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 DarkHorse. All rights reserved."; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 12.1; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "c17 c++20"; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.screeningeagle.KTXLoader; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator"; + SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2,7"; + }; + name = Debug; + }; + 5988D7702B182A4500CAE98E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/KTXLoader/libktx", + ); + GCC_C_LANGUAGE_STANDARD = c17; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/KTXLoader"; + INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 DarkHorse. All rights reserved."; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 12.1; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "c17 c++20"; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.screeningeagle.KTXLoader; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator"; + SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2,7"; + }; + name = Release; + }; + 5988D7722B182A4500CAE98E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 79SQK82M6R; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.2; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.1; + MARKETING_VERSION = 1.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.screeningeagle.KTXLoaderTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GLTFSceneKitSample.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/GLTFSceneKitSample"; + }; + name = Debug; + }; + 5988D7732B182A4500CAE98E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 79SQK82M6R; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.2; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.1; + MARKETING_VERSION = 1.0; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.screeningeagle.KTXLoaderTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GLTFSceneKitSample.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/GLTFSceneKitSample"; + }; + name = Release; + }; + DD3EB0761F52476C009F32D2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUILD_LIBRARY_FOR_DISTRIBUTION = YES; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -905,14 +1339,19 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/GLTFSceneKit/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MARKETING_VERSION = 0.3.0; OTHER_CFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = jp.0spec.GLTFSceneKit; PRODUCT_NAME = GLTFSceneKit; - SDKROOT = iphoneos; + SDKROOT = auto; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG SEEMS_TO_HAVE_VALIDATE_VERTEX_ATTRIBUTE_BUG SEEMS_TO_HAVE_PNG_LOADING_BUG"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2,6"; }; @@ -921,10 +1360,11 @@ DD3EB0771F52476C009F32D2 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + BUILD_LIBRARY_FOR_DISTRIBUTION = YES; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = EF37D6UQZ9; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -932,12 +1372,16 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/GLTFSceneKit/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MARKETING_VERSION = 0.3.0; OTHER_CFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = jp.0spec.GLTFSceneKit; PRODUCT_NAME = GLTFSceneKit; - SDKROOT = iphoneos; + SDKROOT = auto; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "SEEMS_TO_HAVE_VALIDATE_VERTEX_ATTRIBUTE_BUG SEEMS_TO_HAVE_PNG_LOADING_BUG"; SWIFT_VERSION = 4.2; @@ -956,6 +1400,7 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; @@ -1000,6 +1445,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 11.0; MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; + MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; @@ -1019,6 +1465,7 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; @@ -1057,8 +1504,10 @@ IPHONEOS_DEPLOYMENT_TARGET = 11.0; MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1079,7 +1528,10 @@ GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; INFOPLIST_FILE = "$(SRCROOT)/Sources/GLTFSceneKit/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.13; MARKETING_VERSION = 0.3.0; OTHER_CFLAGS = ""; @@ -1108,7 +1560,10 @@ GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; INFOPLIST_FILE = "$(SRCROOT)/Sources/GLTFSceneKit/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.13; MARKETING_VERSION = 0.3.0; OTHER_CFLAGS = ""; @@ -1128,10 +1583,17 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; - DEVELOPMENT_TEAM = EF37D6UQZ9; + DEVELOPMENT_TEAM = ""; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Sources/KTXLoader/libktx", + ); INFOPLIST_FILE = "$(SRCROOT)/Sample/iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MARKETING_VERSION = 0.3.0; PRODUCT_BUNDLE_IDENTIFIER = jp.0spec.GLTFSceneKitSample; PRODUCT_NAME = GLTFSceneKitSample; @@ -1147,10 +1609,17 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; - DEVELOPMENT_TEAM = EF37D6UQZ9; + DEVELOPMENT_TEAM = ""; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Sources/KTXLoader/libktx", + ); INFOPLIST_FILE = "$(SRCROOT)/Sample/iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MARKETING_VERSION = 0.3.0; PRODUCT_BUNDLE_IDENTIFIER = jp.0spec.GLTFSceneKitSample; PRODUCT_NAME = GLTFSceneKitSample; @@ -1167,10 +1636,14 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Sample/macOS/GameSample.entitlements; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = EF37D6UQZ9; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/Sample/macOS/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.13; MARKETING_VERSION = 0.3.0; PRODUCT_BUNDLE_IDENTIFIER = "jp.0spec.GLTFSceneKitSample-macOS"; @@ -1186,10 +1659,14 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Sample/macOS/GameSample.entitlements; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = EF37D6UQZ9; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/Sample/macOS/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.13; MARKETING_VERSION = 0.3.0; PRODUCT_BUNDLE_IDENTIFIER = "jp.0spec.GLTFSceneKitSample-macOS"; @@ -1202,6 +1679,24 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 5988D76E2B182A4500CAE98E /* Build configuration list for PBXNativeTarget "KTXLoader" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5988D76F2B182A4500CAE98E /* Debug */, + 5988D7702B182A4500CAE98E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5988D7712B182A4500CAE98E /* Build configuration list for PBXNativeTarget "KTXLoaderTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5988D7722B182A4500CAE98E /* Debug */, + 5988D7732B182A4500CAE98E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; DD3EB0781F52476C009F32D2 /* Build configuration list for PBXNativeTarget "GLTFSceneKit_iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/GLTFSceneKit.xcodeproj/xcshareddata/xcschemes/GLTFSceneKitSample_iOS.xcscheme b/GLTFSceneKit.xcodeproj/xcshareddata/xcschemes/GLTFSceneKitSample_iOS.xcscheme new file mode 100644 index 00000000..1514565e --- /dev/null +++ b/GLTFSceneKit.xcodeproj/xcshareddata/xcschemes/GLTFSceneKitSample_iOS.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GLTFSceneKit.xcodeproj/xcshareddata/xcschemes/KTXLoaderTests.xcscheme b/GLTFSceneKit.xcodeproj/xcshareddata/xcschemes/KTXLoaderTests.xcscheme new file mode 100644 index 00000000..8a22fd31 --- /dev/null +++ b/GLTFSceneKit.xcodeproj/xcshareddata/xcschemes/KTXLoaderTests.xcscheme @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/KTXLoader/GLTFKTX2Support.h b/KTXLoader/GLTFKTX2Support.h new file mode 100644 index 00000000..151f1af5 --- /dev/null +++ b/KTXLoader/GLTFKTX2Support.h @@ -0,0 +1,18 @@ + +#import + +NS_ASSUME_NONNULL_BEGIN + +extern NSString *const GLTFMediaTypeKTX2; + +extern MTLPixelFormat GLTFMetalPixelFormatForVkFormat(int vkformat); + +extern id _Nullable GLTFCreateTextureFromKTX2Data(NSData *data, id device); + +extern BOOL GLTFMetalDeviceSupportsETC(id device); + +extern BOOL GLTFMetalDeviceSupportsASTC(id device); + +extern BOOL GLTFMetalDeviceSupportsBC(id device); + +NS_ASSUME_NONNULL_END diff --git a/KTXLoader/GLTFKTX2Support.mm b/KTXLoader/GLTFKTX2Support.mm new file mode 100644 index 00000000..fea66958 --- /dev/null +++ b/KTXLoader/GLTFKTX2Support.mm @@ -0,0 +1,285 @@ + +#import "GLTFKTX2Support.h" + +NSString *const GLTFMediaTypeKTX2 = @"image/ktx2"; + +#import + +MTLPixelFormat GLTFMetalPixelFormatForVkFormat(int vkformat); + +BOOL GLTFMetalDeviceSupportsETC(id device) { + if (@available(macos 10.15, iOS 13.0, *)) { + return [device supportsFamily:MTLGPUFamilyApple8] || + [device supportsFamily:MTLGPUFamilyApple7] || + [device supportsFamily:MTLGPUFamilyApple6] || + [device supportsFamily:MTLGPUFamilyApple5] || + [device supportsFamily:MTLGPUFamilyApple4] || + [device supportsFamily:MTLGPUFamilyApple3] || + [device supportsFamily:MTLGPUFamilyApple2]; + } +#if TARGET_OS_IPHONE && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION) + if (@available(iOS 12.0, *)) { + return [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily5_v1] || + [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1] || + [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1] || + [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v1] || + [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v1]; + } +#endif + return NO; +} + +BOOL GLTFMetalDeviceSupportsASTC(id device) { + if (@available(macos 10.15, iOS 13.0, *)) { + return [device supportsFamily:MTLGPUFamilyApple8] || + [device supportsFamily:MTLGPUFamilyApple7] || + [device supportsFamily:MTLGPUFamilyApple6] || + [device supportsFamily:MTLGPUFamilyApple5] || + [device supportsFamily:MTLGPUFamilyApple4] || + [device supportsFamily:MTLGPUFamilyApple3] || + [device supportsFamily:MTLGPUFamilyApple2]; + } +#if TARGET_OS_IPHONE && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION) + if (@available(iOS 12.0, *)) { + return [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily5_v1] || + [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1] || + [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1] || + [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v1]; + } +#endif + return NO; +} + +BOOL GLTFMetalDeviceSupportsBC(id device) { + BOOL hasRuntimeSupport = NO; + if (@available(macos 11.0, iOS 16.4, *)) { + hasRuntimeSupport = [device supportsBCTextureCompression]; + } + if (@available(macos 10.15, iOS 13.0, *)) { + return [device supportsFamily:MTLGPUFamilyMac2] || hasRuntimeSupport; + } + return NO; +} + +id GLTFCreateTextureFromKTX2Data(NSData *data, id device) { + KTX_error_code result; + uint32_t flags = KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT | + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT | + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT; + + ktxTexture2 *ktx2Texture = NULL; + ktx_size_t size = [data length]; + const ktx_uint8_t *bytes = (const ktx_uint8_t *)[data bytes]; + result = ktxTexture2_CreateFromMemory(bytes, size, flags, &ktx2Texture); + if (result != KTX_SUCCESS) { + return nil; + } + + if (ktxTexture2_NeedsTranscoding(ktx2Texture)) { + BOOL deviceHasASTC = GLTFMetalDeviceSupportsASTC(device); + BOOL deviceHasETC2 = GLTFMetalDeviceSupportsETC(device); + BOOL deviceHasBC = GLTFMetalDeviceSupportsBC(device); + + khr_df_model_e colorModel = ktxTexture2_GetColorModel_e(ktx2Texture); + + ktx_transcode_fmt_e tf = KTX_TTF_NOSELECTION; + if (colorModel == KHR_DF_MODEL_UASTC && deviceHasASTC) { + tf = KTX_TTF_ASTC_4x4_RGBA; + } else if (colorModel == KHR_DF_MODEL_ETC1S && deviceHasETC2) { + tf = KTX_TTF_ETC; + } else if (deviceHasASTC) { + tf = KTX_TTF_ASTC_4x4_RGBA; + } else if (deviceHasETC2) { + tf = KTX_TTF_ETC2_RGBA; + } else if (deviceHasBC) { + tf = KTX_TTF_BC3_RGBA; + } + + result = ktxTexture2_TranscodeBasis(ktx2Texture, tf, 0); + } + + MTLTextureType type = MTLTextureType2D; + MTLPixelFormat pixelFormat = GLTFMetalPixelFormatForVkFormat(ktx2Texture->vkFormat); + + BOOL genMipmaps = ktx2Texture->generateMipmaps; + NSUInteger levelCount = ktx2Texture->numLevels; + NSUInteger baseWidth = ktx2Texture->baseWidth; + NSUInteger baseHeight = ktx2Texture->baseHeight; + NSUInteger baseDepth = ktx2Texture->baseDepth; + NSUInteger maxMipLevelCount = floor(log2(MAX(baseWidth, baseHeight))) + 1; + NSUInteger storedMipLevelCount = genMipmaps ? maxMipLevelCount : levelCount; + + MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor new]; + textureDescriptor.textureType = type; + textureDescriptor.pixelFormat = pixelFormat; + textureDescriptor.width = baseWidth; + textureDescriptor.height = (ktx2Texture->numDimensions > 1) ? baseHeight : 1; + textureDescriptor.depth = (ktx2Texture->numDimensions > 2) ? baseDepth : 1; + textureDescriptor.usage = MTLTextureUsageShaderRead; + textureDescriptor.storageMode = MTLStorageModeShared; +#if TARGET_OS_OSX + if (!device.hasUnifiedMemory) { + textureDescriptor.storageMode = MTLStorageModeManaged; + } +#endif + textureDescriptor.arrayLength = 1; + textureDescriptor.mipmapLevelCount = storedMipLevelCount; + + id texture = [device newTextureWithDescriptor:textureDescriptor]; + + ktxTexture *ktx1Texture = (ktxTexture *)ktx2Texture; + + ktx_uint32_t layer = 0, faceSlice = 0; + for (ktx_uint32_t level = 0; level < ktx2Texture->numLevels; ++level) { + ktx_size_t offset = 0; + result = ktxTexture_GetImageOffset(ktx1Texture, level, layer, faceSlice, &offset); + ktx_uint8_t *imageBytes = ktxTexture_GetData(ktx1Texture) + offset; + ktx_uint32_t bytesPerRow = ktxTexture_GetRowPitch(ktx1Texture, level); + ktx_size_t bytesPerImage = ktxTexture_GetImageSize(ktx1Texture, level); + size_t levelWidth = MAX(1, (baseWidth >> level)); + size_t levelHeight = MAX(1, (baseHeight >> level)); + [texture replaceRegion:MTLRegionMake2D(0, 0, levelWidth, levelHeight) + mipmapLevel:level + slice:faceSlice + withBytes:imageBytes + bytesPerRow:bytesPerRow + bytesPerImage:bytesPerImage]; + } + + ktxTexture_Destroy(ktx1Texture); + + if (genMipmaps) { + // TODO: + // id commandBuffer = [commandQueue commandBuffer]; + // id mipmapCommandEncoder = [commandBuffer blitCommandEncoder]; + // [mipmapCommandEncoder generateMipmapsForTexture:texture]; + // [mipmapCommandEncoder endEncoding]; + // [commandBuffer commit]; + } + + return texture; +} + +MTLPixelFormat GLTFMetalPixelFormatForVkFormat(int vkformat) { + switch (vkformat) { + case 2: /* VK_FORMAT_R4G4B4A4_UNORM_PACK16 */ return MTLPixelFormatABGR4Unorm; + case 4: /* VK_FORMAT_R5G6B5_UNORM_PACK16 */ return MTLPixelFormatB5G6R5Unorm; + case 6: /* VK_FORMAT_R5G5B5A1_UNORM_PACK16 */ return MTLPixelFormatA1BGR5Unorm; + case 8: /* VK_FORMAT_A1R5G5B5_UNORM_PACK16 */ return MTLPixelFormatBGR5A1Unorm; + case 9: /* VK_FORMAT_R8_UNORM */ return MTLPixelFormatR8Unorm; + case 10: /* VK_FORMAT_R8_SNORM */ return MTLPixelFormatR8Snorm; + case 13: /* VK_FORMAT_R8_UINT */ return MTLPixelFormatR8Uint; + case 14: /* VK_FORMAT_R8_SINT */ return MTLPixelFormatR8Sint; + case 15: /* VK_FORMAT_R8_SRGB */ return MTLPixelFormatR8Unorm_sRGB; + case 16: /* VK_FORMAT_R8G8_UNORM */ return MTLPixelFormatRG8Unorm; + case 17: /* VK_FORMAT_R8G8_SNORM */ return MTLPixelFormatRG8Snorm; + case 20: /* VK_FORMAT_R8G8_UINT */ return MTLPixelFormatRG8Uint; + case 21: /* VK_FORMAT_R8G8_SINT */ return MTLPixelFormatRG8Sint; + case 22: /* VK_FORMAT_R8G8_SRGB */ return MTLPixelFormatRG8Unorm_sRGB; + case 37: /* VK_FORMAT_R8G8B8A8_UNORM */ return MTLPixelFormatRGBA8Unorm; + case 38: /* VK_FORMAT_R8G8B8A8_SNORM */ return MTLPixelFormatRGBA8Snorm; + case 41: /* VK_FORMAT_R8G8B8A8_UINT */ return MTLPixelFormatRGBA8Uint; + case 42: /* VK_FORMAT_R8G8B8A8_SINT */ return MTLPixelFormatRGBA8Sint; + case 43: /* VK_FORMAT_R8G8B8A8_SRGB */ return MTLPixelFormatRGBA8Unorm_sRGB; + case 44: /* VK_FORMAT_B8G8R8A8_UNORM */ return MTLPixelFormatBGRA8Unorm; + case 50: /* VK_FORMAT_B8G8R8A8_SRGB */ return MTLPixelFormatBGRA8Unorm_sRGB; + case 58: /* VK_FORMAT_A2R10G10B10_UNORM_PACK32 */ return MTLPixelFormatBGR10A2Unorm; + case 64: /* VK_FORMAT_A2B10G10R10_UNORM_PACK32 */ return MTLPixelFormatRGB10A2Unorm; + case 68: /* VK_FORMAT_A2B10G10R10_UINT_PACK32 */ return MTLPixelFormatRGB10A2Uint; + case 70: /* VK_FORMAT_R16_UNORM */ return MTLPixelFormatR16Unorm; + case 71: /* VK_FORMAT_R16_SNORM */ return MTLPixelFormatR16Snorm; + case 74: /* VK_FORMAT_R16_UINT */ return MTLPixelFormatR16Uint; + case 75: /* VK_FORMAT_R16_SINT */ return MTLPixelFormatR16Sint; + case 76: /* VK_FORMAT_R16_SFLOAT */ return MTLPixelFormatR16Float; + case 77: /* VK_FORMAT_R16G16_UNORM */ return MTLPixelFormatRG16Unorm; + case 78: /* VK_FORMAT_R16G16_SNORM */ return MTLPixelFormatRG16Snorm; + case 81: /* VK_FORMAT_R16G16_UINT */ return MTLPixelFormatRG16Uint; + case 82: /* VK_FORMAT_R16G16_SINT */ return MTLPixelFormatRG16Sint; + case 83: /* VK_FORMAT_R16G16_SFLOAT */ return MTLPixelFormatRG16Float; + case 91: /* VK_FORMAT_R16G16B16A16_UNORM */ return MTLPixelFormatRGBA16Unorm; + case 92: /* VK_FORMAT_R16G16B16A16_SNORM */ return MTLPixelFormatRGBA16Snorm; + case 95: /* VK_FORMAT_R16G16B16A16_UINT */ return MTLPixelFormatRGBA16Uint; + case 96: /* VK_FORMAT_R16G16B16A16_SINT */ return MTLPixelFormatRGBA16Sint; + case 97: /* VK_FORMAT_R16G16B16A16_SFLOAT */ return MTLPixelFormatRGBA16Float; + case 98: /* VK_FORMAT_R32_UINT */ return MTLPixelFormatR32Uint; + case 99: /* VK_FORMAT_R32_SINT */ return MTLPixelFormatR32Sint; + case 100: /* VK_FORMAT_R32_SFLOAT */ return MTLPixelFormatR32Float; + case 101: /* VK_FORMAT_R32G32_UINT */ return MTLPixelFormatRG32Uint; + case 102: /* VK_FORMAT_R32G32_SINT */ return MTLPixelFormatRG32Sint; + case 103: /* VK_FORMAT_R32G32_SFLOAT */ return MTLPixelFormatRG32Float; + case 107: /* VK_FORMAT_R32G32B32A32_UINT */ return MTLPixelFormatRGBA32Uint; + case 108: /* VK_FORMAT_R32G32B32A32_SINT */ return MTLPixelFormatRGBA32Sint; + case 109: /* VK_FORMAT_R32G32B32A32_SFLOAT */ return MTLPixelFormatRGBA32Float; + case 122: /* VK_FORMAT_B10G11R11_UFLOAT_PACK32 */ return MTLPixelFormatRG11B10Float; + case 123: /* VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 */ return MTLPixelFormatRGB9E5Float; + case 126: /* VK_FORMAT_D32_SFLOAT */ return MTLPixelFormatDepth32Float; + case 127: /* VK_FORMAT_S8_UINT */ return MTLPixelFormatStencil8; + case 147: /* VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK */ return MTLPixelFormatETC2_RGB8; + case 148: /* VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK */ return MTLPixelFormatETC2_RGB8_sRGB; + case 149: /* VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK */ return MTLPixelFormatETC2_RGB8A1; + case 150: /* VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK */ return MTLPixelFormatETC2_RGB8A1_sRGB; + case 151: /* VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK */ return MTLPixelFormatEAC_RGBA8; + case 152: /* VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK */ return MTLPixelFormatEAC_RGBA8_sRGB; + case 153: /* VK_FORMAT_EAC_R11_UNORM_BLOCK */ return MTLPixelFormatEAC_R11Unorm; + case 154: /* VK_FORMAT_EAC_R11_SNORM_BLOCK */ return MTLPixelFormatEAC_R11Snorm; + case 155: /* VK_FORMAT_EAC_R11G11_UNORM_BLOCK */ return MTLPixelFormatEAC_RG11Unorm; + case 156: /* VK_FORMAT_EAC_R11G11_SNORM_BLOCK */ return MTLPixelFormatEAC_RG11Snorm; + case 157: /* VK_FORMAT_ASTC_4x4_UNORM_BLOCK */ return MTLPixelFormatASTC_4x4_LDR; + case 158: /* VK_FORMAT_ASTC_4x4_SRGB_BLOCK */ return MTLPixelFormatASTC_4x4_sRGB; + case 159: /* VK_FORMAT_ASTC_5x4_UNORM_BLOCK */ return MTLPixelFormatASTC_5x4_LDR; + case 160: /* VK_FORMAT_ASTC_5x4_SRGB_BLOCK */ return MTLPixelFormatASTC_5x4_sRGB; + case 161: /* VK_FORMAT_ASTC_5x5_UNORM_BLOCK */ return MTLPixelFormatASTC_5x5_LDR; + case 162: /* VK_FORMAT_ASTC_5x5_SRGB_BLOCK */ return MTLPixelFormatASTC_5x5_sRGB; + case 163: /* VK_FORMAT_ASTC_6x5_UNORM_BLOCK */ return MTLPixelFormatASTC_6x5_LDR; + case 164: /* VK_FORMAT_ASTC_6x5_SRGB_BLOCK */ return MTLPixelFormatASTC_6x5_sRGB; + case 165: /* VK_FORMAT_ASTC_6x6_UNORM_BLOCK */ return MTLPixelFormatASTC_6x6_LDR; + case 166: /* VK_FORMAT_ASTC_6x6_SRGB_BLOCK */ return MTLPixelFormatASTC_6x6_sRGB; + case 167: /* VK_FORMAT_ASTC_8x5_UNORM_BLOCK */ return MTLPixelFormatASTC_8x5_LDR; + case 168: /* VK_FORMAT_ASTC_8x5_SRGB_BLOCK */ return MTLPixelFormatASTC_8x5_sRGB; + case 169: /* VK_FORMAT_ASTC_8x6_UNORM_BLOCK */ return MTLPixelFormatASTC_8x6_LDR; + case 170: /* VK_FORMAT_ASTC_8x6_SRGB_BLOCK */ return MTLPixelFormatASTC_8x6_sRGB; + case 171: /* VK_FORMAT_ASTC_8x8_UNORM_BLOCK */ return MTLPixelFormatASTC_8x8_LDR; + case 172: /* VK_FORMAT_ASTC_8x8_SRGB_BLOCK */ return MTLPixelFormatASTC_8x8_sRGB; + case 173: /* VK_FORMAT_ASTC_10x5_UNORM_BLOCK */ return MTLPixelFormatASTC_10x5_LDR; + case 174: /* VK_FORMAT_ASTC_10x5_SRGB_BLOCK */ return MTLPixelFormatASTC_10x5_sRGB; + case 175: /* VK_FORMAT_ASTC_10x6_UNORM_BLOCK */ return MTLPixelFormatASTC_10x6_LDR; + case 176: /* VK_FORMAT_ASTC_10x6_SRGB_BLOCK */ return MTLPixelFormatASTC_10x6_sRGB; + case 177: /* VK_FORMAT_ASTC_10x8_UNORM_BLOCK */ return MTLPixelFormatASTC_10x8_LDR; + case 178: /* VK_FORMAT_ASTC_10x8_SRGB_BLOCK */ return MTLPixelFormatASTC_10x8_sRGB; + case 179: /* VK_FORMAT_ASTC_10x10_UNORM_BLOCK */ return MTLPixelFormatASTC_10x10_LDR; + case 180: /* VK_FORMAT_ASTC_10x10_SRGB_BLOCK */ return MTLPixelFormatASTC_10x10_sRGB; + case 181: /* VK_FORMAT_ASTC_12x10_UNORM_BLOCK */ return MTLPixelFormatASTC_12x10_LDR; + case 182: /* VK_FORMAT_ASTC_12x10_SRGB_BLOCK */ return MTLPixelFormatASTC_12x10_sRGB; + case 183: /* VK_FORMAT_ASTC_12x12_UNORM_BLOCK */ return MTLPixelFormatASTC_12x12_LDR; + case 184: /* VK_FORMAT_ASTC_12x12_SRGB_BLOCK */ return MTLPixelFormatASTC_12x12_sRGB; + case 1000156000: /* VK_FORMAT_G8B8G8R8_422_UNORM */ return MTLPixelFormatGBGR422; + case 1000156001: /* VK_FORMAT_B8G8R8G8_422_UNORM */ return MTLPixelFormatBGRG422; + case 1000054000: /* VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG */ return MTLPixelFormatPVRTC_RGBA_2BPP; + case 1000054001: /* VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG */ return MTLPixelFormatPVRTC_RGBA_4BPP; + case 1000054004: /* VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG */ return MTLPixelFormatPVRTC_RGBA_2BPP_sRGB; + case 1000054005: /* VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG */ return MTLPixelFormatPVRTC_RGBA_4BPP_sRGB; + default: + break; + } + if (@available(macos 10.11, iOS 16.4, *)) { + switch (vkformat) { + case 133: /* VK_FORMAT_BC1_RGBA_UNORM_BLOCK */ return MTLPixelFormatBC1_RGBA; + case 134: /* VK_FORMAT_BC1_RGBA_SRGB_BLOCK */ return MTLPixelFormatBC1_RGBA_sRGB; + case 135: /* VK_FORMAT_BC2_UNORM_BLOCK */ return MTLPixelFormatBC2_RGBA; + case 136: /* VK_FORMAT_BC2_SRGB_BLOCK */ return MTLPixelFormatBC2_RGBA_sRGB; + case 137: /* VK_FORMAT_BC3_UNORM_BLOCK */ return MTLPixelFormatBC3_RGBA; + case 138: /* VK_FORMAT_BC3_SRGB_BLOCK */ return MTLPixelFormatBC3_RGBA_sRGB; + case 139: /* VK_FORMAT_BC4_UNORM_BLOCK */ return MTLPixelFormatBC4_RUnorm; + case 140: /* VK_FORMAT_BC4_SNORM_BLOCK */ return MTLPixelFormatBC4_RSnorm; + case 141: /* VK_FORMAT_BC5_UNORM_BLOCK */ return MTLPixelFormatBC5_RGUnorm; + case 142: /* VK_FORMAT_BC5_SNORM_BLOCK */ return MTLPixelFormatBC5_RGSnorm; + case 143: /* VK_FORMAT_BC6H_UFLOAT_BLOCK */ return MTLPixelFormatBC6H_RGBUfloat; + case 144: /* VK_FORMAT_BC6H_SFLOAT_BLOCK */ return MTLPixelFormatBC6H_RGBFloat; + case 145: /* VK_FORMAT_BC7_UNORM_BLOCK */ return MTLPixelFormatBC7_RGBAUnorm; + case 146: /* VK_FORMAT_BC7_SRGB_BLOCK */ return MTLPixelFormatBC7_RGBAUnorm_sRGB; + default: + break; + } + } + return MTLPixelFormatInvalid; +} diff --git a/KTXLoader/KTXLoader.docc/KTXLoader.md b/KTXLoader/KTXLoader.docc/KTXLoader.md new file mode 100755 index 00000000..bae3fa1e --- /dev/null +++ b/KTXLoader/KTXLoader.docc/KTXLoader.md @@ -0,0 +1,13 @@ +# ``KTXLoader`` + +Summary + +## Overview + +Text + +## Topics + +### Group + +- ``Symbol`` \ No newline at end of file diff --git a/KTXLoader/KTXLoader.h b/KTXLoader/KTXLoader.h new file mode 100644 index 00000000..978ef280 --- /dev/null +++ b/KTXLoader/KTXLoader.h @@ -0,0 +1,32 @@ +// +// KTXLoader.h +// KTXLoader +// +// Created by Jesse Armand on 30/11/23. +// Copyright © 2023 DarkHorse. All rights reserved. +// + +#import +#import + +#import + +//! Project version number for KTXLoader. +FOUNDATION_EXPORT double KTXLoaderVersionNumber; + +//! Project version string for KTXLoader. +FOUNDATION_EXPORT const unsigned char KTXLoaderVersionString[]; + +NS_ASSUME_NONNULL_BEGIN + +@interface KTXLoader : NSObject + ++ (nullable id)createTextureFromData:(nonnull NSData *)data device:(id)device; + +- (nullable instancetype)initWithData:(NSData *)data device:(id)device error:(NSError **)error; + +- (id)loadTextureUsingDevice:(id)device; + +@end + +NS_ASSUME_NONNULL_END diff --git a/KTXLoader/KTXLoader.mm b/KTXLoader/KTXLoader.mm new file mode 100644 index 00000000..7272fbd4 --- /dev/null +++ b/KTXLoader/KTXLoader.mm @@ -0,0 +1,131 @@ +// +// KTXLoader.m +// GLTFSceneKit_iOS +// +// Created by Jesse Armand on 29/11/23. +// Copyright © 2023 DarkHorse. All rights reserved. +// + +#import "KTXLoader.h" + +#import + +@implementation KTXLoader { + ktxTexture *texture; + MTLPixelFormat pixelFormat; +} + ++ (nullable id)createTextureFromData:(nonnull NSData *)data device:(id)device { + return GLTFCreateTextureFromKTX2Data(data, device); +} + +- (nullable instancetype)initWithData:(nonnull NSData *)data device:(id)device error:(NSError *__autoreleasing _Nullable * _Nullable)error { + self = [super init]; + if (self == nil) { + return nil; + } + + ktx_size_t size = [data length]; + const ktx_uint8_t *bytes = (const ktx_uint8_t *)[data bytes]; + uint32_t flags = KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT | + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT | + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT; + + ktxTexture2 *texture2 = NULL; + ktxResult result = ktxTexture2_CreateFromMemory(bytes, size, flags, &texture2); + if (result != KTX_SUCCESS) { + *error = [NSError errorWithDomain:@"KTXLoader" code:result userInfo:nil]; + } + + if (ktxTexture2_NeedsTranscoding(texture2)) { + BOOL deviceHasASTC = GLTFMetalDeviceSupportsASTC(device); + BOOL deviceHasETC2 = GLTFMetalDeviceSupportsETC(device); + BOOL deviceHasBC = GLTFMetalDeviceSupportsBC(device); + + khr_df_model_e colorModel = ktxTexture2_GetColorModel_e(texture2); + + ktx_transcode_fmt_e tf = KTX_TTF_NOSELECTION; + if (colorModel == KHR_DF_MODEL_UASTC && deviceHasASTC) { + tf = KTX_TTF_ASTC_4x4_RGBA; + } else if (colorModel == KHR_DF_MODEL_ETC1S && deviceHasETC2) { + tf = KTX_TTF_ETC; + } else if (deviceHasASTC) { + tf = KTX_TTF_ASTC_4x4_RGBA; + } else if (deviceHasETC2) { + tf = KTX_TTF_ETC2_RGBA; + } else if (deviceHasBC) { + tf = KTX_TTF_BC3_RGBA; + } + result = ktxTexture2_TranscodeBasis(texture2, tf, 0); + + if (result != KTX_SUCCESS) { + *error = [NSError errorWithDomain:@"KTXLoader" code:result userInfo:nil]; + } + + texture = (ktxTexture *)texture2; + } + + pixelFormat = GLTFMetalPixelFormatForVkFormat(texture2->vkFormat); + + return self; +} + + +- (id)loadTextureUsingDevice:(id)device { + BOOL generateMipmaps = texture->generateMipmaps; + NSUInteger levelCount = texture->numLevels; + NSUInteger baseWidth = texture->baseWidth; + NSUInteger baseHeight = texture->baseHeight; + NSUInteger baseDepth = texture->baseDepth; + NSUInteger maxMipLevelCount = floor(log2(MAX(baseWidth, baseHeight))) + 1; + NSUInteger storedMipLevelCount = generateMipmaps ? maxMipLevelCount : levelCount; + NSUInteger textureHeight = (texture->numDimensions > 1) ? baseHeight : 1; + NSUInteger textureDepth = (texture->numDimensions > 2) ? baseDepth : 1; + MTLTextureDescriptor *descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixelFormat + width:baseWidth + height:textureHeight + mipmapped:generateMipmaps]; + descriptor.depth = textureDepth; + descriptor.usage = MTLTextureUsageShaderRead; + descriptor.storageMode = MTLStorageModeShared; +#if TARGET_OS_OSX + if (!device.hasUnifiedMemory) { + descriptor.storageMode = MTLStorageModeManaged; + } +#endif + descriptor.arrayLength = 1; + descriptor.mipmapLevelCount = storedMipLevelCount; + + id metalTexture = [device newTextureWithDescriptor:descriptor]; + + KTX_error_code result; + ktx_uint32_t layer = 0, faceSlice = 0; + for (ktx_uint32_t level = 0; level < texture->numLevels; ++level) { + ktx_size_t offset = 0; + result = ktxTexture_GetImageOffset(texture, level, layer, faceSlice, &offset); + ktx_uint8_t *imageBytes = ktxTexture_GetData(texture) + offset; + ktx_uint32_t bytesPerRow = ktxTexture_GetRowPitch(texture, level); + ktx_size_t bytesPerImage = ktxTexture_GetImageSize(texture, level); + size_t levelWidth = MAX(1, (baseWidth >> level)); + size_t levelHeight = MAX(1, (baseHeight >> level)); + [metalTexture replaceRegion:MTLRegionMake2D(0, 0, levelWidth, levelHeight) + mipmapLevel:level + slice:faceSlice + withBytes:imageBytes + bytesPerRow:bytesPerRow + bytesPerImage:bytesPerImage]; + } + + ktxTexture_Destroy(texture); + + if (metalTexture == nil) + { + NSLog(@"Failed to create metal texture from ktxTexture"); + + return nil; + } + return metalTexture; +} + +@end + diff --git a/KTXLoader/libktx/LICENSE.md b/KTXLoader/libktx/LICENSE.md new file mode 100644 index 00000000..7b6d05fe --- /dev/null +++ b/KTXLoader/libktx/LICENSE.md @@ -0,0 +1,36 @@ +LICENSE file for the KhronosGroup/KTX-Software project {#license} +====================================================== + + + +Files unique to this repository generally fall under the Apache 2.0 license +with copyright holders including Mark Callow, the KTX-Software author; The +Khronos Group Inc., which has supported KTX development; and other +contributors to the KTX project. + +Because KTX-Software incorporates material and contributions from many other +projects, which often have their own licenses, there are many other licenses +in use in this repository. While there are many licenses in this repository, +with rare exceptions all are open source licenses that we believe to be +mutually compatible. + +The complete text of each of the licenses used in this repository is found +in LICENSES/*.txt . Additionally, we have updated the repository to pass the +REUSE compliance checker tool (see https://reuse.software/). REUSE verifies +that every file in a git repository either incorporates a license, or that +the license is present in auxiliary files such as .reuse/dep5 . To obtain a +bill of materials for the repository identifying the license for each file, +install the REUSE tool and run + + reuse spdx + +inside the repository. + +## Special Cases + +The file lib/etcdec.cxx is not open source. It is made available under the +terms of an Ericsson license, found in the file itself. diff --git a/KTXLoader/libktx/VERSION b/KTXLoader/libktx/VERSION new file mode 100644 index 00000000..85c71c86 --- /dev/null +++ b/KTXLoader/libktx/VERSION @@ -0,0 +1 @@ +v4.2.1 diff --git a/KTXLoader/libktx/ktx.xcframework/Info.plist b/KTXLoader/libktx/ktx.xcframework/Info.plist new file mode 100644 index 00000000..c9e9640f --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/Info.plist @@ -0,0 +1,135 @@ + + + + + AvailableLibraries + + + BinaryPath + libktx.a + HeadersPath + Headers + LibraryIdentifier + xros-arm64_x86_64-simulator + LibraryPath + libktx.a + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + xros + SupportedPlatformVariant + simulator + + + BinaryPath + libktx.a + HeadersPath + Headers + LibraryIdentifier + ios-arm64 + LibraryPath + libktx.a + SupportedArchitectures + + arm64 + + SupportedPlatform + ios + + + BinaryPath + libktx.a + HeadersPath + Headers + LibraryIdentifier + tvos-arm64_x86_64-simulator + LibraryPath + libktx.a + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + tvos + SupportedPlatformVariant + simulator + + + BinaryPath + libktx.a + HeadersPath + Headers + LibraryIdentifier + macos-arm64_x86_64 + LibraryPath + libktx.a + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + macos + + + BinaryPath + libktx.a + HeadersPath + Headers + LibraryIdentifier + xros-arm64 + LibraryPath + libktx.a + SupportedArchitectures + + arm64 + + SupportedPlatform + xros + + + BinaryPath + libktx.a + HeadersPath + Headers + LibraryIdentifier + tvos-arm64 + LibraryPath + libktx.a + SupportedArchitectures + + arm64 + + SupportedPlatform + tvos + + + BinaryPath + libktx.a + HeadersPath + Headers + LibraryIdentifier + ios-arm64_x86_64-simulator + LibraryPath + libktx.a + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + ios + SupportedPlatformVariant + simulator + + + CFBundlePackageType + XFWK + XCFrameworkFormatVersion + 1.0 + + diff --git a/KTXLoader/libktx/ktx.xcframework/ios-arm64/Headers/KHR/khr_df.h b/KTXLoader/libktx/ktx.xcframework/ios-arm64/Headers/KHR/khr_df.h new file mode 100644 index 00000000..c0d03aa7 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/ios-arm64/Headers/KHR/khr_df.h @@ -0,0 +1,630 @@ +/* The Khronos Data Format Specification (version 1.3) */ +/* +** Copyright 2015-2020 The Khronos Group Inc. +** SPDX-License-Identifier: Apache-2.0 +*/ + +/* This header defines a structure that can describe the layout of image + formats in memory. This means that the data format is transparent to + the application, and the expectation is that this should be used when + the layout is defined external to the API. Many Khronos APIs deliberately + keep the internal layout of images opaque, to allow proprietary layouts + and optimisations. This structure is not appropriate for describing + opaque layouts. */ + +/* We stick to standard C89 constructs for simplicity and portability. */ + +#ifndef _KHR_DATA_FORMAT_H_ +#define _KHR_DATA_FORMAT_H_ + +/** @file khr_df.h + + @brief Data Format enums and macros. +*/ + +/* Accessors */ +typedef enum _khr_word_e { + KHR_DF_WORD_VENDORID = 0U, + KHR_DF_WORD_DESCRIPTORTYPE = 0U, + KHR_DF_WORD_VERSIONNUMBER = 1U, + KHR_DF_WORD_DESCRIPTORBLOCKSIZE = 1U, + KHR_DF_WORD_MODEL = 2U, + KHR_DF_WORD_PRIMARIES = 2U, + KHR_DF_WORD_TRANSFER = 2U, + KHR_DF_WORD_FLAGS = 2U, + KHR_DF_WORD_TEXELBLOCKDIMENSION0 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION1 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION2 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION3 = 3U, + KHR_DF_WORD_BYTESPLANE0 = 4U, + KHR_DF_WORD_BYTESPLANE1 = 4U, + KHR_DF_WORD_BYTESPLANE2 = 4U, + KHR_DF_WORD_BYTESPLANE3 = 4U, + KHR_DF_WORD_BYTESPLANE4 = 5U, + KHR_DF_WORD_BYTESPLANE5 = 5U, + KHR_DF_WORD_BYTESPLANE6 = 5U, + KHR_DF_WORD_BYTESPLANE7 = 5U, + KHR_DF_WORD_SAMPLESTART = 6U, + KHR_DF_WORD_SAMPLEWORDS = 4U +} khr_df_word_e; + +typedef enum _khr_df_shift_e { + KHR_DF_SHIFT_VENDORID = 0U, + KHR_DF_SHIFT_DESCRIPTORTYPE = 17U, + KHR_DF_SHIFT_VERSIONNUMBER = 0U, + KHR_DF_SHIFT_DESCRIPTORBLOCKSIZE = 16U, + KHR_DF_SHIFT_MODEL = 0U, + KHR_DF_SHIFT_PRIMARIES = 8U, + KHR_DF_SHIFT_TRANSFER = 16U, + KHR_DF_SHIFT_FLAGS = 24U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION0 = 0U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION1 = 8U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION2 = 16U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION3 = 24U, + KHR_DF_SHIFT_BYTESPLANE0 = 0U, + KHR_DF_SHIFT_BYTESPLANE1 = 8U, + KHR_DF_SHIFT_BYTESPLANE2 = 16U, + KHR_DF_SHIFT_BYTESPLANE3 = 24U, + KHR_DF_SHIFT_BYTESPLANE4 = 0U, + KHR_DF_SHIFT_BYTESPLANE5 = 8U, + KHR_DF_SHIFT_BYTESPLANE6 = 16U, + KHR_DF_SHIFT_BYTESPLANE7 = 24U +} khr_df_shift_e; + +typedef enum _khr_df_mask_e { + KHR_DF_MASK_VENDORID = 0x1FFFFU, + KHR_DF_MASK_DESCRIPTORTYPE = 0x7FFFU, + KHR_DF_MASK_VERSIONNUMBER = 0xFFFFU, + KHR_DF_MASK_DESCRIPTORBLOCKSIZE = 0xFFFFU, + KHR_DF_MASK_MODEL = 0xFFU, + KHR_DF_MASK_PRIMARIES = 0xFFU, + KHR_DF_MASK_TRANSFER = 0xFFU, + KHR_DF_MASK_FLAGS = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION0 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION1 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION2 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE0 = 0xFFU, + KHR_DF_MASK_BYTESPLANE1 = 0xFFU, + KHR_DF_MASK_BYTESPLANE2 = 0xFFU, + KHR_DF_MASK_BYTESPLANE3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE4 = 0xFFU, + KHR_DF_MASK_BYTESPLANE5 = 0xFFU, + KHR_DF_MASK_BYTESPLANE6 = 0xFFU, + KHR_DF_MASK_BYTESPLANE7 = 0xFFU +} khr_df_mask_e; + +/* Helper macro: + Extract field X from basic descriptor block BDB */ +#define KHR_DFDVAL(BDB, X) \ + (((BDB)[KHR_DF_WORD_ ## X] >> (KHR_DF_SHIFT_ ## X)) \ + & (KHR_DF_MASK_ ## X)) + +/* Helper macro: + Set field X of basic descriptor block BDB */ +#define KHR_DFDSETVAL(BDB, X, val) \ + ((BDB)[KHR_DF_WORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_ ## X] & \ + ~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \ + (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X))) + +/* Offsets relative to the start of a sample */ +typedef enum _khr_df_sampleword_e { + KHR_DF_SAMPLEWORD_BITOFFSET = 0U, + KHR_DF_SAMPLEWORD_BITLENGTH = 0U, + KHR_DF_SAMPLEWORD_CHANNELID = 0U, + KHR_DF_SAMPLEWORD_QUALIFIERS = 0U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION0 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION1 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION2 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION3 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL = 1U, + KHR_DF_SAMPLEWORD_SAMPLELOWER = 2U, + KHR_DF_SAMPLEWORD_SAMPLEUPPER = 3U +} khr_df_sampleword_e; + +typedef enum _khr_df_sampleshift_e { + KHR_DF_SAMPLESHIFT_BITOFFSET = 0U, + KHR_DF_SAMPLESHIFT_BITLENGTH = 16U, + KHR_DF_SAMPLESHIFT_CHANNELID = 24U, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLESHIFT_QUALIFIERS = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION0 = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION1 = 8U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION2 = 16U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION3 = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION_ALL = 0U, + KHR_DF_SAMPLESHIFT_SAMPLELOWER = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEUPPER = 0U +} khr_df_sampleshift_e; + +typedef enum _khr_df_samplemask_e { + KHR_DF_SAMPLEMASK_BITOFFSET = 0xFFFFU, + KHR_DF_SAMPLEMASK_BITLENGTH = 0xFF, + KHR_DF_SAMPLEMASK_CHANNELID = 0xF, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLEMASK_QUALIFIERS = 0xF0, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION0 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION1 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION2 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION3 = 0xFF, + /* ISO C restricts enum values to range of int hence the + cast. We do it verbosely instead of using -1 to ensure + it is a 32-bit value even if int is 64 bits. */ + KHR_DF_SAMPLEMASK_SAMPLEPOSITION_ALL = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLELOWER = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLEUPPER = (int) 0xFFFFFFFFU +} khr_df_samplemask_e; + +/* Helper macro: + Extract field X of sample S from basic descriptor block BDB */ +#define KHR_DFDSVAL(BDB, S, X) \ + (((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] >> (KHR_DF_SAMPLESHIFT_ ## X)) \ + & (KHR_DF_SAMPLEMASK_ ## X)) + +/* Helper macro: + Set field X of sample S of basic descriptor block BDB */ +#define KHR_DFDSETSVAL(BDB, S, X, val) \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] & \ + ~((uint32_t)(KHR_DF_SAMPLEMASK_ ## X) << (KHR_DF_SAMPLESHIFT_ ## X))) | \ + (((val) & (uint32_t)(KHR_DF_SAMPLEMASK_ ## X)) << (KHR_DF_SAMPLESHIFT_ ## X))) + +/* Helper macro: + Number of samples in basic descriptor block BDB */ +#define KHR_DFDSAMPLECOUNT(BDB) \ + (((KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) >> 2) - \ + KHR_DF_WORD_SAMPLESTART) \ + / KHR_DF_WORD_SAMPLEWORDS) + +/* Helper macro: + Size in words of basic descriptor block for S samples */ +#define KHR_DFDSIZEWORDS(S) \ + (KHR_DF_WORD_SAMPLESTART + \ + (S) * KHR_DF_WORD_SAMPLEWORDS) + +/* Vendor ids */ +typedef enum _khr_df_vendorid_e { + /* Standard Khronos descriptor */ + KHR_DF_VENDORID_KHRONOS = 0U, + KHR_DF_VENDORID_MAX = 0x1FFFFU +} khr_df_vendorid_e; + +/* Descriptor types */ +typedef enum _khr_df_khr_descriptortype_e { + /* Default Khronos basic descriptor block */ + KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0U, + /* Extension descriptor block for additional planes */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_PLANES = 0x6001U, + /* Extension descriptor block for additional dimensions */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_DIMENSIONS = 0x6002U, + /* Bit indicates modifying requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_WRITE_BIT = 0x2000U, + /* Bit indicates processing requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_DECODE_BIT = 0x4000U, + KHR_DF_KHR_DESCRIPTORTYPE_MAX = 0x7FFFU +} khr_df_khr_descriptortype_e; + +/* Descriptor block version */ +typedef enum _khr_df_versionnumber_e { + /* Standard Khronos descriptor */ + KHR_DF_VERSIONNUMBER_1_0 = 0U, /* Version 1.0 of the specification */ + KHR_DF_VERSIONNUMBER_1_1 = 0U, /* Version 1.1 did not bump the version number */ + KHR_DF_VERSIONNUMBER_1_2 = 1U, /* Version 1.2 increased the version number */ + KHR_DF_VERSIONNUMBER_1_3 = 2U, /* Version 1.3 increased the version number */ + KHR_DF_VERSIONNUMBER_LATEST = KHR_DF_VERSIONNUMBER_1_3, + KHR_DF_VERSIONNUMBER_MAX = 0xFFFFU +} khr_df_versionnumber_e; + +/** @~English + @brief Model in which the color coordinate space is defined. + There is no requirement that a color format use all the + channel types that are defined in the color model. */ +typedef enum _khr_df_model_e { + /** No interpretation of color channels defined */ + KHR_DF_MODEL_UNSPECIFIED = 0U, + /** Color primaries (red, green, blue) + alpha, depth and stencil */ + KHR_DF_MODEL_RGBSDA = 1U, + /** Color differences (Y', Cb, Cr) + alpha, depth and stencil */ + KHR_DF_MODEL_YUVSDA = 2U, + /** Color differences (Y', I, Q) + alpha, depth and stencil */ + KHR_DF_MODEL_YIQSDA = 3U, + /** Perceptual color (CIE L*a*b*) + alpha, depth and stencil */ + KHR_DF_MODEL_LABSDA = 4U, + /** Subtractive colors (cyan, magenta, yellow, black) + alpha */ + KHR_DF_MODEL_CMYKA = 5U, + /** Non-color coordinate data (X, Y, Z, W) */ + KHR_DF_MODEL_XYZW = 6U, + /** Hue, saturation, value, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSVA_ANG = 7U, + /** Hue, saturation, lightness, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSLA_ANG = 8U, + /** Hue, saturation, value, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSVA_HEX = 9U, + /** Hue, saturation, lightness, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSLA_HEX = 10U, + /** Lightweight approximate color difference (luma, orange, green) */ + KHR_DF_MODEL_YCGCOA = 11U, + /** ITU BT.2020 constant luminance YcCbcCrc */ + KHR_DF_MODEL_YCCBCCRC = 12U, + /** ITU BT.2100 constant intensity ICtCp */ + KHR_DF_MODEL_ICTCP = 13U, + /** CIE 1931 XYZ color coordinates (X, Y, Z) */ + KHR_DF_MODEL_CIEXYZ = 14U, + /** CIE 1931 xyY color coordinates (X, Y, Y) */ + KHR_DF_MODEL_CIEXYY = 15U, + + /* Compressed formats start at 128. */ + /* These compressed formats should generally have a single sample, + sited at the 0,0 position of the texel block. Where multiple + channels are used to distinguish formats, these should be cosited. */ + /* Direct3D (and S3) compressed formats */ + /* Note that premultiplied status is recorded separately */ + /** DXT1 "channels" are RGB (0), Alpha (1) + DXT1/BC1 with one channel is opaque + DXT1/BC1 with a cosited alpha sample is transparent */ + KHR_DF_MODEL_DXT1A = 128U, + KHR_DF_MODEL_BC1A = 128U, + /** DXT2/DXT3/BC2, with explicit 4-bit alpha */ + KHR_DF_MODEL_DXT2 = 129U, + KHR_DF_MODEL_DXT3 = 129U, + KHR_DF_MODEL_BC2 = 129U, + /** DXT4/DXT5/BC3, with interpolated alpha */ + KHR_DF_MODEL_DXT4 = 130U, + KHR_DF_MODEL_DXT5 = 130U, + KHR_DF_MODEL_BC3 = 130U, + /** BC4 - single channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC4 = 131U, + /** BC5 - two channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC5 = 132U, + /** BC6H - DX11 format for 16-bit float channels */ + KHR_DF_MODEL_BC6H = 133U, + /** BC7 - DX11 format */ + KHR_DF_MODEL_BC7 = 134U, + /* Gap left for future desktop expansion */ + + /* Mobile compressed formats follow */ + /** A format of ETC1 indicates that the format shall be decodable + by an ETC1-compliant decoder and not rely on ETC2 features */ + KHR_DF_MODEL_ETC1 = 160U, + /** A format of ETC2 is permitted to use ETC2 encodings on top of + the baseline ETC1 specification. + The ETC2 format has channels "red", "green", "RGB" and "alpha", + which should be cosited samples. + Punch-through alpha can be distinguished from full alpha by + the plane size in bytes required for the texel block */ + KHR_DF_MODEL_ETC2 = 161U, + /** Adaptive Scalable Texture Compression */ + /** ASTC HDR vs LDR is determined by the float flag in the channel */ + /** ASTC block size can be distinguished by texel block size */ + KHR_DF_MODEL_ASTC = 162U, + /** ETC1S is a simplified subset of ETC1 */ + KHR_DF_MODEL_ETC1S = 163U, + /** PowerVR Texture Compression v1 */ + KHR_DF_MODEL_PVRTC = 164U, + /** PowerVR Texture Compression v2 */ + KHR_DF_MODEL_PVRTC2 = 165U, + /** UASTC is a transcodable subset of ASTC + with additions to support the transcoding. */ + KHR_DF_MODEL_UASTC = 166U, + /* Proprietary formats (ATITC, etc.) should follow */ + KHR_DF_MODEL_MAX = 0xFFU +} khr_df_model_e; + +/* Definition of channel names for each color model */ +typedef enum _khr_df_model_channels_e { + /* Unspecified format with nominal channel numbering */ + KHR_DF_CHANNEL_UNSPECIFIED_0 = 0U, + KHR_DF_CHANNEL_UNSPECIFIED_1 = 1U, + KHR_DF_CHANNEL_UNSPECIFIED_2 = 2U, + KHR_DF_CHANNEL_UNSPECIFIED_3 = 3U, + KHR_DF_CHANNEL_UNSPECIFIED_4 = 4U, + KHR_DF_CHANNEL_UNSPECIFIED_5 = 5U, + KHR_DF_CHANNEL_UNSPECIFIED_6 = 6U, + KHR_DF_CHANNEL_UNSPECIFIED_7 = 7U, + KHR_DF_CHANNEL_UNSPECIFIED_8 = 8U, + KHR_DF_CHANNEL_UNSPECIFIED_9 = 9U, + KHR_DF_CHANNEL_UNSPECIFIED_10 = 10U, + KHR_DF_CHANNEL_UNSPECIFIED_11 = 11U, + KHR_DF_CHANNEL_UNSPECIFIED_12 = 12U, + KHR_DF_CHANNEL_UNSPECIFIED_13 = 13U, + KHR_DF_CHANNEL_UNSPECIFIED_14 = 14U, + KHR_DF_CHANNEL_UNSPECIFIED_15 = 15U, + /* MODEL_RGBSDA - red, green, blue, stencil, depth, alpha */ + KHR_DF_CHANNEL_RGBSDA_RED = 0U, + KHR_DF_CHANNEL_RGBSDA_R = 0U, + KHR_DF_CHANNEL_RGBSDA_GREEN = 1U, + KHR_DF_CHANNEL_RGBSDA_G = 1U, + KHR_DF_CHANNEL_RGBSDA_BLUE = 2U, + KHR_DF_CHANNEL_RGBSDA_B = 2U, + KHR_DF_CHANNEL_RGBSDA_STENCIL = 13U, + KHR_DF_CHANNEL_RGBSDA_S = 13U, + KHR_DF_CHANNEL_RGBSDA_DEPTH = 14U, + KHR_DF_CHANNEL_RGBSDA_D = 14U, + KHR_DF_CHANNEL_RGBSDA_ALPHA = 15U, + KHR_DF_CHANNEL_RGBSDA_A = 15U, + /* MODEL_YUVSDA - luma, Cb, Cr, stencil, depth, alpha */ + KHR_DF_CHANNEL_YUVSDA_Y = 0U, + KHR_DF_CHANNEL_YUVSDA_CB = 1U, + KHR_DF_CHANNEL_YUVSDA_U = 1U, + KHR_DF_CHANNEL_YUVSDA_CR = 2U, + KHR_DF_CHANNEL_YUVSDA_V = 2U, + KHR_DF_CHANNEL_YUVSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YUVSDA_S = 13U, + KHR_DF_CHANNEL_YUVSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YUVSDA_D = 14U, + KHR_DF_CHANNEL_YUVSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YUVSDA_A = 15U, + /* MODEL_YIQSDA - luma, in-phase, quadrature, stencil, depth, alpha */ + KHR_DF_CHANNEL_YIQSDA_Y = 0U, + KHR_DF_CHANNEL_YIQSDA_I = 1U, + KHR_DF_CHANNEL_YIQSDA_Q = 2U, + KHR_DF_CHANNEL_YIQSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YIQSDA_S = 13U, + KHR_DF_CHANNEL_YIQSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YIQSDA_D = 14U, + KHR_DF_CHANNEL_YIQSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YIQSDA_A = 15U, + /* MODEL_LABSDA - CIELAB/L*a*b* luma, red-green, blue-yellow, stencil, depth, alpha */ + KHR_DF_CHANNEL_LABSDA_L = 0U, + KHR_DF_CHANNEL_LABSDA_A = 1U, + KHR_DF_CHANNEL_LABSDA_B = 2U, + KHR_DF_CHANNEL_LABSDA_STENCIL = 13U, + KHR_DF_CHANNEL_LABSDA_S = 13U, + KHR_DF_CHANNEL_LABSDA_DEPTH = 14U, + KHR_DF_CHANNEL_LABSDA_D = 14U, + KHR_DF_CHANNEL_LABSDA_ALPHA = 15U, + /* NOTE: KHR_DF_CHANNEL_LABSDA_A is not a synonym for alpha! */ + /* MODEL_CMYKA - cyan, magenta, yellow, key/blacK, alpha */ + KHR_DF_CHANNEL_CMYKSDA_CYAN = 0U, + KHR_DF_CHANNEL_CMYKSDA_C = 0U, + KHR_DF_CHANNEL_CMYKSDA_MAGENTA = 1U, + KHR_DF_CHANNEL_CMYKSDA_M = 1U, + KHR_DF_CHANNEL_CMYKSDA_YELLOW = 2U, + KHR_DF_CHANNEL_CMYKSDA_Y = 2U, + KHR_DF_CHANNEL_CMYKSDA_KEY = 3U, + KHR_DF_CHANNEL_CMYKSDA_BLACK = 3U, + KHR_DF_CHANNEL_CMYKSDA_K = 3U, + KHR_DF_CHANNEL_CMYKSDA_ALPHA = 15U, + KHR_DF_CHANNEL_CMYKSDA_A = 15U, + /* MODEL_XYZW - coordinates x, y, z, w */ + KHR_DF_CHANNEL_XYZW_X = 0U, + KHR_DF_CHANNEL_XYZW_Y = 1U, + KHR_DF_CHANNEL_XYZW_Z = 2U, + KHR_DF_CHANNEL_XYZW_W = 3U, + /* MODEL_HSVA_ANG - value (luma), saturation, hue, alpha, angular projection, conical space */ + KHR_DF_CHANNEL_HSVA_ANG_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_ANG_V = 0U, + KHR_DF_CHANNEL_HSVA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_ANG_S = 1U, + KHR_DF_CHANNEL_HSVA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSVA_ANG_H = 2U, + KHR_DF_CHANNEL_HSVA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_ANG_A = 15U, + /* MODEL_HSLA_ANG - lightness (luma), saturation, hue, alpha, angular projection, double conical space */ + KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_ANG_L = 0U, + KHR_DF_CHANNEL_HSLA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_ANG_S = 1U, + KHR_DF_CHANNEL_HSLA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSLA_ANG_H = 2U, + KHR_DF_CHANNEL_HSLA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_ANG_A = 15U, + /* MODEL_HSVA_HEX - value (luma), saturation, hue, alpha, hexagonal projection, conical space */ + KHR_DF_CHANNEL_HSVA_HEX_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_HEX_V = 0U, + KHR_DF_CHANNEL_HSVA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_HEX_S = 1U, + KHR_DF_CHANNEL_HSVA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSVA_HEX_H = 2U, + KHR_DF_CHANNEL_HSVA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_HEX_A = 15U, + /* MODEL_HSLA_HEX - lightness (luma), saturation, hue, alpha, hexagonal projection, double conical space */ + KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_HEX_L = 0U, + KHR_DF_CHANNEL_HSLA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_HEX_S = 1U, + KHR_DF_CHANNEL_HSLA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSLA_HEX_H = 2U, + KHR_DF_CHANNEL_HSLA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_HEX_A = 15U, + /* MODEL_YCGCOA - luma, green delta, orange delta, alpha */ + KHR_DF_CHANNEL_YCGCOA_Y = 0U, + KHR_DF_CHANNEL_YCGCOA_CG = 1U, + KHR_DF_CHANNEL_YCGCOA_CO = 2U, + KHR_DF_CHANNEL_YCGCOA_ALPHA = 15U, + KHR_DF_CHANNEL_YCGCOA_A = 15U, + /* MODEL_CIEXYZ - CIE 1931 X, Y, Z */ + KHR_DF_CHANNEL_CIEXYZ_X = 0U, + KHR_DF_CHANNEL_CIEXYZ_Y = 1U, + KHR_DF_CHANNEL_CIEXYZ_Z = 2U, + /* MODEL_CIEXYY - CIE 1931 x, y, Y */ + KHR_DF_CHANNEL_CIEXYY_X = 0U, + KHR_DF_CHANNEL_CIEXYY_YCHROMA = 1U, + KHR_DF_CHANNEL_CIEXYY_YLUMA = 2U, + + /* Compressed formats */ + /* MODEL_DXT1A/MODEL_BC1A */ + KHR_DF_CHANNEL_DXT1A_COLOR = 0U, + KHR_DF_CHANNEL_BC1A_COLOR = 0U, + KHR_DF_CHANNEL_DXT1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_DXT1A_ALPHA = 1U, + KHR_DF_CHANNEL_BC1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_BC1A_ALPHA = 1U, + /* MODEL_DXT2/3/MODEL_BC2 */ + KHR_DF_CHANNEL_DXT2_COLOR = 0U, + KHR_DF_CHANNEL_DXT3_COLOR = 0U, + KHR_DF_CHANNEL_BC2_COLOR = 0U, + KHR_DF_CHANNEL_DXT2_ALPHA = 15U, + KHR_DF_CHANNEL_DXT3_ALPHA = 15U, + KHR_DF_CHANNEL_BC2_ALPHA = 15U, + /* MODEL_DXT4/5/MODEL_BC3 */ + KHR_DF_CHANNEL_DXT4_COLOR = 0U, + KHR_DF_CHANNEL_DXT5_COLOR = 0U, + KHR_DF_CHANNEL_BC3_COLOR = 0U, + KHR_DF_CHANNEL_DXT4_ALPHA = 15U, + KHR_DF_CHANNEL_DXT5_ALPHA = 15U, + KHR_DF_CHANNEL_BC3_ALPHA = 15U, + /* MODEL_BC4 */ + KHR_DF_CHANNEL_BC4_DATA = 0U, + /* MODEL_BC5 */ + KHR_DF_CHANNEL_BC5_RED = 0U, + KHR_DF_CHANNEL_BC5_R = 0U, + KHR_DF_CHANNEL_BC5_GREEN = 1U, + KHR_DF_CHANNEL_BC5_G = 1U, + /* MODEL_BC6H */ + KHR_DF_CHANNEL_BC6H_COLOR = 0U, + KHR_DF_CHANNEL_BC6H_DATA = 0U, + /* MODEL_BC7 */ + KHR_DF_CHANNEL_BC7_DATA = 0U, + KHR_DF_CHANNEL_BC7_COLOR = 0U, + /* MODEL_ETC1 */ + KHR_DF_CHANNEL_ETC1_DATA = 0U, + KHR_DF_CHANNEL_ETC1_COLOR = 0U, + /* MODEL_ETC2 */ + KHR_DF_CHANNEL_ETC2_RED = 0U, + KHR_DF_CHANNEL_ETC2_R = 0U, + KHR_DF_CHANNEL_ETC2_GREEN = 1U, + KHR_DF_CHANNEL_ETC2_G = 1U, + KHR_DF_CHANNEL_ETC2_COLOR = 2U, + KHR_DF_CHANNEL_ETC2_ALPHA = 15U, + KHR_DF_CHANNEL_ETC2_A = 15U, + /* MODEL_ASTC */ + KHR_DF_CHANNEL_ASTC_DATA = 0U, + /* MODEL_ETC1S */ + KHR_DF_CHANNEL_ETC1S_RGB = 0U, + KHR_DF_CHANNEL_ETC1S_RRR = 3U, + KHR_DF_CHANNEL_ETC1S_GGG = 4U, + KHR_DF_CHANNEL_ETC1S_AAA = 15U, + /* MODEL_PVRTC */ + KHR_DF_CHANNEL_PVRTC_DATA = 0U, + KHR_DF_CHANNEL_PVRTC_COLOR = 0U, + /* MODEL_PVRTC2 */ + KHR_DF_CHANNEL_PVRTC2_DATA = 0U, + KHR_DF_CHANNEL_PVRTC2_COLOR = 0U, + /* MODEL UASTC */ + KHR_DF_CHANNEL_UASTC_DATA = 0U, + KHR_DF_CHANNEL_UASTC_RGB = 0U, + KHR_DF_CHANNEL_UASTC_RGBA = 3U, + KHR_DF_CHANNEL_UASTC_RRR = 4U, + KHR_DF_CHANNEL_UASTC_RRRG = 5U, + KHR_DF_CHANNEL_UASTC_RG = 6U, + + /* Common channel names shared by multiple formats */ + KHR_DF_CHANNEL_COMMON_LUMA = 0U, + KHR_DF_CHANNEL_COMMON_L = 0U, + KHR_DF_CHANNEL_COMMON_STENCIL = 13U, + KHR_DF_CHANNEL_COMMON_S = 13U, + KHR_DF_CHANNEL_COMMON_DEPTH = 14U, + KHR_DF_CHANNEL_COMMON_D = 14U, + KHR_DF_CHANNEL_COMMON_ALPHA = 15U, + KHR_DF_CHANNEL_COMMON_A = 15U +} khr_df_model_channels_e; + +/** @~English + @brief Definition of the primary colors in color coordinates. + This is implicitly responsible for defining the conversion + between RGB an YUV color spaces. + LAB and related absolute color models should use + KHR_DF_PRIMARIES_CIEXYZ. */ +typedef enum _khr_df_primaries_e { + /** No color primaries defined */ + KHR_DF_PRIMARIES_UNSPECIFIED = 0U, + /** Color primaries of ITU-R BT.709 and sRGB */ + KHR_DF_PRIMARIES_BT709 = 1U, + /** Synonym for KHR_DF_PRIMARIES_BT709 */ + KHR_DF_PRIMARIES_SRGB = 1U, + /** Color primaries of ITU-R BT.601 (625-line EBU variant) */ + KHR_DF_PRIMARIES_BT601_EBU = 2U, + /** Color primaries of ITU-R BT.601 (525-line SMPTE C variant) */ + KHR_DF_PRIMARIES_BT601_SMPTE = 3U, + /** Color primaries of ITU-R BT.2020 */ + KHR_DF_PRIMARIES_BT2020 = 4U, + /** CIE theoretical color coordinate space */ + KHR_DF_PRIMARIES_CIEXYZ = 5U, + /** Academy Color Encoding System primaries */ + KHR_DF_PRIMARIES_ACES = 6U, + /** Color primaries of ACEScc */ + KHR_DF_PRIMARIES_ACESCC = 7U, + /** Legacy NTSC 1953 primaries */ + KHR_DF_PRIMARIES_NTSC1953 = 8U, + /** Legacy PAL 525-line primaries */ + KHR_DF_PRIMARIES_PAL525 = 9U, + /** Color primaries of Display P3 */ + KHR_DF_PRIMARIES_DISPLAYP3 = 10U, + /** Color primaries of Adobe RGB (1998) */ + KHR_DF_PRIMARIES_ADOBERGB = 11U, + KHR_DF_PRIMARIES_MAX = 0xFFU +} khr_df_primaries_e; + +/** @~English + @brief Definition of the optical to digital transfer function + ("gamma correction"). Most transfer functions are not a pure + power function and also include a linear element. + LAB and related absolute color representations should use + KHR_DF_TRANSFER_UNSPECIFIED. */ +typedef enum _khr_df_transfer_e { + /** No transfer function defined */ + KHR_DF_TRANSFER_UNSPECIFIED = 0U, + /** Linear transfer function (value proportional to intensity) */ + KHR_DF_TRANSFER_LINEAR = 1U, + /** Perceptually-linear transfer function of sRGH (~2.4) */ + KHR_DF_TRANSFER_SRGB = 2U, + /** Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45) */ + KHR_DF_TRANSFER_ITU = 3U, + /** SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) */ + KHR_DF_TRANSFER_SMTPE170M = 3U, + /** Perceptually-linear gamma function of original NTSC (simple 2.2 gamma) */ + KHR_DF_TRANSFER_NTSC = 4U, + /** Sony S-log used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG = 5U, + /** Sony S-log 2 used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG2 = 6U, + /** ITU BT.1886 EOTF */ + KHR_DF_TRANSFER_BT1886 = 7U, + /** ITU BT.2100 HLG OETF */ + KHR_DF_TRANSFER_HLG_OETF = 8U, + /** ITU BT.2100 HLG EOTF */ + KHR_DF_TRANSFER_HLG_EOTF = 9U, + /** ITU BT.2100 PQ EOTF */ + KHR_DF_TRANSFER_PQ_EOTF = 10U, + /** ITU BT.2100 PQ OETF */ + KHR_DF_TRANSFER_PQ_OETF = 11U, + /** DCI P3 transfer function */ + KHR_DF_TRANSFER_DCIP3 = 12U, + /** Legacy PAL OETF */ + KHR_DF_TRANSFER_PAL_OETF = 13U, + /** Legacy PAL 625-line EOTF */ + KHR_DF_TRANSFER_PAL625_EOTF = 14U, + /** Legacy ST240 transfer function */ + KHR_DF_TRANSFER_ST240 = 15U, + /** ACEScc transfer function */ + KHR_DF_TRANSFER_ACESCC = 16U, + /** ACEScct transfer function */ + KHR_DF_TRANSFER_ACESCCT = 17U, + /** Adobe RGB (1998) transfer function */ + KHR_DF_TRANSFER_ADOBERGB = 18U, + KHR_DF_TRANSFER_MAX = 0xFFU +} khr_df_transfer_e; + +typedef enum _khr_df_flags_e { + KHR_DF_FLAG_ALPHA_STRAIGHT = 0U, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1U +} khr_df_flags_e; + +typedef enum _khr_df_sample_datatype_qualifiers_e { + KHR_DF_SAMPLE_DATATYPE_LINEAR = 1U << 4U, + KHR_DF_SAMPLE_DATATYPE_EXPONENT = 1U << 5U, + KHR_DF_SAMPLE_DATATYPE_SIGNED = 1U << 6U, + KHR_DF_SAMPLE_DATATYPE_FLOAT = 1U << 7U +} khr_df_sample_datatype_qualifiers_e; + +#endif diff --git a/KTXLoader/libktx/ktx.xcframework/ios-arm64/Headers/ktx.h b/KTXLoader/libktx/ktx.xcframework/ios-arm64/Headers/ktx.h new file mode 100644 index 00000000..fd321c30 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/ios-arm64/Headers/ktx.h @@ -0,0 +1,1835 @@ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + +#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1 +#define KTX_H_A55A6F00956F42F3A137C11929827FE1 + +/* + * Copyright 2010-2018 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + * + * See the accompanying LICENSE.md for licensing details for all files in + * the KTX library and KTX loader tests. + */ + +/** + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX API. + * + * @author Mark Callow, Edgewise Consulting and while at HI Corporation + * @author Based on original work by Georg Kolling, Imagination Technology + * + * @snippet{doc} version.h API version + */ + +#include +#include +#include + +#include + +/* + * Don't use khrplatform.h in order not to break apps existing + * before these definitions were needed. + */ +#if defined(KHRONOS_STATIC) + #define KTX_API +#elif defined(_WIN32) || defined(__CYGWIN__) + #if !defined(KTX_API) + #if __GNUC__ + #define KTX_API __attribute__ ((dllimport)) + #elif _MSC_VER + #define KTX_API __declspec(dllimport) + #else + #error "Your compiler's equivalent of dllimport is unknown" + #endif + #endif +#elif defined(__ANDROID__) + #define KTX_API __attribute__((visibility("default"))) +#else + #define KTX_API +#endif + +#if defined(_WIN32) && !defined(KHRONOS_STATIC) + #if !defined(KTX_APIENTRY) + #define KTX_APIENTRY __stdcall + #endif +#else + #define KTX_APIENTRY +#endif + +/* To avoid including define our own types. */ +typedef unsigned char ktx_uint8_t; +typedef bool ktx_bool_t; +#ifdef _MSC_VER +typedef unsigned __int16 ktx_uint16_t; +typedef signed __int16 ktx_int16_t; +typedef unsigned __int32 ktx_uint32_t; +typedef signed __int32 ktx_int32_t; +typedef size_t ktx_size_t; +typedef unsigned __int64 ktx_uint64_t; +typedef signed __int64 ktx_int64_t; +#else +#include +typedef uint16_t ktx_uint16_t; +typedef int16_t ktx_int16_t; +typedef uint32_t ktx_uint32_t; +typedef int32_t ktx_int32_t; +typedef size_t ktx_size_t; +typedef uint64_t ktx_uint64_t; +typedef int64_t ktx_int64_t; +#endif + +/* This will cause compilation to fail if size of uint32 != 4. */ +typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4]; + +/* + * This #if allows libktx to be compiled with strict c99. It avoids + * compiler warnings or even errors when a gl.h is already included. + * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if + * gl.h comes after. However nobody has complained about the unguarded typedefs + * since they were introduced so this is unlikely to be a problem in practice. + * Presumably everybody is using platform default compilers not c99 or else + * they are using C++. + */ +#if !defined(GL_NO_ERROR) + /* + * To avoid having to including gl.h ... + */ + typedef unsigned char GLboolean; + typedef unsigned int GLenum; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLuint; + typedef unsigned char GLubyte; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_ANIMDATA_KEY "KTXanimData" +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +#define KTX_ORIENTATION_KEY "KTXorientation" +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +#define KTX_SWIZZLE_KEY "KTXswizzle" +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_WRITER_KEY "KTXwriter" +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams" +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +#define KTX_ORIENTATION1_FMT "S=%c" +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +#define KTX_ORIENTATION2_FMT "S=%c,T=%c" +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c" +/** + * @~English + * @brief Required unpack alignment + */ +#define KTX_GL_UNPACK_ALIGNMENT 4 + +#define KTX_TRUE true +#define KTX_FALSE false + +/** + * @~English + * @brief Error codes returned by library functions. + */ +typedef enum ktx_error_code_e { + KTX_SUCCESS = 0, /*!< Operation was successful. */ + KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */ + KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */ + KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */ + KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */ + KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */ + KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */ + KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */ + KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */ + KTX_GL_ERROR, /*!< GL operations resulted in an error. */ + KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ + KTX_INVALID_VALUE, /*!< A parameter value was not valid */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ + KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ + KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ + KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ + KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */ + KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */ + KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */ + KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */ + KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */ + KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */ +} ktx_error_code_e; +/** + * @deprecated + * @~English + * @brief For backward compatibility + */ +#define KTX_error_code ktx_error_code_e + +#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } +#define KTX_ENDIAN_REF (0x04030201) +#define KTX_ENDIAN_REF_REV (0x01020304) +#define KTX_HEADER_SIZE (64) + +/** + * @~English + * @brief Result codes returned by library functions. + */ + typedef enum ktx_error_code_e ktxResult; + +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ +typedef struct ktxKVListEntry* ktxHashList; + +typedef struct ktxStream ktxStream; + +#define KTX_APIENTRYP KTX_APIENTRY * +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ +typedef struct ktxKVListEntry ktxHashListEntry; + +typedef enum ktxOrientationX { + KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r' +} ktxOrientationX; + +typedef enum ktxOrientationY { + KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd' +} ktxOrientationY; + +typedef enum ktxOrientationZ { + KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o' +} ktxOrientationZ; + +typedef enum class_id { + ktxTexture1_c = 1, + ktxTexture2_c = 2 +} class_id; + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +struct ktxOrientation { + ktxOrientationX x; /*!< Orientation in X */ + ktxOrientationY y; /*!< Orientation in Y */ + ktxOrientationZ z; /*!< Orientation in Z */ +}; + +#define KTXTEXTURECLASSDEFN \ + class_id classId; \ + struct ktxTexture_vtbl* vtbl; \ + struct ktxTexture_vvtbl* vvtbl; \ + struct ktxTexture_protected* _protected; \ + ktx_bool_t isArray; \ + ktx_bool_t isCubemap; \ + ktx_bool_t isCompressed; \ + ktx_bool_t generateMipmaps; \ + ktx_uint32_t baseWidth; \ + ktx_uint32_t baseHeight; \ + ktx_uint32_t baseDepth; \ + ktx_uint32_t numDimensions; \ + ktx_uint32_t numLevels; \ + ktx_uint32_t numLayers; \ + ktx_uint32_t numFaces; \ + struct ktxOrientation orientation; \ + ktxHashList kvDataHead; \ + ktx_uint32_t kvDataLen; \ + ktx_uint8_t* kvData; \ + ktx_size_t dataSize; \ + ktx_uint8_t* pData; + + +/** + * @class ktxTexture + * @~English + * @brief Base class representing a texture. + * + * ktxTextures should be created only by one of the provided + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture { + KTXTEXTURECLASSDEFN +} ktxTexture; +/** + * @typedef ktxTexture::classId + * @~English + * @brief Identify the class type. + * + * Since there are no public ktxTexture constructors, this can only have + * values of ktxTexture1_c or ktxTexture2_c. + */ +/** + * @typedef ktxTexture::vtbl + * @~English + * @brief Pointer to the class's vtble. + */ +/** + * @typedef ktxTexture::vvtbl + * @~English + * @brief Pointer to the class's vtble for Vulkan functions. + * + * A separate vtble is used so this header does not need to include vulkan.h. + */ +/** + * @typedef ktxTexture::_protected + * @~English + * @brief Opaque pointer to the class's protected variables. + */ +/** + * @typedef ktxTexture::isArray + * @~English + * + * KTX_TRUE if the texture is an array texture, i.e, + * a GL_TEXTURE_*_ARRAY target is to be used. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture is a cubemap or cubemap array. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture's format is a block compressed format. + */ +/** + * @typedef ktxTexture::generateMipmaps + * @~English + * + * KTX_TRUE if mipmaps should be generated for the texture by + * ktxTexture_GLUpload() or ktxTexture_VkUpload(). + */ +/**n + * @typedef ktxTexture::baseWidth + * @~English + * @brief Width of the texture's base level. + */ +/** + * @typedef ktxTexture::baseHeight + * @~English + * @brief Height of the texture's base level. + */ +/** + * @typedef ktxTexture::baseDepth + * @~English + * @brief Depth of the texture's base level. + */ +/** + * @typedef ktxTexture::numDimensions + * @~English + * @brief Number of dimensions in the texture: 1, 2 or 3. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of mip levels in the texture. + * + * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a + * full pyramid but always starts at the base level. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of array layers in the texture. + */ +/** + * @typedef ktxTexture::numFaces + * @~English + * @brief Number of faces: 6 for cube maps, 1 otherwise. + */ +/** + * @typedef ktxTexture::orientation + * @~English + * @brief Describes the logical orientation of the images in each dimension. + * + * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z. + */ +/** + * @typedef ktxTexture::kvDataHead + * @~English + * @brief Head of the hash list of metadata. + */ +/** + * @typedef ktxTexture::kvDataLen + * @~English + * @brief Length of the metadata, if it has been extracted in its raw form, + * otherwise 0. + */ +/** + * @typedef ktxTexture::kvData + * @~English + * @brief Pointer to the metadata, if it has been extracted in its raw form, + * otherwise NULL. + */ +/** + * @typedef ktxTexture::dataSize + * @~English + * @brief Byte length of the texture's uncompressed image data. + */ +/** + * @typedef ktxTexture::pData + * @~English + * @brief Pointer to the start of the image data. + */ + +/** + * @memberof ktxTexture + * @~English + * @brief Signature of function called by the ktxTexture_Iterate* + * functions to receive image data. + * + * The function parameters are used to pass values which change for each image. + * Obtain values which are uniform across all images from the @c ktxTexture + * object. + * + * @param [in] miplevel MIP level from 0 to the max level which is + * dependent on the texture size. + * @param [in] face usually 0; for cube maps, one of the 6 cube + * faces in the order +X, -X, +Y, -Y, +Z, -Z, + * 0 to 5. + * @param [in] width width of the image. + * @param [in] height height of the image or, for 1D textures + * textures, 1. + * @param [in] depth depth of the image or, for 1D & 2D + * textures, 1. + * @param [in] faceLodSize number of bytes of data pointed at by + * @p pixels. + * @param [in] pixels pointer to the image data. + * @param [in,out] userdata pointer for the application to pass data to and + * from the callback function. + */ + +typedef KTX_error_code + (* PFNKTXITERCB)(int miplevel, int face, + int width, int height, int depth, + ktx_uint64_t faceLodSize, + void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + ktx_size_t* pOffset); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This, + PFNKTXITERCB iterCb, + void* userdata); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This, + ktx_uint8_t* pBuffer, + ktx_size_t bufSize); +typedef ktx_bool_t + (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + const ktx_uint8_t* src, + ktx_size_t srcSize); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + FILE* src, ktx_size_t srcSize); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This, + const char* const dstname); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, + ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + struct ktxTexture_vtbl { + PFNKTEXDESTROY Destroy; + PFNKTEXGETIMAGEOFFSET GetImageOffset; + PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + PFNKTEXGETIMAGESIZE GetImageSize; + PFNKTEXITERATELEVELS IterateLevels; + PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + PFNKTEXLOADIMAGEDATA LoadImageData; + PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; +}; + +/**************************************************************** + * Macros to give some backward compatibility to the previous API + ****************************************************************/ + +/** + * @~English + * @brief Helper for calling the Destroy virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_Destroy + */ +#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This) + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \ + (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset) + +/** + * @~English + * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture. + * + * For a ktxTexture1 this will always return the value of This->dataSize. + * + * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed + */ +#define ktxTexture_GetDataSizeUncompressed(This) \ + (This)->vtbl->GetDataSizeUncompressed(This) + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +#define ktxTexture_GetImageSize(This, level) \ + (This)->vtbl->GetImageSize(This, level) + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +#define ktxTexture_IterateLevels(This, iterCb, userdata) \ + (This)->vtbl->IterateLevels(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \ + (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \ + (This)->vtbl->LoadImageData(This, pBuffer, bufSize) + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This) + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize) + +/** + * @~English + * @brief Helper for calling the SetImageFromStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream + */ +#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) + +/** + * @~English + * @brief Helper for calling the WriteToStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream + */ +#define ktxTexture_WriteToStdioStream(This, dstsstr) \ + (This)->vtbl->WriteToStdioStream(This, dstsstr) + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +#define ktxTexture_WriteToNamedFile(This, dstname) \ + (This)->vtbl->WriteToNamedFile(This, dstname) + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ + (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + + +/** + * @class ktxTexture1 + * @~English + * @brief Class representing a KTX version 1 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture1 { + KTXTEXTURECLASSDEFN + ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + struct ktxTexture1_private* _private; /*!< Private data. */ +} ktxTexture1; + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +typedef enum ktxSupercmpScheme { + KTX_SS_NONE = 0, /*!< No supercompression. */ + KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */ + KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */ + KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */ + KTX_SS_BEGIN_RANGE = KTX_SS_NONE, + KTX_SS_END_RANGE = KTX_SS_ZLIB, + KTX_SS_BEGIN_VENDOR_RANGE = 0x10000, + KTX_SS_END_VENDOR_RANGE = 0x1ffff, + KTX_SS_BEGIN_RESERVED = 0x20000, + KTX_SUPERCOMPRESSION_BASIS = KTX_SS_BASIS_LZ, + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_BASIS_LZ instead. */ + KTX_SUPERCOMPRESSION_ZSTD = KTX_SS_ZSTD + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_ZSTD instead. */ +} ktxSupercmpScheme; + +/** + * @class ktxTexture2 + * @~English + * @brief Class representing a KTX version 2 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture2 { + KTXTEXTURECLASSDEFN + ktx_uint32_t vkFormat; + ktx_uint32_t* pDfd; + ktxSupercmpScheme supercompressionScheme; + ktx_bool_t isVideo; + ktx_uint32_t duration; + ktx_uint32_t timescale; + ktx_uint32_t loopcount; + struct ktxTexture2_private* _private; /*!< Private data. */ +} ktxTexture2; + +#define ktxTexture(t) ((ktxTexture*)t) + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1_Create() and + * ktxTexture2_Create(). + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef struct +{ + ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an + array texture. Means OpenGL will use a + GL_TEXTURE_*_ARRAY target. */ + ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} ktxTextureCreateInfo; + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef enum { + KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */ + KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */ +} ktxTextureCreateStorageEnum; + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +enum ktxTextureCreateFlagBits { + KTX_TEXTURE_CREATE_NO_FLAGS = 0x00, + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01, + /*!< Load the images from the KTX source. */ + KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08 + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +}; +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +typedef ktx_uint32_t ktxTextureCreateFlags; + +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + ktxStream_write write; /*!< pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< destruct the stream. */ + + enum streamType type; + union { + FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + struct + { + void* address; /**< pointer to the data. */ + void* allocatorAddress; /**< pointer to a memory allocator. */ + ktx_size_t size; /**< size of the data. */ + } custom_ptr; /**< pointer to a struct for custom streams. */ + } data; /**< pointer to the stream data. */ + ktx_off_t readpos; /**< used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +}; + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ +KTX_API ktx_uint8_t* KTX_APIENTRY +ktxTexture_GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ +KTX_API ktx_size_t KTX_APIENTRY +ktxTexture_GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, + GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); +/* + * Create a new ktxTexture1. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture1_NeedsTranscoding(ktxTexture1* This); + +/* + * Write a ktxTexture object to a stdio stream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + +/* + * Write a ktxTexture object to a named file in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname); + +/* + * Write a ktxTexture object to a block of memory in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, + ktx_uint8_t** bytes, ktx_size_t* size); + +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + +/* + * Create a new ktxTexture2. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + +KTX_API void KTX_APIENTRY +ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, + ktx_uint32_t* componentByteLength); + +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetNumComponents(ktxTexture2* This); + +KTX_API khr_df_transfer_e KTX_APIENTRY +ktxTexture2_GetOETF_e(ktxTexture2* This); + +// For backward compatibility +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetOETF(ktxTexture2* This); + +KTX_API khr_df_model_e KTX_APIENTRY +ktxTexture2_GetColorModel_e(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_NeedsTranscoding(ktxTexture2* This); + +/** + * @~English + * @brief Flags specifiying UASTC encoding options. + */ +typedef enum ktx_pack_uastc_flag_bits_e { + KTX_PACK_UASTC_LEVEL_FASTEST = 0, + /*!< Fastest compression. 43.45dB. */ + KTX_PACK_UASTC_LEVEL_FASTER = 1, + /*!< Faster compression. 46.49dB. */ + KTX_PACK_UASTC_LEVEL_DEFAULT = 2, + /*!< Default compression. 47.47dB. */ + KTX_PACK_UASTC_LEVEL_SLOWER = 3, + /*!< Slower compression. 48.01dB. */ + KTX_PACK_UASTC_LEVEL_VERYSLOW = 4, + /*!< Very slow compression. 48.24dB. */ + KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW, + /*!< Maximum supported quality level. */ + KTX_PACK_UASTC_LEVEL_MASK = 0xF, + /*!< Mask to extract the level from the other bits. */ + KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8, + /*!< Optimize for lowest UASTC error. */ + KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16, + /*!< Optimize for lowest BC7 error. */ + KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64, + /*!< Optimize for faster transcoding to ETC1. */ + KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128, + /*!< Optimize for fastest transcoding to ETC1. */ + KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256 + /*!< Not documented in BasisU code. */ +} ktx_pack_uastc_flag_bits_e; +typedef ktx_uint32_t ktx_pack_uastc_flags; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +typedef enum ktx_pack_astc_quality_levels_e { + KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0, + /*!< Fastest compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10, + /*!< Fast compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60, + /*!< Medium compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98, + /*!< Slower compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100, + /*!< Very slow compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE, + /*!< Maximum supported quality level. */ +} ktx_pack_astc_quality_levels_e; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +typedef enum ktx_pack_astc_block_dimension_e { + // 2D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp + // 3D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6 + /*!< Maximum supported blocks. */ +} ktx_pack_astc_block_dimension_e; + +/** + * @~English + * @brief Options specifying ASTC encoder profile mode + * This and function is used later to derive the profile. + */ +typedef enum ktx_pack_astc_encoder_mode_e { + KTX_PACK_ASTC_ENCODER_MODE_DEFAULT, + KTX_PACK_ASTC_ENCODER_MODE_LDR, + KTX_PACK_ASTC_ENCODER_MODE_HDR, + KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR +} ktx_pack_astc_encoder_mode_e; + +extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture_CompressAstc. + * + * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension + * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to + * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended. + */ +typedef struct ktxAstcParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + ktx_uint32_t qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps + In this mode normals are compressed to X,Y components + Discarding Z component, reader will need to generate Z + component in shaders. + */ + + ktx_bool_t perceptual; + /*!< The codec should optimize for perceptual error, instead of direct + RMS error. This aims to improves perceived image quality, but + typically lowers the measured PSNR score. Perceptual methods are + currently only available for normal maps and RGB color data. + */ + + char inputSwizzle[4]; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} ktxAstcParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + +/** + * @memberof ktxTexture2 + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture2_CompressBasisEx(). + * + * If you only want default values, use ktxTexture2_CompressBasis(). Here, at a minimum you + * must initialize the structure as follows: + * @code + * ktxBasisParams params = {0}; + * params.structSize = sizeof(params); + * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e compressionLevel has to be explicitly set because 0 is a valid @e compressionLevel + * but is not the default used by the BasisU encoder when no value is set. Only the other + * settings that are to be non-default must be non-zero. + */ +typedef struct ktxBasisParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + ktx_bool_t uastc; + /*!< True to use UASTC base, false to use ETC1S base. */ + ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + ktx_uint32_t compressionLevel; + /*!< Encoding speed vs. quality tradeoff. Range is [0,5]. Higher values + are slower, but give higher quality. There is no default. Callers + must explicitly set this value. Callers can use + KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL as a default value. + Currently this is 2. + */ + ktx_uint32_t qualityLevel; + /*!< Compression quality. Range is [1,255]. Lower gives better + compression/lower quality/faster. Higher gives less compression + /higher quality/slower. This automatically determines values for + @c maxEndpoints, @c maxSelectors, + @c endpointRDOThreshold and @c selectorRDOThreshold + for the target quality level. Setting these parameters overrides + the values determined by @c qualityLevel which defaults to + 128 if neither it nor both of @c maxEndpoints and + @c maxSelectors have been set. + @note @e Both of @c maxEndpoints and @c maxSelectors + must be set for them to have any effect. + @note qualityLevel will only determine values for + @c endpointRDOThreshold and @c selectorRDOThreshold + when its value exceeds 128, otherwise their defaults will be used. + */ + ktx_uint32_t maxEndpoints; + /*!< Manually set the max number of color endpoint clusters. + Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors + must also be set, otherwise the value will be ignored. + */ + float endpointRDOThreshold; + /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is + higher quality but less quality per output bit (try [1.0,3.0]. + This will override the value chosen by @c qualityLevel. + */ + ktx_uint32_t maxSelectors; + /*!< Manually set the max number of color selector clusters. Range + is [1,16128]. Default is 0, unset. If this is set, maxEndpoints + must also be set, otherwise the value will be ignored. + */ + float selectorRDOThreshold; + /*!< Set selector RDO quality threshold. The default is 1.5. Lower is + higher quality but less quality per output bit (try [1.0,3.0]). + This will override the value chosen by @c qualityLevel. + */ + char inputSwizzle[4]; + /*!< A swizzle to apply before encoding. It must match the regular + expression /^[rgba01]{4}$/. If both this and preSwizzle + are specified ktxTexture_CompressBasisEx will raise + KTX_INVALID_OPERATION. + */ + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps (no + selector RDO, no endpoint RDO) and sets the texture's DFD appropriately. + Only valid for linear textures. + */ + ktx_bool_t separateRGToRGB_A; + /*!< @deprecated. This was and is a no-op. 2-component inputs have always been + automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode. + */ + ktx_bool_t preSwizzle; + /*!< If the texture has @c KTXswizzle metadata, apply it before + compressing. Swizzling, like @c rabb may yield drastically + different error metrics if done after supercompression. + */ + ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + ktx_bool_t noSelectorRDO; + /*!< Disable selector rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + + /* UASTC params */ + + ktx_pack_uastc_flags uastcFlags; + /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC + encoding. The most important value is the level given in the + least-significant 4 bits which selects a speed vs quality tradeoff + as shown in the following table: + + Level/Speed | Quality + :-----: | :-------: + KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB + KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB + KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB + KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB + KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB + */ + ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + float uastcRDOQualityScalar; + /*!< UASTC RDO quality scalar (lambda). Lower values yield higher + quality/larger LZ compressed files, higher values yield lower + quality/smaller LZ compressed files. A good range to try is [.2,4]. + Full range is [.001,50.0]. Default is 1.0. + */ + ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + float uastcRDOMaxSmoothBlockErrorScale; + /*!< UASTC RDO max smooth block error scale. Range is [1,300]. + Default is 10.0, 1.0 is disabled. Larger values suppress more + artifacts (and allocate more bits) on smooth blocks. + */ + float uastcRDOMaxSmoothBlockStdDev; + /*!< UASTC RDO max smooth block standard deviation. Range is + [.01,65536.0]. Default is 18.0. Larger values expand the range of + blocks considered smooth. + */ + ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + +} ktxBasisParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params); + +/** + * @~English + * @brief Enumerators for specifying the transcode target format. + * + * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate + * RGB images, a.k.a slices within the BasisU compressed data. For UASTC + * format they refer to the RGB and the alpha components of the UASTC data. If + * the original image had only 2 components, R will be in the opaque portion + * and G in the alpha portion. The R value will be replicated in the RGB + * components. In the case of BasisU the G value will be replicated in all 3 + * components of the alpha slice. If the original image had only 1 component + * it's value is replicated in all 3 components of the opaque portion and + * there is no alpha. + * + * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R, + * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565, + * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor + * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader + * will not produce correct results if any texture filtering is being used. + */ +typedef enum ktx_transcode_fmt_e { + // Compressed formats + + // ETC1-2 + KTX_TTF_ETC1_RGB = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_RGBA = 1, + /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + + // BC1-5, BC7 (desktop, some mobile devices) + KTX_TTF_BC1_RGB = 2, + /*!< Opaque only, no punchthrough alpha support yet. Returns RGB + or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS + flag is specified. */ + KTX_TTF_BC3_RGBA = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + KTX_TTF_BC4_R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_BC5_RG = 5, + /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should + have an alpha channel (if not G will be all 255's. For tangent + space normal maps. */ + KTX_TTF_BC7_RGBA = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + KTX_TTF_PVRTC1_4_RGB = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_PVRTC1_4_RGBA = 9, + /*!< Opaque+alpha. Most useful for simple opacity maps. If the + texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB + will be used instead. Lowest quality of any supported + texture format. */ + + // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day) + KTX_TTF_ASTC_4x4_RGBA = 10, + /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for + textures without an alpha channel. The transcoder uses + RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and + [0,255]) endpoint precisions. */ + + // ATC and FXT1 formats are not supported by KTX2 as there + // are no equivalent VkFormats. + + KTX_TTF_PVRTC2_4_RGB = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + KTX_TTF_PVRTC2_4_RGBA = 19, + /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB. + Premultiplied alpha is highly recommended, otherwise the + color channel can leak into the alpha channel on transparent + blocks. */ + + KTX_TTF_ETC2_EAC_R11 = 20, + /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_EAC_RG11 = 21, + /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The + texture should have an alpha channel (if not G will be all + 255's. For tangent space normal maps. */ + + // Uncompressed (raw pixel) formats + KTX_TTF_RGBA32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + KTX_TTF_RGB565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + KTX_TTF_BGR565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + KTX_TTF_RGBA4444 = 16, + /*!< 16bpp RGBA image stored in raster (not block) order in memory, + R at bit position 12, A at bit position 0. */ + + // Values for automatic selection of RGB or RGBA depending if alpha + // present. + KTX_TTF_ETC = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + KTX_TTF_BC1_OR_3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + KTX_TTF_NOSELECTION = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + KTX_TF_ETC1 = KTX_TTF_ETC1_RGB, + //!< @deprecated. Use #KTX_TTF_ETC1_RGB. + KTX_TF_ETC2 = KTX_TTF_ETC, + //!< @deprecated. Use #KTX_TTF_ETC. + KTX_TF_BC1 = KTX_TTF_BC1_RGB, + //!< @deprecated. Use #KTX_TTF_BC1_RGB. + KTX_TF_BC3 = KTX_TTF_BC3_RGBA, + //!< @deprecated. Use #KTX_TTF_BC3_RGBA. + KTX_TF_BC4 = KTX_TTF_BC4_R, + //!< @deprecated. Use #KTX_TTF_BC4_R. + KTX_TF_BC5 = KTX_TTF_BC5_RG, + //!< @deprecated. Use #KTX_TTF_BC5_RG. + KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA + KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB + //!< @deprecated. Use #KTX_TTF_PVRTC1_4_RGB. +} ktx_transcode_fmt_e; + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +typedef enum ktx_transcode_flag_bits_e { + KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2, + /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger + power of 2 (not implemented yet, but we're going to support it). + Ignored if the slice's dimensions are already a power of 2. + */ + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4, + /*!< When decoding to an opaque texture format, if the Basis data has + alpha, decode the alpha slice instead of the color slice to the + output texture format. Has no effect if there is no alpha data. + */ + KTX_TF_HIGH_QUALITY = 32, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} ktx_transcode_flag_bits_e; +typedef ktx_uint32_t ktx_transcode_flags; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, + ktx_transcode_flags transcodeFlags); + +/* + * Returns a string corresponding to a KTX error code. + */ +KTX_API const char* KTX_APIENTRY +ktxErrorString(KTX_error_code error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ +KTX_API const char* KTX_APIENTRY +ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ +KTX_API const char* KTX_APIENTRY +ktxTranscodeFormatString(ktx_transcode_fmt_e format); + +KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl); +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl); +KTX_API void KTX_APIENTRY +ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head); +KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_AddKVPair(ktxHashList* pHead, const char* key, + unsigned int valueLen, const void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindEntry(ktxHashList* pHead, const char* key, + ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindValue(ktxHashList* pHead, const char* key, + unsigned int* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ +KTX_API ktxHashListEntry* KTX_APIENTRY +ktxHashList_Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Serialize(ktxHashList* pHead, + unsigned int* kvdLen, unsigned char** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd); + +/* + * Get the key from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetKey(ktxHashListEntry* This, + unsigned int* pKeyLen, char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetValue(ktxHashListEntry* This, + unsigned int* pValueLen, void** ppValue); + +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX2 file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); + +#ifdef __cplusplus +} +#endif + +/*========================================================================* + * For backward compatibilty with the V3 & early versions of the V4 APIs. * + *========================================================================*/ + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_transcode_fmt_e ktx_transcode_fmt_e + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_decode_flags ktx_transcode_flag_bits + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktxTexture_GetSize ktxTexture_GetDatasize + +/** +@~English +@page libktx_history Revision History + +No longer updated. Kept to preserve ancient history. For more recent history see the repo log at +https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo. + +@section v8 Version 4.0 +Added: +@li Support for KTX Version 2. +@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files. +@li Function to print info about a KTX file. + +@section v7 Version 3.0.1 +Fixed: +@li GitHub issue #159: compile failure with recent Vulkan SDKs. +@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents. +@li Incorrect BC4 blocksize. +@li Missing mapping of PVRTC formats from GL to Vulkan. +@li Incorrect block width and height calculations for sizes that are not + a multiple of the block size. +@li Incorrect KTXorientation key in test images. + +@section v6 Version 3.0 +Added: +@li new ktxTexture object based API for reading KTX files without an OpenGL context. +@li Vulkan loader. @#include to use it. + +Changed: +@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h. + Applications using OpenGL must now include these files themselves. +@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures + when the OpenGL context does not support 1D textures. + KTX_UNSUPPORTED_TEXTURE_TYPE is now returned. + +@section v5 Version 2.0.2 +Added: +@li Support for cubemap arrays. + +Changed: +@li New build system + +Fixed: +@li GitHub issue #40: failure to byte-swap key-value lengths. +@li GitHub issue #33: returning incorrect target when loading cubemaps. +@li GitHub PR #42: loading of texture arrays. +@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined. +@li GitHub issue #39: stack-buffer-overflow in toktx +@li Don't use GL_EXTENSIONS on recent OpenGL versions. + +@section v4 Version 2.0.1 +Added: +@li CMake build files. Thanks to Pavel Rotjberg for the initial version. + +Changed: +@li ktxWriteKTXF to check the validity of the type & format combinations + passed to it. + +Fixed: +@li Public Bugzilla 999: 16-bit luminance texture cannot be written. +@li compile warnings from compilers stricter than MS Visual C++. Thanks to + Pavel Rotjberg. + +@section v3 Version 2.0 +Added: +@li support for decoding ETC2 and EAC formats in the absence of a hardware + decoder. +@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA, + etc. formats to the equivalent R, RG, etc. format with an + appropriate swizzle, when loading in OpenGL Core Profile contexts. +@li ktxErrorString function to return a string corresponding to an error code. +@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3. + The latter includes an EGL on WGL wrapper that makes porting apps between + OpenGL ES and OpenGL easier on Windows. +@li more texture formats to ktxLoadTexture[FN] and toktx tests. + +Changed: +@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at + run time and load textures, or not, according to those capabilities. + +Fixed: +@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX + format. +@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write + more than 1 byte of face-LOD padding. + +Although there is only a very minor API change, the addition of ktxErrorString, +the functional changes are large enough to justify bumping the major revision +number. + +@section v2 Version 1.0.1 +Implemented ktxLoadTextureM. +Fixed the following: +@li Public Bugzilla 571: crash when null passed for pIsMipmapped. +@li Public Bugzilla 572: memory leak when unpacking ETC textures. +@li Public Bugzilla 573: potential crash when unpacking ETC textures with unused padding pixels. +@li Public Bugzilla 576: various small fixes. + +Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes. + +@section v1 Version 1.0 +Initial release. + +*/ + +#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ diff --git a/KTXLoader/libktx/ktx.xcframework/ios-arm64/libktx.a b/KTXLoader/libktx/ktx.xcframework/ios-arm64/libktx.a new file mode 100644 index 00000000..912f365f Binary files /dev/null and b/KTXLoader/libktx/ktx.xcframework/ios-arm64/libktx.a differ diff --git a/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/Headers/KHR/khr_df.h b/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/Headers/KHR/khr_df.h new file mode 100644 index 00000000..c0d03aa7 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/Headers/KHR/khr_df.h @@ -0,0 +1,630 @@ +/* The Khronos Data Format Specification (version 1.3) */ +/* +** Copyright 2015-2020 The Khronos Group Inc. +** SPDX-License-Identifier: Apache-2.0 +*/ + +/* This header defines a structure that can describe the layout of image + formats in memory. This means that the data format is transparent to + the application, and the expectation is that this should be used when + the layout is defined external to the API. Many Khronos APIs deliberately + keep the internal layout of images opaque, to allow proprietary layouts + and optimisations. This structure is not appropriate for describing + opaque layouts. */ + +/* We stick to standard C89 constructs for simplicity and portability. */ + +#ifndef _KHR_DATA_FORMAT_H_ +#define _KHR_DATA_FORMAT_H_ + +/** @file khr_df.h + + @brief Data Format enums and macros. +*/ + +/* Accessors */ +typedef enum _khr_word_e { + KHR_DF_WORD_VENDORID = 0U, + KHR_DF_WORD_DESCRIPTORTYPE = 0U, + KHR_DF_WORD_VERSIONNUMBER = 1U, + KHR_DF_WORD_DESCRIPTORBLOCKSIZE = 1U, + KHR_DF_WORD_MODEL = 2U, + KHR_DF_WORD_PRIMARIES = 2U, + KHR_DF_WORD_TRANSFER = 2U, + KHR_DF_WORD_FLAGS = 2U, + KHR_DF_WORD_TEXELBLOCKDIMENSION0 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION1 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION2 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION3 = 3U, + KHR_DF_WORD_BYTESPLANE0 = 4U, + KHR_DF_WORD_BYTESPLANE1 = 4U, + KHR_DF_WORD_BYTESPLANE2 = 4U, + KHR_DF_WORD_BYTESPLANE3 = 4U, + KHR_DF_WORD_BYTESPLANE4 = 5U, + KHR_DF_WORD_BYTESPLANE5 = 5U, + KHR_DF_WORD_BYTESPLANE6 = 5U, + KHR_DF_WORD_BYTESPLANE7 = 5U, + KHR_DF_WORD_SAMPLESTART = 6U, + KHR_DF_WORD_SAMPLEWORDS = 4U +} khr_df_word_e; + +typedef enum _khr_df_shift_e { + KHR_DF_SHIFT_VENDORID = 0U, + KHR_DF_SHIFT_DESCRIPTORTYPE = 17U, + KHR_DF_SHIFT_VERSIONNUMBER = 0U, + KHR_DF_SHIFT_DESCRIPTORBLOCKSIZE = 16U, + KHR_DF_SHIFT_MODEL = 0U, + KHR_DF_SHIFT_PRIMARIES = 8U, + KHR_DF_SHIFT_TRANSFER = 16U, + KHR_DF_SHIFT_FLAGS = 24U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION0 = 0U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION1 = 8U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION2 = 16U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION3 = 24U, + KHR_DF_SHIFT_BYTESPLANE0 = 0U, + KHR_DF_SHIFT_BYTESPLANE1 = 8U, + KHR_DF_SHIFT_BYTESPLANE2 = 16U, + KHR_DF_SHIFT_BYTESPLANE3 = 24U, + KHR_DF_SHIFT_BYTESPLANE4 = 0U, + KHR_DF_SHIFT_BYTESPLANE5 = 8U, + KHR_DF_SHIFT_BYTESPLANE6 = 16U, + KHR_DF_SHIFT_BYTESPLANE7 = 24U +} khr_df_shift_e; + +typedef enum _khr_df_mask_e { + KHR_DF_MASK_VENDORID = 0x1FFFFU, + KHR_DF_MASK_DESCRIPTORTYPE = 0x7FFFU, + KHR_DF_MASK_VERSIONNUMBER = 0xFFFFU, + KHR_DF_MASK_DESCRIPTORBLOCKSIZE = 0xFFFFU, + KHR_DF_MASK_MODEL = 0xFFU, + KHR_DF_MASK_PRIMARIES = 0xFFU, + KHR_DF_MASK_TRANSFER = 0xFFU, + KHR_DF_MASK_FLAGS = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION0 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION1 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION2 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE0 = 0xFFU, + KHR_DF_MASK_BYTESPLANE1 = 0xFFU, + KHR_DF_MASK_BYTESPLANE2 = 0xFFU, + KHR_DF_MASK_BYTESPLANE3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE4 = 0xFFU, + KHR_DF_MASK_BYTESPLANE5 = 0xFFU, + KHR_DF_MASK_BYTESPLANE6 = 0xFFU, + KHR_DF_MASK_BYTESPLANE7 = 0xFFU +} khr_df_mask_e; + +/* Helper macro: + Extract field X from basic descriptor block BDB */ +#define KHR_DFDVAL(BDB, X) \ + (((BDB)[KHR_DF_WORD_ ## X] >> (KHR_DF_SHIFT_ ## X)) \ + & (KHR_DF_MASK_ ## X)) + +/* Helper macro: + Set field X of basic descriptor block BDB */ +#define KHR_DFDSETVAL(BDB, X, val) \ + ((BDB)[KHR_DF_WORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_ ## X] & \ + ~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \ + (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X))) + +/* Offsets relative to the start of a sample */ +typedef enum _khr_df_sampleword_e { + KHR_DF_SAMPLEWORD_BITOFFSET = 0U, + KHR_DF_SAMPLEWORD_BITLENGTH = 0U, + KHR_DF_SAMPLEWORD_CHANNELID = 0U, + KHR_DF_SAMPLEWORD_QUALIFIERS = 0U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION0 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION1 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION2 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION3 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL = 1U, + KHR_DF_SAMPLEWORD_SAMPLELOWER = 2U, + KHR_DF_SAMPLEWORD_SAMPLEUPPER = 3U +} khr_df_sampleword_e; + +typedef enum _khr_df_sampleshift_e { + KHR_DF_SAMPLESHIFT_BITOFFSET = 0U, + KHR_DF_SAMPLESHIFT_BITLENGTH = 16U, + KHR_DF_SAMPLESHIFT_CHANNELID = 24U, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLESHIFT_QUALIFIERS = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION0 = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION1 = 8U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION2 = 16U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION3 = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION_ALL = 0U, + KHR_DF_SAMPLESHIFT_SAMPLELOWER = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEUPPER = 0U +} khr_df_sampleshift_e; + +typedef enum _khr_df_samplemask_e { + KHR_DF_SAMPLEMASK_BITOFFSET = 0xFFFFU, + KHR_DF_SAMPLEMASK_BITLENGTH = 0xFF, + KHR_DF_SAMPLEMASK_CHANNELID = 0xF, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLEMASK_QUALIFIERS = 0xF0, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION0 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION1 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION2 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION3 = 0xFF, + /* ISO C restricts enum values to range of int hence the + cast. We do it verbosely instead of using -1 to ensure + it is a 32-bit value even if int is 64 bits. */ + KHR_DF_SAMPLEMASK_SAMPLEPOSITION_ALL = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLELOWER = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLEUPPER = (int) 0xFFFFFFFFU +} khr_df_samplemask_e; + +/* Helper macro: + Extract field X of sample S from basic descriptor block BDB */ +#define KHR_DFDSVAL(BDB, S, X) \ + (((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] >> (KHR_DF_SAMPLESHIFT_ ## X)) \ + & (KHR_DF_SAMPLEMASK_ ## X)) + +/* Helper macro: + Set field X of sample S of basic descriptor block BDB */ +#define KHR_DFDSETSVAL(BDB, S, X, val) \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] & \ + ~((uint32_t)(KHR_DF_SAMPLEMASK_ ## X) << (KHR_DF_SAMPLESHIFT_ ## X))) | \ + (((val) & (uint32_t)(KHR_DF_SAMPLEMASK_ ## X)) << (KHR_DF_SAMPLESHIFT_ ## X))) + +/* Helper macro: + Number of samples in basic descriptor block BDB */ +#define KHR_DFDSAMPLECOUNT(BDB) \ + (((KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) >> 2) - \ + KHR_DF_WORD_SAMPLESTART) \ + / KHR_DF_WORD_SAMPLEWORDS) + +/* Helper macro: + Size in words of basic descriptor block for S samples */ +#define KHR_DFDSIZEWORDS(S) \ + (KHR_DF_WORD_SAMPLESTART + \ + (S) * KHR_DF_WORD_SAMPLEWORDS) + +/* Vendor ids */ +typedef enum _khr_df_vendorid_e { + /* Standard Khronos descriptor */ + KHR_DF_VENDORID_KHRONOS = 0U, + KHR_DF_VENDORID_MAX = 0x1FFFFU +} khr_df_vendorid_e; + +/* Descriptor types */ +typedef enum _khr_df_khr_descriptortype_e { + /* Default Khronos basic descriptor block */ + KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0U, + /* Extension descriptor block for additional planes */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_PLANES = 0x6001U, + /* Extension descriptor block for additional dimensions */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_DIMENSIONS = 0x6002U, + /* Bit indicates modifying requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_WRITE_BIT = 0x2000U, + /* Bit indicates processing requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_DECODE_BIT = 0x4000U, + KHR_DF_KHR_DESCRIPTORTYPE_MAX = 0x7FFFU +} khr_df_khr_descriptortype_e; + +/* Descriptor block version */ +typedef enum _khr_df_versionnumber_e { + /* Standard Khronos descriptor */ + KHR_DF_VERSIONNUMBER_1_0 = 0U, /* Version 1.0 of the specification */ + KHR_DF_VERSIONNUMBER_1_1 = 0U, /* Version 1.1 did not bump the version number */ + KHR_DF_VERSIONNUMBER_1_2 = 1U, /* Version 1.2 increased the version number */ + KHR_DF_VERSIONNUMBER_1_3 = 2U, /* Version 1.3 increased the version number */ + KHR_DF_VERSIONNUMBER_LATEST = KHR_DF_VERSIONNUMBER_1_3, + KHR_DF_VERSIONNUMBER_MAX = 0xFFFFU +} khr_df_versionnumber_e; + +/** @~English + @brief Model in which the color coordinate space is defined. + There is no requirement that a color format use all the + channel types that are defined in the color model. */ +typedef enum _khr_df_model_e { + /** No interpretation of color channels defined */ + KHR_DF_MODEL_UNSPECIFIED = 0U, + /** Color primaries (red, green, blue) + alpha, depth and stencil */ + KHR_DF_MODEL_RGBSDA = 1U, + /** Color differences (Y', Cb, Cr) + alpha, depth and stencil */ + KHR_DF_MODEL_YUVSDA = 2U, + /** Color differences (Y', I, Q) + alpha, depth and stencil */ + KHR_DF_MODEL_YIQSDA = 3U, + /** Perceptual color (CIE L*a*b*) + alpha, depth and stencil */ + KHR_DF_MODEL_LABSDA = 4U, + /** Subtractive colors (cyan, magenta, yellow, black) + alpha */ + KHR_DF_MODEL_CMYKA = 5U, + /** Non-color coordinate data (X, Y, Z, W) */ + KHR_DF_MODEL_XYZW = 6U, + /** Hue, saturation, value, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSVA_ANG = 7U, + /** Hue, saturation, lightness, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSLA_ANG = 8U, + /** Hue, saturation, value, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSVA_HEX = 9U, + /** Hue, saturation, lightness, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSLA_HEX = 10U, + /** Lightweight approximate color difference (luma, orange, green) */ + KHR_DF_MODEL_YCGCOA = 11U, + /** ITU BT.2020 constant luminance YcCbcCrc */ + KHR_DF_MODEL_YCCBCCRC = 12U, + /** ITU BT.2100 constant intensity ICtCp */ + KHR_DF_MODEL_ICTCP = 13U, + /** CIE 1931 XYZ color coordinates (X, Y, Z) */ + KHR_DF_MODEL_CIEXYZ = 14U, + /** CIE 1931 xyY color coordinates (X, Y, Y) */ + KHR_DF_MODEL_CIEXYY = 15U, + + /* Compressed formats start at 128. */ + /* These compressed formats should generally have a single sample, + sited at the 0,0 position of the texel block. Where multiple + channels are used to distinguish formats, these should be cosited. */ + /* Direct3D (and S3) compressed formats */ + /* Note that premultiplied status is recorded separately */ + /** DXT1 "channels" are RGB (0), Alpha (1) + DXT1/BC1 with one channel is opaque + DXT1/BC1 with a cosited alpha sample is transparent */ + KHR_DF_MODEL_DXT1A = 128U, + KHR_DF_MODEL_BC1A = 128U, + /** DXT2/DXT3/BC2, with explicit 4-bit alpha */ + KHR_DF_MODEL_DXT2 = 129U, + KHR_DF_MODEL_DXT3 = 129U, + KHR_DF_MODEL_BC2 = 129U, + /** DXT4/DXT5/BC3, with interpolated alpha */ + KHR_DF_MODEL_DXT4 = 130U, + KHR_DF_MODEL_DXT5 = 130U, + KHR_DF_MODEL_BC3 = 130U, + /** BC4 - single channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC4 = 131U, + /** BC5 - two channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC5 = 132U, + /** BC6H - DX11 format for 16-bit float channels */ + KHR_DF_MODEL_BC6H = 133U, + /** BC7 - DX11 format */ + KHR_DF_MODEL_BC7 = 134U, + /* Gap left for future desktop expansion */ + + /* Mobile compressed formats follow */ + /** A format of ETC1 indicates that the format shall be decodable + by an ETC1-compliant decoder and not rely on ETC2 features */ + KHR_DF_MODEL_ETC1 = 160U, + /** A format of ETC2 is permitted to use ETC2 encodings on top of + the baseline ETC1 specification. + The ETC2 format has channels "red", "green", "RGB" and "alpha", + which should be cosited samples. + Punch-through alpha can be distinguished from full alpha by + the plane size in bytes required for the texel block */ + KHR_DF_MODEL_ETC2 = 161U, + /** Adaptive Scalable Texture Compression */ + /** ASTC HDR vs LDR is determined by the float flag in the channel */ + /** ASTC block size can be distinguished by texel block size */ + KHR_DF_MODEL_ASTC = 162U, + /** ETC1S is a simplified subset of ETC1 */ + KHR_DF_MODEL_ETC1S = 163U, + /** PowerVR Texture Compression v1 */ + KHR_DF_MODEL_PVRTC = 164U, + /** PowerVR Texture Compression v2 */ + KHR_DF_MODEL_PVRTC2 = 165U, + /** UASTC is a transcodable subset of ASTC + with additions to support the transcoding. */ + KHR_DF_MODEL_UASTC = 166U, + /* Proprietary formats (ATITC, etc.) should follow */ + KHR_DF_MODEL_MAX = 0xFFU +} khr_df_model_e; + +/* Definition of channel names for each color model */ +typedef enum _khr_df_model_channels_e { + /* Unspecified format with nominal channel numbering */ + KHR_DF_CHANNEL_UNSPECIFIED_0 = 0U, + KHR_DF_CHANNEL_UNSPECIFIED_1 = 1U, + KHR_DF_CHANNEL_UNSPECIFIED_2 = 2U, + KHR_DF_CHANNEL_UNSPECIFIED_3 = 3U, + KHR_DF_CHANNEL_UNSPECIFIED_4 = 4U, + KHR_DF_CHANNEL_UNSPECIFIED_5 = 5U, + KHR_DF_CHANNEL_UNSPECIFIED_6 = 6U, + KHR_DF_CHANNEL_UNSPECIFIED_7 = 7U, + KHR_DF_CHANNEL_UNSPECIFIED_8 = 8U, + KHR_DF_CHANNEL_UNSPECIFIED_9 = 9U, + KHR_DF_CHANNEL_UNSPECIFIED_10 = 10U, + KHR_DF_CHANNEL_UNSPECIFIED_11 = 11U, + KHR_DF_CHANNEL_UNSPECIFIED_12 = 12U, + KHR_DF_CHANNEL_UNSPECIFIED_13 = 13U, + KHR_DF_CHANNEL_UNSPECIFIED_14 = 14U, + KHR_DF_CHANNEL_UNSPECIFIED_15 = 15U, + /* MODEL_RGBSDA - red, green, blue, stencil, depth, alpha */ + KHR_DF_CHANNEL_RGBSDA_RED = 0U, + KHR_DF_CHANNEL_RGBSDA_R = 0U, + KHR_DF_CHANNEL_RGBSDA_GREEN = 1U, + KHR_DF_CHANNEL_RGBSDA_G = 1U, + KHR_DF_CHANNEL_RGBSDA_BLUE = 2U, + KHR_DF_CHANNEL_RGBSDA_B = 2U, + KHR_DF_CHANNEL_RGBSDA_STENCIL = 13U, + KHR_DF_CHANNEL_RGBSDA_S = 13U, + KHR_DF_CHANNEL_RGBSDA_DEPTH = 14U, + KHR_DF_CHANNEL_RGBSDA_D = 14U, + KHR_DF_CHANNEL_RGBSDA_ALPHA = 15U, + KHR_DF_CHANNEL_RGBSDA_A = 15U, + /* MODEL_YUVSDA - luma, Cb, Cr, stencil, depth, alpha */ + KHR_DF_CHANNEL_YUVSDA_Y = 0U, + KHR_DF_CHANNEL_YUVSDA_CB = 1U, + KHR_DF_CHANNEL_YUVSDA_U = 1U, + KHR_DF_CHANNEL_YUVSDA_CR = 2U, + KHR_DF_CHANNEL_YUVSDA_V = 2U, + KHR_DF_CHANNEL_YUVSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YUVSDA_S = 13U, + KHR_DF_CHANNEL_YUVSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YUVSDA_D = 14U, + KHR_DF_CHANNEL_YUVSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YUVSDA_A = 15U, + /* MODEL_YIQSDA - luma, in-phase, quadrature, stencil, depth, alpha */ + KHR_DF_CHANNEL_YIQSDA_Y = 0U, + KHR_DF_CHANNEL_YIQSDA_I = 1U, + KHR_DF_CHANNEL_YIQSDA_Q = 2U, + KHR_DF_CHANNEL_YIQSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YIQSDA_S = 13U, + KHR_DF_CHANNEL_YIQSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YIQSDA_D = 14U, + KHR_DF_CHANNEL_YIQSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YIQSDA_A = 15U, + /* MODEL_LABSDA - CIELAB/L*a*b* luma, red-green, blue-yellow, stencil, depth, alpha */ + KHR_DF_CHANNEL_LABSDA_L = 0U, + KHR_DF_CHANNEL_LABSDA_A = 1U, + KHR_DF_CHANNEL_LABSDA_B = 2U, + KHR_DF_CHANNEL_LABSDA_STENCIL = 13U, + KHR_DF_CHANNEL_LABSDA_S = 13U, + KHR_DF_CHANNEL_LABSDA_DEPTH = 14U, + KHR_DF_CHANNEL_LABSDA_D = 14U, + KHR_DF_CHANNEL_LABSDA_ALPHA = 15U, + /* NOTE: KHR_DF_CHANNEL_LABSDA_A is not a synonym for alpha! */ + /* MODEL_CMYKA - cyan, magenta, yellow, key/blacK, alpha */ + KHR_DF_CHANNEL_CMYKSDA_CYAN = 0U, + KHR_DF_CHANNEL_CMYKSDA_C = 0U, + KHR_DF_CHANNEL_CMYKSDA_MAGENTA = 1U, + KHR_DF_CHANNEL_CMYKSDA_M = 1U, + KHR_DF_CHANNEL_CMYKSDA_YELLOW = 2U, + KHR_DF_CHANNEL_CMYKSDA_Y = 2U, + KHR_DF_CHANNEL_CMYKSDA_KEY = 3U, + KHR_DF_CHANNEL_CMYKSDA_BLACK = 3U, + KHR_DF_CHANNEL_CMYKSDA_K = 3U, + KHR_DF_CHANNEL_CMYKSDA_ALPHA = 15U, + KHR_DF_CHANNEL_CMYKSDA_A = 15U, + /* MODEL_XYZW - coordinates x, y, z, w */ + KHR_DF_CHANNEL_XYZW_X = 0U, + KHR_DF_CHANNEL_XYZW_Y = 1U, + KHR_DF_CHANNEL_XYZW_Z = 2U, + KHR_DF_CHANNEL_XYZW_W = 3U, + /* MODEL_HSVA_ANG - value (luma), saturation, hue, alpha, angular projection, conical space */ + KHR_DF_CHANNEL_HSVA_ANG_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_ANG_V = 0U, + KHR_DF_CHANNEL_HSVA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_ANG_S = 1U, + KHR_DF_CHANNEL_HSVA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSVA_ANG_H = 2U, + KHR_DF_CHANNEL_HSVA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_ANG_A = 15U, + /* MODEL_HSLA_ANG - lightness (luma), saturation, hue, alpha, angular projection, double conical space */ + KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_ANG_L = 0U, + KHR_DF_CHANNEL_HSLA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_ANG_S = 1U, + KHR_DF_CHANNEL_HSLA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSLA_ANG_H = 2U, + KHR_DF_CHANNEL_HSLA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_ANG_A = 15U, + /* MODEL_HSVA_HEX - value (luma), saturation, hue, alpha, hexagonal projection, conical space */ + KHR_DF_CHANNEL_HSVA_HEX_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_HEX_V = 0U, + KHR_DF_CHANNEL_HSVA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_HEX_S = 1U, + KHR_DF_CHANNEL_HSVA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSVA_HEX_H = 2U, + KHR_DF_CHANNEL_HSVA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_HEX_A = 15U, + /* MODEL_HSLA_HEX - lightness (luma), saturation, hue, alpha, hexagonal projection, double conical space */ + KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_HEX_L = 0U, + KHR_DF_CHANNEL_HSLA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_HEX_S = 1U, + KHR_DF_CHANNEL_HSLA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSLA_HEX_H = 2U, + KHR_DF_CHANNEL_HSLA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_HEX_A = 15U, + /* MODEL_YCGCOA - luma, green delta, orange delta, alpha */ + KHR_DF_CHANNEL_YCGCOA_Y = 0U, + KHR_DF_CHANNEL_YCGCOA_CG = 1U, + KHR_DF_CHANNEL_YCGCOA_CO = 2U, + KHR_DF_CHANNEL_YCGCOA_ALPHA = 15U, + KHR_DF_CHANNEL_YCGCOA_A = 15U, + /* MODEL_CIEXYZ - CIE 1931 X, Y, Z */ + KHR_DF_CHANNEL_CIEXYZ_X = 0U, + KHR_DF_CHANNEL_CIEXYZ_Y = 1U, + KHR_DF_CHANNEL_CIEXYZ_Z = 2U, + /* MODEL_CIEXYY - CIE 1931 x, y, Y */ + KHR_DF_CHANNEL_CIEXYY_X = 0U, + KHR_DF_CHANNEL_CIEXYY_YCHROMA = 1U, + KHR_DF_CHANNEL_CIEXYY_YLUMA = 2U, + + /* Compressed formats */ + /* MODEL_DXT1A/MODEL_BC1A */ + KHR_DF_CHANNEL_DXT1A_COLOR = 0U, + KHR_DF_CHANNEL_BC1A_COLOR = 0U, + KHR_DF_CHANNEL_DXT1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_DXT1A_ALPHA = 1U, + KHR_DF_CHANNEL_BC1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_BC1A_ALPHA = 1U, + /* MODEL_DXT2/3/MODEL_BC2 */ + KHR_DF_CHANNEL_DXT2_COLOR = 0U, + KHR_DF_CHANNEL_DXT3_COLOR = 0U, + KHR_DF_CHANNEL_BC2_COLOR = 0U, + KHR_DF_CHANNEL_DXT2_ALPHA = 15U, + KHR_DF_CHANNEL_DXT3_ALPHA = 15U, + KHR_DF_CHANNEL_BC2_ALPHA = 15U, + /* MODEL_DXT4/5/MODEL_BC3 */ + KHR_DF_CHANNEL_DXT4_COLOR = 0U, + KHR_DF_CHANNEL_DXT5_COLOR = 0U, + KHR_DF_CHANNEL_BC3_COLOR = 0U, + KHR_DF_CHANNEL_DXT4_ALPHA = 15U, + KHR_DF_CHANNEL_DXT5_ALPHA = 15U, + KHR_DF_CHANNEL_BC3_ALPHA = 15U, + /* MODEL_BC4 */ + KHR_DF_CHANNEL_BC4_DATA = 0U, + /* MODEL_BC5 */ + KHR_DF_CHANNEL_BC5_RED = 0U, + KHR_DF_CHANNEL_BC5_R = 0U, + KHR_DF_CHANNEL_BC5_GREEN = 1U, + KHR_DF_CHANNEL_BC5_G = 1U, + /* MODEL_BC6H */ + KHR_DF_CHANNEL_BC6H_COLOR = 0U, + KHR_DF_CHANNEL_BC6H_DATA = 0U, + /* MODEL_BC7 */ + KHR_DF_CHANNEL_BC7_DATA = 0U, + KHR_DF_CHANNEL_BC7_COLOR = 0U, + /* MODEL_ETC1 */ + KHR_DF_CHANNEL_ETC1_DATA = 0U, + KHR_DF_CHANNEL_ETC1_COLOR = 0U, + /* MODEL_ETC2 */ + KHR_DF_CHANNEL_ETC2_RED = 0U, + KHR_DF_CHANNEL_ETC2_R = 0U, + KHR_DF_CHANNEL_ETC2_GREEN = 1U, + KHR_DF_CHANNEL_ETC2_G = 1U, + KHR_DF_CHANNEL_ETC2_COLOR = 2U, + KHR_DF_CHANNEL_ETC2_ALPHA = 15U, + KHR_DF_CHANNEL_ETC2_A = 15U, + /* MODEL_ASTC */ + KHR_DF_CHANNEL_ASTC_DATA = 0U, + /* MODEL_ETC1S */ + KHR_DF_CHANNEL_ETC1S_RGB = 0U, + KHR_DF_CHANNEL_ETC1S_RRR = 3U, + KHR_DF_CHANNEL_ETC1S_GGG = 4U, + KHR_DF_CHANNEL_ETC1S_AAA = 15U, + /* MODEL_PVRTC */ + KHR_DF_CHANNEL_PVRTC_DATA = 0U, + KHR_DF_CHANNEL_PVRTC_COLOR = 0U, + /* MODEL_PVRTC2 */ + KHR_DF_CHANNEL_PVRTC2_DATA = 0U, + KHR_DF_CHANNEL_PVRTC2_COLOR = 0U, + /* MODEL UASTC */ + KHR_DF_CHANNEL_UASTC_DATA = 0U, + KHR_DF_CHANNEL_UASTC_RGB = 0U, + KHR_DF_CHANNEL_UASTC_RGBA = 3U, + KHR_DF_CHANNEL_UASTC_RRR = 4U, + KHR_DF_CHANNEL_UASTC_RRRG = 5U, + KHR_DF_CHANNEL_UASTC_RG = 6U, + + /* Common channel names shared by multiple formats */ + KHR_DF_CHANNEL_COMMON_LUMA = 0U, + KHR_DF_CHANNEL_COMMON_L = 0U, + KHR_DF_CHANNEL_COMMON_STENCIL = 13U, + KHR_DF_CHANNEL_COMMON_S = 13U, + KHR_DF_CHANNEL_COMMON_DEPTH = 14U, + KHR_DF_CHANNEL_COMMON_D = 14U, + KHR_DF_CHANNEL_COMMON_ALPHA = 15U, + KHR_DF_CHANNEL_COMMON_A = 15U +} khr_df_model_channels_e; + +/** @~English + @brief Definition of the primary colors in color coordinates. + This is implicitly responsible for defining the conversion + between RGB an YUV color spaces. + LAB and related absolute color models should use + KHR_DF_PRIMARIES_CIEXYZ. */ +typedef enum _khr_df_primaries_e { + /** No color primaries defined */ + KHR_DF_PRIMARIES_UNSPECIFIED = 0U, + /** Color primaries of ITU-R BT.709 and sRGB */ + KHR_DF_PRIMARIES_BT709 = 1U, + /** Synonym for KHR_DF_PRIMARIES_BT709 */ + KHR_DF_PRIMARIES_SRGB = 1U, + /** Color primaries of ITU-R BT.601 (625-line EBU variant) */ + KHR_DF_PRIMARIES_BT601_EBU = 2U, + /** Color primaries of ITU-R BT.601 (525-line SMPTE C variant) */ + KHR_DF_PRIMARIES_BT601_SMPTE = 3U, + /** Color primaries of ITU-R BT.2020 */ + KHR_DF_PRIMARIES_BT2020 = 4U, + /** CIE theoretical color coordinate space */ + KHR_DF_PRIMARIES_CIEXYZ = 5U, + /** Academy Color Encoding System primaries */ + KHR_DF_PRIMARIES_ACES = 6U, + /** Color primaries of ACEScc */ + KHR_DF_PRIMARIES_ACESCC = 7U, + /** Legacy NTSC 1953 primaries */ + KHR_DF_PRIMARIES_NTSC1953 = 8U, + /** Legacy PAL 525-line primaries */ + KHR_DF_PRIMARIES_PAL525 = 9U, + /** Color primaries of Display P3 */ + KHR_DF_PRIMARIES_DISPLAYP3 = 10U, + /** Color primaries of Adobe RGB (1998) */ + KHR_DF_PRIMARIES_ADOBERGB = 11U, + KHR_DF_PRIMARIES_MAX = 0xFFU +} khr_df_primaries_e; + +/** @~English + @brief Definition of the optical to digital transfer function + ("gamma correction"). Most transfer functions are not a pure + power function and also include a linear element. + LAB and related absolute color representations should use + KHR_DF_TRANSFER_UNSPECIFIED. */ +typedef enum _khr_df_transfer_e { + /** No transfer function defined */ + KHR_DF_TRANSFER_UNSPECIFIED = 0U, + /** Linear transfer function (value proportional to intensity) */ + KHR_DF_TRANSFER_LINEAR = 1U, + /** Perceptually-linear transfer function of sRGH (~2.4) */ + KHR_DF_TRANSFER_SRGB = 2U, + /** Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45) */ + KHR_DF_TRANSFER_ITU = 3U, + /** SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) */ + KHR_DF_TRANSFER_SMTPE170M = 3U, + /** Perceptually-linear gamma function of original NTSC (simple 2.2 gamma) */ + KHR_DF_TRANSFER_NTSC = 4U, + /** Sony S-log used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG = 5U, + /** Sony S-log 2 used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG2 = 6U, + /** ITU BT.1886 EOTF */ + KHR_DF_TRANSFER_BT1886 = 7U, + /** ITU BT.2100 HLG OETF */ + KHR_DF_TRANSFER_HLG_OETF = 8U, + /** ITU BT.2100 HLG EOTF */ + KHR_DF_TRANSFER_HLG_EOTF = 9U, + /** ITU BT.2100 PQ EOTF */ + KHR_DF_TRANSFER_PQ_EOTF = 10U, + /** ITU BT.2100 PQ OETF */ + KHR_DF_TRANSFER_PQ_OETF = 11U, + /** DCI P3 transfer function */ + KHR_DF_TRANSFER_DCIP3 = 12U, + /** Legacy PAL OETF */ + KHR_DF_TRANSFER_PAL_OETF = 13U, + /** Legacy PAL 625-line EOTF */ + KHR_DF_TRANSFER_PAL625_EOTF = 14U, + /** Legacy ST240 transfer function */ + KHR_DF_TRANSFER_ST240 = 15U, + /** ACEScc transfer function */ + KHR_DF_TRANSFER_ACESCC = 16U, + /** ACEScct transfer function */ + KHR_DF_TRANSFER_ACESCCT = 17U, + /** Adobe RGB (1998) transfer function */ + KHR_DF_TRANSFER_ADOBERGB = 18U, + KHR_DF_TRANSFER_MAX = 0xFFU +} khr_df_transfer_e; + +typedef enum _khr_df_flags_e { + KHR_DF_FLAG_ALPHA_STRAIGHT = 0U, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1U +} khr_df_flags_e; + +typedef enum _khr_df_sample_datatype_qualifiers_e { + KHR_DF_SAMPLE_DATATYPE_LINEAR = 1U << 4U, + KHR_DF_SAMPLE_DATATYPE_EXPONENT = 1U << 5U, + KHR_DF_SAMPLE_DATATYPE_SIGNED = 1U << 6U, + KHR_DF_SAMPLE_DATATYPE_FLOAT = 1U << 7U +} khr_df_sample_datatype_qualifiers_e; + +#endif diff --git a/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/Headers/ktx.h b/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/Headers/ktx.h new file mode 100644 index 00000000..fd321c30 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/Headers/ktx.h @@ -0,0 +1,1835 @@ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + +#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1 +#define KTX_H_A55A6F00956F42F3A137C11929827FE1 + +/* + * Copyright 2010-2018 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + * + * See the accompanying LICENSE.md for licensing details for all files in + * the KTX library and KTX loader tests. + */ + +/** + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX API. + * + * @author Mark Callow, Edgewise Consulting and while at HI Corporation + * @author Based on original work by Georg Kolling, Imagination Technology + * + * @snippet{doc} version.h API version + */ + +#include +#include +#include + +#include + +/* + * Don't use khrplatform.h in order not to break apps existing + * before these definitions were needed. + */ +#if defined(KHRONOS_STATIC) + #define KTX_API +#elif defined(_WIN32) || defined(__CYGWIN__) + #if !defined(KTX_API) + #if __GNUC__ + #define KTX_API __attribute__ ((dllimport)) + #elif _MSC_VER + #define KTX_API __declspec(dllimport) + #else + #error "Your compiler's equivalent of dllimport is unknown" + #endif + #endif +#elif defined(__ANDROID__) + #define KTX_API __attribute__((visibility("default"))) +#else + #define KTX_API +#endif + +#if defined(_WIN32) && !defined(KHRONOS_STATIC) + #if !defined(KTX_APIENTRY) + #define KTX_APIENTRY __stdcall + #endif +#else + #define KTX_APIENTRY +#endif + +/* To avoid including define our own types. */ +typedef unsigned char ktx_uint8_t; +typedef bool ktx_bool_t; +#ifdef _MSC_VER +typedef unsigned __int16 ktx_uint16_t; +typedef signed __int16 ktx_int16_t; +typedef unsigned __int32 ktx_uint32_t; +typedef signed __int32 ktx_int32_t; +typedef size_t ktx_size_t; +typedef unsigned __int64 ktx_uint64_t; +typedef signed __int64 ktx_int64_t; +#else +#include +typedef uint16_t ktx_uint16_t; +typedef int16_t ktx_int16_t; +typedef uint32_t ktx_uint32_t; +typedef int32_t ktx_int32_t; +typedef size_t ktx_size_t; +typedef uint64_t ktx_uint64_t; +typedef int64_t ktx_int64_t; +#endif + +/* This will cause compilation to fail if size of uint32 != 4. */ +typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4]; + +/* + * This #if allows libktx to be compiled with strict c99. It avoids + * compiler warnings or even errors when a gl.h is already included. + * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if + * gl.h comes after. However nobody has complained about the unguarded typedefs + * since they were introduced so this is unlikely to be a problem in practice. + * Presumably everybody is using platform default compilers not c99 or else + * they are using C++. + */ +#if !defined(GL_NO_ERROR) + /* + * To avoid having to including gl.h ... + */ + typedef unsigned char GLboolean; + typedef unsigned int GLenum; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLuint; + typedef unsigned char GLubyte; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_ANIMDATA_KEY "KTXanimData" +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +#define KTX_ORIENTATION_KEY "KTXorientation" +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +#define KTX_SWIZZLE_KEY "KTXswizzle" +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_WRITER_KEY "KTXwriter" +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams" +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +#define KTX_ORIENTATION1_FMT "S=%c" +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +#define KTX_ORIENTATION2_FMT "S=%c,T=%c" +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c" +/** + * @~English + * @brief Required unpack alignment + */ +#define KTX_GL_UNPACK_ALIGNMENT 4 + +#define KTX_TRUE true +#define KTX_FALSE false + +/** + * @~English + * @brief Error codes returned by library functions. + */ +typedef enum ktx_error_code_e { + KTX_SUCCESS = 0, /*!< Operation was successful. */ + KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */ + KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */ + KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */ + KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */ + KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */ + KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */ + KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */ + KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */ + KTX_GL_ERROR, /*!< GL operations resulted in an error. */ + KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ + KTX_INVALID_VALUE, /*!< A parameter value was not valid */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ + KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ + KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ + KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ + KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */ + KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */ + KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */ + KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */ + KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */ + KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */ +} ktx_error_code_e; +/** + * @deprecated + * @~English + * @brief For backward compatibility + */ +#define KTX_error_code ktx_error_code_e + +#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } +#define KTX_ENDIAN_REF (0x04030201) +#define KTX_ENDIAN_REF_REV (0x01020304) +#define KTX_HEADER_SIZE (64) + +/** + * @~English + * @brief Result codes returned by library functions. + */ + typedef enum ktx_error_code_e ktxResult; + +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ +typedef struct ktxKVListEntry* ktxHashList; + +typedef struct ktxStream ktxStream; + +#define KTX_APIENTRYP KTX_APIENTRY * +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ +typedef struct ktxKVListEntry ktxHashListEntry; + +typedef enum ktxOrientationX { + KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r' +} ktxOrientationX; + +typedef enum ktxOrientationY { + KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd' +} ktxOrientationY; + +typedef enum ktxOrientationZ { + KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o' +} ktxOrientationZ; + +typedef enum class_id { + ktxTexture1_c = 1, + ktxTexture2_c = 2 +} class_id; + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +struct ktxOrientation { + ktxOrientationX x; /*!< Orientation in X */ + ktxOrientationY y; /*!< Orientation in Y */ + ktxOrientationZ z; /*!< Orientation in Z */ +}; + +#define KTXTEXTURECLASSDEFN \ + class_id classId; \ + struct ktxTexture_vtbl* vtbl; \ + struct ktxTexture_vvtbl* vvtbl; \ + struct ktxTexture_protected* _protected; \ + ktx_bool_t isArray; \ + ktx_bool_t isCubemap; \ + ktx_bool_t isCompressed; \ + ktx_bool_t generateMipmaps; \ + ktx_uint32_t baseWidth; \ + ktx_uint32_t baseHeight; \ + ktx_uint32_t baseDepth; \ + ktx_uint32_t numDimensions; \ + ktx_uint32_t numLevels; \ + ktx_uint32_t numLayers; \ + ktx_uint32_t numFaces; \ + struct ktxOrientation orientation; \ + ktxHashList kvDataHead; \ + ktx_uint32_t kvDataLen; \ + ktx_uint8_t* kvData; \ + ktx_size_t dataSize; \ + ktx_uint8_t* pData; + + +/** + * @class ktxTexture + * @~English + * @brief Base class representing a texture. + * + * ktxTextures should be created only by one of the provided + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture { + KTXTEXTURECLASSDEFN +} ktxTexture; +/** + * @typedef ktxTexture::classId + * @~English + * @brief Identify the class type. + * + * Since there are no public ktxTexture constructors, this can only have + * values of ktxTexture1_c or ktxTexture2_c. + */ +/** + * @typedef ktxTexture::vtbl + * @~English + * @brief Pointer to the class's vtble. + */ +/** + * @typedef ktxTexture::vvtbl + * @~English + * @brief Pointer to the class's vtble for Vulkan functions. + * + * A separate vtble is used so this header does not need to include vulkan.h. + */ +/** + * @typedef ktxTexture::_protected + * @~English + * @brief Opaque pointer to the class's protected variables. + */ +/** + * @typedef ktxTexture::isArray + * @~English + * + * KTX_TRUE if the texture is an array texture, i.e, + * a GL_TEXTURE_*_ARRAY target is to be used. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture is a cubemap or cubemap array. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture's format is a block compressed format. + */ +/** + * @typedef ktxTexture::generateMipmaps + * @~English + * + * KTX_TRUE if mipmaps should be generated for the texture by + * ktxTexture_GLUpload() or ktxTexture_VkUpload(). + */ +/**n + * @typedef ktxTexture::baseWidth + * @~English + * @brief Width of the texture's base level. + */ +/** + * @typedef ktxTexture::baseHeight + * @~English + * @brief Height of the texture's base level. + */ +/** + * @typedef ktxTexture::baseDepth + * @~English + * @brief Depth of the texture's base level. + */ +/** + * @typedef ktxTexture::numDimensions + * @~English + * @brief Number of dimensions in the texture: 1, 2 or 3. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of mip levels in the texture. + * + * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a + * full pyramid but always starts at the base level. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of array layers in the texture. + */ +/** + * @typedef ktxTexture::numFaces + * @~English + * @brief Number of faces: 6 for cube maps, 1 otherwise. + */ +/** + * @typedef ktxTexture::orientation + * @~English + * @brief Describes the logical orientation of the images in each dimension. + * + * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z. + */ +/** + * @typedef ktxTexture::kvDataHead + * @~English + * @brief Head of the hash list of metadata. + */ +/** + * @typedef ktxTexture::kvDataLen + * @~English + * @brief Length of the metadata, if it has been extracted in its raw form, + * otherwise 0. + */ +/** + * @typedef ktxTexture::kvData + * @~English + * @brief Pointer to the metadata, if it has been extracted in its raw form, + * otherwise NULL. + */ +/** + * @typedef ktxTexture::dataSize + * @~English + * @brief Byte length of the texture's uncompressed image data. + */ +/** + * @typedef ktxTexture::pData + * @~English + * @brief Pointer to the start of the image data. + */ + +/** + * @memberof ktxTexture + * @~English + * @brief Signature of function called by the ktxTexture_Iterate* + * functions to receive image data. + * + * The function parameters are used to pass values which change for each image. + * Obtain values which are uniform across all images from the @c ktxTexture + * object. + * + * @param [in] miplevel MIP level from 0 to the max level which is + * dependent on the texture size. + * @param [in] face usually 0; for cube maps, one of the 6 cube + * faces in the order +X, -X, +Y, -Y, +Z, -Z, + * 0 to 5. + * @param [in] width width of the image. + * @param [in] height height of the image or, for 1D textures + * textures, 1. + * @param [in] depth depth of the image or, for 1D & 2D + * textures, 1. + * @param [in] faceLodSize number of bytes of data pointed at by + * @p pixels. + * @param [in] pixels pointer to the image data. + * @param [in,out] userdata pointer for the application to pass data to and + * from the callback function. + */ + +typedef KTX_error_code + (* PFNKTXITERCB)(int miplevel, int face, + int width, int height, int depth, + ktx_uint64_t faceLodSize, + void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + ktx_size_t* pOffset); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This, + PFNKTXITERCB iterCb, + void* userdata); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This, + ktx_uint8_t* pBuffer, + ktx_size_t bufSize); +typedef ktx_bool_t + (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + const ktx_uint8_t* src, + ktx_size_t srcSize); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + FILE* src, ktx_size_t srcSize); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This, + const char* const dstname); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, + ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + struct ktxTexture_vtbl { + PFNKTEXDESTROY Destroy; + PFNKTEXGETIMAGEOFFSET GetImageOffset; + PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + PFNKTEXGETIMAGESIZE GetImageSize; + PFNKTEXITERATELEVELS IterateLevels; + PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + PFNKTEXLOADIMAGEDATA LoadImageData; + PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; +}; + +/**************************************************************** + * Macros to give some backward compatibility to the previous API + ****************************************************************/ + +/** + * @~English + * @brief Helper for calling the Destroy virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_Destroy + */ +#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This) + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \ + (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset) + +/** + * @~English + * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture. + * + * For a ktxTexture1 this will always return the value of This->dataSize. + * + * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed + */ +#define ktxTexture_GetDataSizeUncompressed(This) \ + (This)->vtbl->GetDataSizeUncompressed(This) + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +#define ktxTexture_GetImageSize(This, level) \ + (This)->vtbl->GetImageSize(This, level) + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +#define ktxTexture_IterateLevels(This, iterCb, userdata) \ + (This)->vtbl->IterateLevels(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \ + (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \ + (This)->vtbl->LoadImageData(This, pBuffer, bufSize) + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This) + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize) + +/** + * @~English + * @brief Helper for calling the SetImageFromStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream + */ +#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) + +/** + * @~English + * @brief Helper for calling the WriteToStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream + */ +#define ktxTexture_WriteToStdioStream(This, dstsstr) \ + (This)->vtbl->WriteToStdioStream(This, dstsstr) + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +#define ktxTexture_WriteToNamedFile(This, dstname) \ + (This)->vtbl->WriteToNamedFile(This, dstname) + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ + (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + + +/** + * @class ktxTexture1 + * @~English + * @brief Class representing a KTX version 1 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture1 { + KTXTEXTURECLASSDEFN + ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + struct ktxTexture1_private* _private; /*!< Private data. */ +} ktxTexture1; + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +typedef enum ktxSupercmpScheme { + KTX_SS_NONE = 0, /*!< No supercompression. */ + KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */ + KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */ + KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */ + KTX_SS_BEGIN_RANGE = KTX_SS_NONE, + KTX_SS_END_RANGE = KTX_SS_ZLIB, + KTX_SS_BEGIN_VENDOR_RANGE = 0x10000, + KTX_SS_END_VENDOR_RANGE = 0x1ffff, + KTX_SS_BEGIN_RESERVED = 0x20000, + KTX_SUPERCOMPRESSION_BASIS = KTX_SS_BASIS_LZ, + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_BASIS_LZ instead. */ + KTX_SUPERCOMPRESSION_ZSTD = KTX_SS_ZSTD + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_ZSTD instead. */ +} ktxSupercmpScheme; + +/** + * @class ktxTexture2 + * @~English + * @brief Class representing a KTX version 2 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture2 { + KTXTEXTURECLASSDEFN + ktx_uint32_t vkFormat; + ktx_uint32_t* pDfd; + ktxSupercmpScheme supercompressionScheme; + ktx_bool_t isVideo; + ktx_uint32_t duration; + ktx_uint32_t timescale; + ktx_uint32_t loopcount; + struct ktxTexture2_private* _private; /*!< Private data. */ +} ktxTexture2; + +#define ktxTexture(t) ((ktxTexture*)t) + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1_Create() and + * ktxTexture2_Create(). + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef struct +{ + ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an + array texture. Means OpenGL will use a + GL_TEXTURE_*_ARRAY target. */ + ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} ktxTextureCreateInfo; + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef enum { + KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */ + KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */ +} ktxTextureCreateStorageEnum; + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +enum ktxTextureCreateFlagBits { + KTX_TEXTURE_CREATE_NO_FLAGS = 0x00, + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01, + /*!< Load the images from the KTX source. */ + KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08 + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +}; +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +typedef ktx_uint32_t ktxTextureCreateFlags; + +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + ktxStream_write write; /*!< pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< destruct the stream. */ + + enum streamType type; + union { + FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + struct + { + void* address; /**< pointer to the data. */ + void* allocatorAddress; /**< pointer to a memory allocator. */ + ktx_size_t size; /**< size of the data. */ + } custom_ptr; /**< pointer to a struct for custom streams. */ + } data; /**< pointer to the stream data. */ + ktx_off_t readpos; /**< used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +}; + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ +KTX_API ktx_uint8_t* KTX_APIENTRY +ktxTexture_GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ +KTX_API ktx_size_t KTX_APIENTRY +ktxTexture_GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, + GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); +/* + * Create a new ktxTexture1. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture1_NeedsTranscoding(ktxTexture1* This); + +/* + * Write a ktxTexture object to a stdio stream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + +/* + * Write a ktxTexture object to a named file in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname); + +/* + * Write a ktxTexture object to a block of memory in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, + ktx_uint8_t** bytes, ktx_size_t* size); + +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + +/* + * Create a new ktxTexture2. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + +KTX_API void KTX_APIENTRY +ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, + ktx_uint32_t* componentByteLength); + +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetNumComponents(ktxTexture2* This); + +KTX_API khr_df_transfer_e KTX_APIENTRY +ktxTexture2_GetOETF_e(ktxTexture2* This); + +// For backward compatibility +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetOETF(ktxTexture2* This); + +KTX_API khr_df_model_e KTX_APIENTRY +ktxTexture2_GetColorModel_e(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_NeedsTranscoding(ktxTexture2* This); + +/** + * @~English + * @brief Flags specifiying UASTC encoding options. + */ +typedef enum ktx_pack_uastc_flag_bits_e { + KTX_PACK_UASTC_LEVEL_FASTEST = 0, + /*!< Fastest compression. 43.45dB. */ + KTX_PACK_UASTC_LEVEL_FASTER = 1, + /*!< Faster compression. 46.49dB. */ + KTX_PACK_UASTC_LEVEL_DEFAULT = 2, + /*!< Default compression. 47.47dB. */ + KTX_PACK_UASTC_LEVEL_SLOWER = 3, + /*!< Slower compression. 48.01dB. */ + KTX_PACK_UASTC_LEVEL_VERYSLOW = 4, + /*!< Very slow compression. 48.24dB. */ + KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW, + /*!< Maximum supported quality level. */ + KTX_PACK_UASTC_LEVEL_MASK = 0xF, + /*!< Mask to extract the level from the other bits. */ + KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8, + /*!< Optimize for lowest UASTC error. */ + KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16, + /*!< Optimize for lowest BC7 error. */ + KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64, + /*!< Optimize for faster transcoding to ETC1. */ + KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128, + /*!< Optimize for fastest transcoding to ETC1. */ + KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256 + /*!< Not documented in BasisU code. */ +} ktx_pack_uastc_flag_bits_e; +typedef ktx_uint32_t ktx_pack_uastc_flags; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +typedef enum ktx_pack_astc_quality_levels_e { + KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0, + /*!< Fastest compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10, + /*!< Fast compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60, + /*!< Medium compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98, + /*!< Slower compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100, + /*!< Very slow compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE, + /*!< Maximum supported quality level. */ +} ktx_pack_astc_quality_levels_e; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +typedef enum ktx_pack_astc_block_dimension_e { + // 2D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp + // 3D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6 + /*!< Maximum supported blocks. */ +} ktx_pack_astc_block_dimension_e; + +/** + * @~English + * @brief Options specifying ASTC encoder profile mode + * This and function is used later to derive the profile. + */ +typedef enum ktx_pack_astc_encoder_mode_e { + KTX_PACK_ASTC_ENCODER_MODE_DEFAULT, + KTX_PACK_ASTC_ENCODER_MODE_LDR, + KTX_PACK_ASTC_ENCODER_MODE_HDR, + KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR +} ktx_pack_astc_encoder_mode_e; + +extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture_CompressAstc. + * + * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension + * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to + * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended. + */ +typedef struct ktxAstcParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + ktx_uint32_t qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps + In this mode normals are compressed to X,Y components + Discarding Z component, reader will need to generate Z + component in shaders. + */ + + ktx_bool_t perceptual; + /*!< The codec should optimize for perceptual error, instead of direct + RMS error. This aims to improves perceived image quality, but + typically lowers the measured PSNR score. Perceptual methods are + currently only available for normal maps and RGB color data. + */ + + char inputSwizzle[4]; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} ktxAstcParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + +/** + * @memberof ktxTexture2 + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture2_CompressBasisEx(). + * + * If you only want default values, use ktxTexture2_CompressBasis(). Here, at a minimum you + * must initialize the structure as follows: + * @code + * ktxBasisParams params = {0}; + * params.structSize = sizeof(params); + * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e compressionLevel has to be explicitly set because 0 is a valid @e compressionLevel + * but is not the default used by the BasisU encoder when no value is set. Only the other + * settings that are to be non-default must be non-zero. + */ +typedef struct ktxBasisParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + ktx_bool_t uastc; + /*!< True to use UASTC base, false to use ETC1S base. */ + ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + ktx_uint32_t compressionLevel; + /*!< Encoding speed vs. quality tradeoff. Range is [0,5]. Higher values + are slower, but give higher quality. There is no default. Callers + must explicitly set this value. Callers can use + KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL as a default value. + Currently this is 2. + */ + ktx_uint32_t qualityLevel; + /*!< Compression quality. Range is [1,255]. Lower gives better + compression/lower quality/faster. Higher gives less compression + /higher quality/slower. This automatically determines values for + @c maxEndpoints, @c maxSelectors, + @c endpointRDOThreshold and @c selectorRDOThreshold + for the target quality level. Setting these parameters overrides + the values determined by @c qualityLevel which defaults to + 128 if neither it nor both of @c maxEndpoints and + @c maxSelectors have been set. + @note @e Both of @c maxEndpoints and @c maxSelectors + must be set for them to have any effect. + @note qualityLevel will only determine values for + @c endpointRDOThreshold and @c selectorRDOThreshold + when its value exceeds 128, otherwise their defaults will be used. + */ + ktx_uint32_t maxEndpoints; + /*!< Manually set the max number of color endpoint clusters. + Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors + must also be set, otherwise the value will be ignored. + */ + float endpointRDOThreshold; + /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is + higher quality but less quality per output bit (try [1.0,3.0]. + This will override the value chosen by @c qualityLevel. + */ + ktx_uint32_t maxSelectors; + /*!< Manually set the max number of color selector clusters. Range + is [1,16128]. Default is 0, unset. If this is set, maxEndpoints + must also be set, otherwise the value will be ignored. + */ + float selectorRDOThreshold; + /*!< Set selector RDO quality threshold. The default is 1.5. Lower is + higher quality but less quality per output bit (try [1.0,3.0]). + This will override the value chosen by @c qualityLevel. + */ + char inputSwizzle[4]; + /*!< A swizzle to apply before encoding. It must match the regular + expression /^[rgba01]{4}$/. If both this and preSwizzle + are specified ktxTexture_CompressBasisEx will raise + KTX_INVALID_OPERATION. + */ + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps (no + selector RDO, no endpoint RDO) and sets the texture's DFD appropriately. + Only valid for linear textures. + */ + ktx_bool_t separateRGToRGB_A; + /*!< @deprecated. This was and is a no-op. 2-component inputs have always been + automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode. + */ + ktx_bool_t preSwizzle; + /*!< If the texture has @c KTXswizzle metadata, apply it before + compressing. Swizzling, like @c rabb may yield drastically + different error metrics if done after supercompression. + */ + ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + ktx_bool_t noSelectorRDO; + /*!< Disable selector rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + + /* UASTC params */ + + ktx_pack_uastc_flags uastcFlags; + /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC + encoding. The most important value is the level given in the + least-significant 4 bits which selects a speed vs quality tradeoff + as shown in the following table: + + Level/Speed | Quality + :-----: | :-------: + KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB + KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB + KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB + KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB + KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB + */ + ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + float uastcRDOQualityScalar; + /*!< UASTC RDO quality scalar (lambda). Lower values yield higher + quality/larger LZ compressed files, higher values yield lower + quality/smaller LZ compressed files. A good range to try is [.2,4]. + Full range is [.001,50.0]. Default is 1.0. + */ + ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + float uastcRDOMaxSmoothBlockErrorScale; + /*!< UASTC RDO max smooth block error scale. Range is [1,300]. + Default is 10.0, 1.0 is disabled. Larger values suppress more + artifacts (and allocate more bits) on smooth blocks. + */ + float uastcRDOMaxSmoothBlockStdDev; + /*!< UASTC RDO max smooth block standard deviation. Range is + [.01,65536.0]. Default is 18.0. Larger values expand the range of + blocks considered smooth. + */ + ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + +} ktxBasisParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params); + +/** + * @~English + * @brief Enumerators for specifying the transcode target format. + * + * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate + * RGB images, a.k.a slices within the BasisU compressed data. For UASTC + * format they refer to the RGB and the alpha components of the UASTC data. If + * the original image had only 2 components, R will be in the opaque portion + * and G in the alpha portion. The R value will be replicated in the RGB + * components. In the case of BasisU the G value will be replicated in all 3 + * components of the alpha slice. If the original image had only 1 component + * it's value is replicated in all 3 components of the opaque portion and + * there is no alpha. + * + * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R, + * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565, + * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor + * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader + * will not produce correct results if any texture filtering is being used. + */ +typedef enum ktx_transcode_fmt_e { + // Compressed formats + + // ETC1-2 + KTX_TTF_ETC1_RGB = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_RGBA = 1, + /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + + // BC1-5, BC7 (desktop, some mobile devices) + KTX_TTF_BC1_RGB = 2, + /*!< Opaque only, no punchthrough alpha support yet. Returns RGB + or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS + flag is specified. */ + KTX_TTF_BC3_RGBA = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + KTX_TTF_BC4_R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_BC5_RG = 5, + /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should + have an alpha channel (if not G will be all 255's. For tangent + space normal maps. */ + KTX_TTF_BC7_RGBA = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + KTX_TTF_PVRTC1_4_RGB = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_PVRTC1_4_RGBA = 9, + /*!< Opaque+alpha. Most useful for simple opacity maps. If the + texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB + will be used instead. Lowest quality of any supported + texture format. */ + + // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day) + KTX_TTF_ASTC_4x4_RGBA = 10, + /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for + textures without an alpha channel. The transcoder uses + RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and + [0,255]) endpoint precisions. */ + + // ATC and FXT1 formats are not supported by KTX2 as there + // are no equivalent VkFormats. + + KTX_TTF_PVRTC2_4_RGB = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + KTX_TTF_PVRTC2_4_RGBA = 19, + /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB. + Premultiplied alpha is highly recommended, otherwise the + color channel can leak into the alpha channel on transparent + blocks. */ + + KTX_TTF_ETC2_EAC_R11 = 20, + /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_EAC_RG11 = 21, + /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The + texture should have an alpha channel (if not G will be all + 255's. For tangent space normal maps. */ + + // Uncompressed (raw pixel) formats + KTX_TTF_RGBA32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + KTX_TTF_RGB565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + KTX_TTF_BGR565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + KTX_TTF_RGBA4444 = 16, + /*!< 16bpp RGBA image stored in raster (not block) order in memory, + R at bit position 12, A at bit position 0. */ + + // Values for automatic selection of RGB or RGBA depending if alpha + // present. + KTX_TTF_ETC = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + KTX_TTF_BC1_OR_3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + KTX_TTF_NOSELECTION = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + KTX_TF_ETC1 = KTX_TTF_ETC1_RGB, + //!< @deprecated. Use #KTX_TTF_ETC1_RGB. + KTX_TF_ETC2 = KTX_TTF_ETC, + //!< @deprecated. Use #KTX_TTF_ETC. + KTX_TF_BC1 = KTX_TTF_BC1_RGB, + //!< @deprecated. Use #KTX_TTF_BC1_RGB. + KTX_TF_BC3 = KTX_TTF_BC3_RGBA, + //!< @deprecated. Use #KTX_TTF_BC3_RGBA. + KTX_TF_BC4 = KTX_TTF_BC4_R, + //!< @deprecated. Use #KTX_TTF_BC4_R. + KTX_TF_BC5 = KTX_TTF_BC5_RG, + //!< @deprecated. Use #KTX_TTF_BC5_RG. + KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA + KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB + //!< @deprecated. Use #KTX_TTF_PVRTC1_4_RGB. +} ktx_transcode_fmt_e; + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +typedef enum ktx_transcode_flag_bits_e { + KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2, + /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger + power of 2 (not implemented yet, but we're going to support it). + Ignored if the slice's dimensions are already a power of 2. + */ + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4, + /*!< When decoding to an opaque texture format, if the Basis data has + alpha, decode the alpha slice instead of the color slice to the + output texture format. Has no effect if there is no alpha data. + */ + KTX_TF_HIGH_QUALITY = 32, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} ktx_transcode_flag_bits_e; +typedef ktx_uint32_t ktx_transcode_flags; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, + ktx_transcode_flags transcodeFlags); + +/* + * Returns a string corresponding to a KTX error code. + */ +KTX_API const char* KTX_APIENTRY +ktxErrorString(KTX_error_code error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ +KTX_API const char* KTX_APIENTRY +ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ +KTX_API const char* KTX_APIENTRY +ktxTranscodeFormatString(ktx_transcode_fmt_e format); + +KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl); +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl); +KTX_API void KTX_APIENTRY +ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head); +KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_AddKVPair(ktxHashList* pHead, const char* key, + unsigned int valueLen, const void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindEntry(ktxHashList* pHead, const char* key, + ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindValue(ktxHashList* pHead, const char* key, + unsigned int* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ +KTX_API ktxHashListEntry* KTX_APIENTRY +ktxHashList_Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Serialize(ktxHashList* pHead, + unsigned int* kvdLen, unsigned char** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd); + +/* + * Get the key from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetKey(ktxHashListEntry* This, + unsigned int* pKeyLen, char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetValue(ktxHashListEntry* This, + unsigned int* pValueLen, void** ppValue); + +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX2 file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); + +#ifdef __cplusplus +} +#endif + +/*========================================================================* + * For backward compatibilty with the V3 & early versions of the V4 APIs. * + *========================================================================*/ + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_transcode_fmt_e ktx_transcode_fmt_e + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_decode_flags ktx_transcode_flag_bits + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktxTexture_GetSize ktxTexture_GetDatasize + +/** +@~English +@page libktx_history Revision History + +No longer updated. Kept to preserve ancient history. For more recent history see the repo log at +https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo. + +@section v8 Version 4.0 +Added: +@li Support for KTX Version 2. +@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files. +@li Function to print info about a KTX file. + +@section v7 Version 3.0.1 +Fixed: +@li GitHub issue #159: compile failure with recent Vulkan SDKs. +@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents. +@li Incorrect BC4 blocksize. +@li Missing mapping of PVRTC formats from GL to Vulkan. +@li Incorrect block width and height calculations for sizes that are not + a multiple of the block size. +@li Incorrect KTXorientation key in test images. + +@section v6 Version 3.0 +Added: +@li new ktxTexture object based API for reading KTX files without an OpenGL context. +@li Vulkan loader. @#include to use it. + +Changed: +@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h. + Applications using OpenGL must now include these files themselves. +@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures + when the OpenGL context does not support 1D textures. + KTX_UNSUPPORTED_TEXTURE_TYPE is now returned. + +@section v5 Version 2.0.2 +Added: +@li Support for cubemap arrays. + +Changed: +@li New build system + +Fixed: +@li GitHub issue #40: failure to byte-swap key-value lengths. +@li GitHub issue #33: returning incorrect target when loading cubemaps. +@li GitHub PR #42: loading of texture arrays. +@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined. +@li GitHub issue #39: stack-buffer-overflow in toktx +@li Don't use GL_EXTENSIONS on recent OpenGL versions. + +@section v4 Version 2.0.1 +Added: +@li CMake build files. Thanks to Pavel Rotjberg for the initial version. + +Changed: +@li ktxWriteKTXF to check the validity of the type & format combinations + passed to it. + +Fixed: +@li Public Bugzilla 999: 16-bit luminance texture cannot be written. +@li compile warnings from compilers stricter than MS Visual C++. Thanks to + Pavel Rotjberg. + +@section v3 Version 2.0 +Added: +@li support for decoding ETC2 and EAC formats in the absence of a hardware + decoder. +@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA, + etc. formats to the equivalent R, RG, etc. format with an + appropriate swizzle, when loading in OpenGL Core Profile contexts. +@li ktxErrorString function to return a string corresponding to an error code. +@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3. + The latter includes an EGL on WGL wrapper that makes porting apps between + OpenGL ES and OpenGL easier on Windows. +@li more texture formats to ktxLoadTexture[FN] and toktx tests. + +Changed: +@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at + run time and load textures, or not, according to those capabilities. + +Fixed: +@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX + format. +@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write + more than 1 byte of face-LOD padding. + +Although there is only a very minor API change, the addition of ktxErrorString, +the functional changes are large enough to justify bumping the major revision +number. + +@section v2 Version 1.0.1 +Implemented ktxLoadTextureM. +Fixed the following: +@li Public Bugzilla 571: crash when null passed for pIsMipmapped. +@li Public Bugzilla 572: memory leak when unpacking ETC textures. +@li Public Bugzilla 573: potential crash when unpacking ETC textures with unused padding pixels. +@li Public Bugzilla 576: various small fixes. + +Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes. + +@section v1 Version 1.0 +Initial release. + +*/ + +#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ diff --git a/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/libktx.a b/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/libktx.a new file mode 100644 index 00000000..d26a7f94 Binary files /dev/null and b/KTXLoader/libktx/ktx.xcframework/ios-arm64_x86_64-simulator/libktx.a differ diff --git a/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/Headers/KHR/khr_df.h b/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/Headers/KHR/khr_df.h new file mode 100644 index 00000000..c0d03aa7 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/Headers/KHR/khr_df.h @@ -0,0 +1,630 @@ +/* The Khronos Data Format Specification (version 1.3) */ +/* +** Copyright 2015-2020 The Khronos Group Inc. +** SPDX-License-Identifier: Apache-2.0 +*/ + +/* This header defines a structure that can describe the layout of image + formats in memory. This means that the data format is transparent to + the application, and the expectation is that this should be used when + the layout is defined external to the API. Many Khronos APIs deliberately + keep the internal layout of images opaque, to allow proprietary layouts + and optimisations. This structure is not appropriate for describing + opaque layouts. */ + +/* We stick to standard C89 constructs for simplicity and portability. */ + +#ifndef _KHR_DATA_FORMAT_H_ +#define _KHR_DATA_FORMAT_H_ + +/** @file khr_df.h + + @brief Data Format enums and macros. +*/ + +/* Accessors */ +typedef enum _khr_word_e { + KHR_DF_WORD_VENDORID = 0U, + KHR_DF_WORD_DESCRIPTORTYPE = 0U, + KHR_DF_WORD_VERSIONNUMBER = 1U, + KHR_DF_WORD_DESCRIPTORBLOCKSIZE = 1U, + KHR_DF_WORD_MODEL = 2U, + KHR_DF_WORD_PRIMARIES = 2U, + KHR_DF_WORD_TRANSFER = 2U, + KHR_DF_WORD_FLAGS = 2U, + KHR_DF_WORD_TEXELBLOCKDIMENSION0 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION1 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION2 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION3 = 3U, + KHR_DF_WORD_BYTESPLANE0 = 4U, + KHR_DF_WORD_BYTESPLANE1 = 4U, + KHR_DF_WORD_BYTESPLANE2 = 4U, + KHR_DF_WORD_BYTESPLANE3 = 4U, + KHR_DF_WORD_BYTESPLANE4 = 5U, + KHR_DF_WORD_BYTESPLANE5 = 5U, + KHR_DF_WORD_BYTESPLANE6 = 5U, + KHR_DF_WORD_BYTESPLANE7 = 5U, + KHR_DF_WORD_SAMPLESTART = 6U, + KHR_DF_WORD_SAMPLEWORDS = 4U +} khr_df_word_e; + +typedef enum _khr_df_shift_e { + KHR_DF_SHIFT_VENDORID = 0U, + KHR_DF_SHIFT_DESCRIPTORTYPE = 17U, + KHR_DF_SHIFT_VERSIONNUMBER = 0U, + KHR_DF_SHIFT_DESCRIPTORBLOCKSIZE = 16U, + KHR_DF_SHIFT_MODEL = 0U, + KHR_DF_SHIFT_PRIMARIES = 8U, + KHR_DF_SHIFT_TRANSFER = 16U, + KHR_DF_SHIFT_FLAGS = 24U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION0 = 0U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION1 = 8U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION2 = 16U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION3 = 24U, + KHR_DF_SHIFT_BYTESPLANE0 = 0U, + KHR_DF_SHIFT_BYTESPLANE1 = 8U, + KHR_DF_SHIFT_BYTESPLANE2 = 16U, + KHR_DF_SHIFT_BYTESPLANE3 = 24U, + KHR_DF_SHIFT_BYTESPLANE4 = 0U, + KHR_DF_SHIFT_BYTESPLANE5 = 8U, + KHR_DF_SHIFT_BYTESPLANE6 = 16U, + KHR_DF_SHIFT_BYTESPLANE7 = 24U +} khr_df_shift_e; + +typedef enum _khr_df_mask_e { + KHR_DF_MASK_VENDORID = 0x1FFFFU, + KHR_DF_MASK_DESCRIPTORTYPE = 0x7FFFU, + KHR_DF_MASK_VERSIONNUMBER = 0xFFFFU, + KHR_DF_MASK_DESCRIPTORBLOCKSIZE = 0xFFFFU, + KHR_DF_MASK_MODEL = 0xFFU, + KHR_DF_MASK_PRIMARIES = 0xFFU, + KHR_DF_MASK_TRANSFER = 0xFFU, + KHR_DF_MASK_FLAGS = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION0 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION1 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION2 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE0 = 0xFFU, + KHR_DF_MASK_BYTESPLANE1 = 0xFFU, + KHR_DF_MASK_BYTESPLANE2 = 0xFFU, + KHR_DF_MASK_BYTESPLANE3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE4 = 0xFFU, + KHR_DF_MASK_BYTESPLANE5 = 0xFFU, + KHR_DF_MASK_BYTESPLANE6 = 0xFFU, + KHR_DF_MASK_BYTESPLANE7 = 0xFFU +} khr_df_mask_e; + +/* Helper macro: + Extract field X from basic descriptor block BDB */ +#define KHR_DFDVAL(BDB, X) \ + (((BDB)[KHR_DF_WORD_ ## X] >> (KHR_DF_SHIFT_ ## X)) \ + & (KHR_DF_MASK_ ## X)) + +/* Helper macro: + Set field X of basic descriptor block BDB */ +#define KHR_DFDSETVAL(BDB, X, val) \ + ((BDB)[KHR_DF_WORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_ ## X] & \ + ~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \ + (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X))) + +/* Offsets relative to the start of a sample */ +typedef enum _khr_df_sampleword_e { + KHR_DF_SAMPLEWORD_BITOFFSET = 0U, + KHR_DF_SAMPLEWORD_BITLENGTH = 0U, + KHR_DF_SAMPLEWORD_CHANNELID = 0U, + KHR_DF_SAMPLEWORD_QUALIFIERS = 0U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION0 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION1 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION2 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION3 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL = 1U, + KHR_DF_SAMPLEWORD_SAMPLELOWER = 2U, + KHR_DF_SAMPLEWORD_SAMPLEUPPER = 3U +} khr_df_sampleword_e; + +typedef enum _khr_df_sampleshift_e { + KHR_DF_SAMPLESHIFT_BITOFFSET = 0U, + KHR_DF_SAMPLESHIFT_BITLENGTH = 16U, + KHR_DF_SAMPLESHIFT_CHANNELID = 24U, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLESHIFT_QUALIFIERS = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION0 = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION1 = 8U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION2 = 16U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION3 = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION_ALL = 0U, + KHR_DF_SAMPLESHIFT_SAMPLELOWER = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEUPPER = 0U +} khr_df_sampleshift_e; + +typedef enum _khr_df_samplemask_e { + KHR_DF_SAMPLEMASK_BITOFFSET = 0xFFFFU, + KHR_DF_SAMPLEMASK_BITLENGTH = 0xFF, + KHR_DF_SAMPLEMASK_CHANNELID = 0xF, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLEMASK_QUALIFIERS = 0xF0, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION0 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION1 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION2 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION3 = 0xFF, + /* ISO C restricts enum values to range of int hence the + cast. We do it verbosely instead of using -1 to ensure + it is a 32-bit value even if int is 64 bits. */ + KHR_DF_SAMPLEMASK_SAMPLEPOSITION_ALL = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLELOWER = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLEUPPER = (int) 0xFFFFFFFFU +} khr_df_samplemask_e; + +/* Helper macro: + Extract field X of sample S from basic descriptor block BDB */ +#define KHR_DFDSVAL(BDB, S, X) \ + (((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] >> (KHR_DF_SAMPLESHIFT_ ## X)) \ + & (KHR_DF_SAMPLEMASK_ ## X)) + +/* Helper macro: + Set field X of sample S of basic descriptor block BDB */ +#define KHR_DFDSETSVAL(BDB, S, X, val) \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] & \ + ~((uint32_t)(KHR_DF_SAMPLEMASK_ ## X) << (KHR_DF_SAMPLESHIFT_ ## X))) | \ + (((val) & (uint32_t)(KHR_DF_SAMPLEMASK_ ## X)) << (KHR_DF_SAMPLESHIFT_ ## X))) + +/* Helper macro: + Number of samples in basic descriptor block BDB */ +#define KHR_DFDSAMPLECOUNT(BDB) \ + (((KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) >> 2) - \ + KHR_DF_WORD_SAMPLESTART) \ + / KHR_DF_WORD_SAMPLEWORDS) + +/* Helper macro: + Size in words of basic descriptor block for S samples */ +#define KHR_DFDSIZEWORDS(S) \ + (KHR_DF_WORD_SAMPLESTART + \ + (S) * KHR_DF_WORD_SAMPLEWORDS) + +/* Vendor ids */ +typedef enum _khr_df_vendorid_e { + /* Standard Khronos descriptor */ + KHR_DF_VENDORID_KHRONOS = 0U, + KHR_DF_VENDORID_MAX = 0x1FFFFU +} khr_df_vendorid_e; + +/* Descriptor types */ +typedef enum _khr_df_khr_descriptortype_e { + /* Default Khronos basic descriptor block */ + KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0U, + /* Extension descriptor block for additional planes */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_PLANES = 0x6001U, + /* Extension descriptor block for additional dimensions */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_DIMENSIONS = 0x6002U, + /* Bit indicates modifying requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_WRITE_BIT = 0x2000U, + /* Bit indicates processing requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_DECODE_BIT = 0x4000U, + KHR_DF_KHR_DESCRIPTORTYPE_MAX = 0x7FFFU +} khr_df_khr_descriptortype_e; + +/* Descriptor block version */ +typedef enum _khr_df_versionnumber_e { + /* Standard Khronos descriptor */ + KHR_DF_VERSIONNUMBER_1_0 = 0U, /* Version 1.0 of the specification */ + KHR_DF_VERSIONNUMBER_1_1 = 0U, /* Version 1.1 did not bump the version number */ + KHR_DF_VERSIONNUMBER_1_2 = 1U, /* Version 1.2 increased the version number */ + KHR_DF_VERSIONNUMBER_1_3 = 2U, /* Version 1.3 increased the version number */ + KHR_DF_VERSIONNUMBER_LATEST = KHR_DF_VERSIONNUMBER_1_3, + KHR_DF_VERSIONNUMBER_MAX = 0xFFFFU +} khr_df_versionnumber_e; + +/** @~English + @brief Model in which the color coordinate space is defined. + There is no requirement that a color format use all the + channel types that are defined in the color model. */ +typedef enum _khr_df_model_e { + /** No interpretation of color channels defined */ + KHR_DF_MODEL_UNSPECIFIED = 0U, + /** Color primaries (red, green, blue) + alpha, depth and stencil */ + KHR_DF_MODEL_RGBSDA = 1U, + /** Color differences (Y', Cb, Cr) + alpha, depth and stencil */ + KHR_DF_MODEL_YUVSDA = 2U, + /** Color differences (Y', I, Q) + alpha, depth and stencil */ + KHR_DF_MODEL_YIQSDA = 3U, + /** Perceptual color (CIE L*a*b*) + alpha, depth and stencil */ + KHR_DF_MODEL_LABSDA = 4U, + /** Subtractive colors (cyan, magenta, yellow, black) + alpha */ + KHR_DF_MODEL_CMYKA = 5U, + /** Non-color coordinate data (X, Y, Z, W) */ + KHR_DF_MODEL_XYZW = 6U, + /** Hue, saturation, value, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSVA_ANG = 7U, + /** Hue, saturation, lightness, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSLA_ANG = 8U, + /** Hue, saturation, value, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSVA_HEX = 9U, + /** Hue, saturation, lightness, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSLA_HEX = 10U, + /** Lightweight approximate color difference (luma, orange, green) */ + KHR_DF_MODEL_YCGCOA = 11U, + /** ITU BT.2020 constant luminance YcCbcCrc */ + KHR_DF_MODEL_YCCBCCRC = 12U, + /** ITU BT.2100 constant intensity ICtCp */ + KHR_DF_MODEL_ICTCP = 13U, + /** CIE 1931 XYZ color coordinates (X, Y, Z) */ + KHR_DF_MODEL_CIEXYZ = 14U, + /** CIE 1931 xyY color coordinates (X, Y, Y) */ + KHR_DF_MODEL_CIEXYY = 15U, + + /* Compressed formats start at 128. */ + /* These compressed formats should generally have a single sample, + sited at the 0,0 position of the texel block. Where multiple + channels are used to distinguish formats, these should be cosited. */ + /* Direct3D (and S3) compressed formats */ + /* Note that premultiplied status is recorded separately */ + /** DXT1 "channels" are RGB (0), Alpha (1) + DXT1/BC1 with one channel is opaque + DXT1/BC1 with a cosited alpha sample is transparent */ + KHR_DF_MODEL_DXT1A = 128U, + KHR_DF_MODEL_BC1A = 128U, + /** DXT2/DXT3/BC2, with explicit 4-bit alpha */ + KHR_DF_MODEL_DXT2 = 129U, + KHR_DF_MODEL_DXT3 = 129U, + KHR_DF_MODEL_BC2 = 129U, + /** DXT4/DXT5/BC3, with interpolated alpha */ + KHR_DF_MODEL_DXT4 = 130U, + KHR_DF_MODEL_DXT5 = 130U, + KHR_DF_MODEL_BC3 = 130U, + /** BC4 - single channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC4 = 131U, + /** BC5 - two channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC5 = 132U, + /** BC6H - DX11 format for 16-bit float channels */ + KHR_DF_MODEL_BC6H = 133U, + /** BC7 - DX11 format */ + KHR_DF_MODEL_BC7 = 134U, + /* Gap left for future desktop expansion */ + + /* Mobile compressed formats follow */ + /** A format of ETC1 indicates that the format shall be decodable + by an ETC1-compliant decoder and not rely on ETC2 features */ + KHR_DF_MODEL_ETC1 = 160U, + /** A format of ETC2 is permitted to use ETC2 encodings on top of + the baseline ETC1 specification. + The ETC2 format has channels "red", "green", "RGB" and "alpha", + which should be cosited samples. + Punch-through alpha can be distinguished from full alpha by + the plane size in bytes required for the texel block */ + KHR_DF_MODEL_ETC2 = 161U, + /** Adaptive Scalable Texture Compression */ + /** ASTC HDR vs LDR is determined by the float flag in the channel */ + /** ASTC block size can be distinguished by texel block size */ + KHR_DF_MODEL_ASTC = 162U, + /** ETC1S is a simplified subset of ETC1 */ + KHR_DF_MODEL_ETC1S = 163U, + /** PowerVR Texture Compression v1 */ + KHR_DF_MODEL_PVRTC = 164U, + /** PowerVR Texture Compression v2 */ + KHR_DF_MODEL_PVRTC2 = 165U, + /** UASTC is a transcodable subset of ASTC + with additions to support the transcoding. */ + KHR_DF_MODEL_UASTC = 166U, + /* Proprietary formats (ATITC, etc.) should follow */ + KHR_DF_MODEL_MAX = 0xFFU +} khr_df_model_e; + +/* Definition of channel names for each color model */ +typedef enum _khr_df_model_channels_e { + /* Unspecified format with nominal channel numbering */ + KHR_DF_CHANNEL_UNSPECIFIED_0 = 0U, + KHR_DF_CHANNEL_UNSPECIFIED_1 = 1U, + KHR_DF_CHANNEL_UNSPECIFIED_2 = 2U, + KHR_DF_CHANNEL_UNSPECIFIED_3 = 3U, + KHR_DF_CHANNEL_UNSPECIFIED_4 = 4U, + KHR_DF_CHANNEL_UNSPECIFIED_5 = 5U, + KHR_DF_CHANNEL_UNSPECIFIED_6 = 6U, + KHR_DF_CHANNEL_UNSPECIFIED_7 = 7U, + KHR_DF_CHANNEL_UNSPECIFIED_8 = 8U, + KHR_DF_CHANNEL_UNSPECIFIED_9 = 9U, + KHR_DF_CHANNEL_UNSPECIFIED_10 = 10U, + KHR_DF_CHANNEL_UNSPECIFIED_11 = 11U, + KHR_DF_CHANNEL_UNSPECIFIED_12 = 12U, + KHR_DF_CHANNEL_UNSPECIFIED_13 = 13U, + KHR_DF_CHANNEL_UNSPECIFIED_14 = 14U, + KHR_DF_CHANNEL_UNSPECIFIED_15 = 15U, + /* MODEL_RGBSDA - red, green, blue, stencil, depth, alpha */ + KHR_DF_CHANNEL_RGBSDA_RED = 0U, + KHR_DF_CHANNEL_RGBSDA_R = 0U, + KHR_DF_CHANNEL_RGBSDA_GREEN = 1U, + KHR_DF_CHANNEL_RGBSDA_G = 1U, + KHR_DF_CHANNEL_RGBSDA_BLUE = 2U, + KHR_DF_CHANNEL_RGBSDA_B = 2U, + KHR_DF_CHANNEL_RGBSDA_STENCIL = 13U, + KHR_DF_CHANNEL_RGBSDA_S = 13U, + KHR_DF_CHANNEL_RGBSDA_DEPTH = 14U, + KHR_DF_CHANNEL_RGBSDA_D = 14U, + KHR_DF_CHANNEL_RGBSDA_ALPHA = 15U, + KHR_DF_CHANNEL_RGBSDA_A = 15U, + /* MODEL_YUVSDA - luma, Cb, Cr, stencil, depth, alpha */ + KHR_DF_CHANNEL_YUVSDA_Y = 0U, + KHR_DF_CHANNEL_YUVSDA_CB = 1U, + KHR_DF_CHANNEL_YUVSDA_U = 1U, + KHR_DF_CHANNEL_YUVSDA_CR = 2U, + KHR_DF_CHANNEL_YUVSDA_V = 2U, + KHR_DF_CHANNEL_YUVSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YUVSDA_S = 13U, + KHR_DF_CHANNEL_YUVSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YUVSDA_D = 14U, + KHR_DF_CHANNEL_YUVSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YUVSDA_A = 15U, + /* MODEL_YIQSDA - luma, in-phase, quadrature, stencil, depth, alpha */ + KHR_DF_CHANNEL_YIQSDA_Y = 0U, + KHR_DF_CHANNEL_YIQSDA_I = 1U, + KHR_DF_CHANNEL_YIQSDA_Q = 2U, + KHR_DF_CHANNEL_YIQSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YIQSDA_S = 13U, + KHR_DF_CHANNEL_YIQSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YIQSDA_D = 14U, + KHR_DF_CHANNEL_YIQSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YIQSDA_A = 15U, + /* MODEL_LABSDA - CIELAB/L*a*b* luma, red-green, blue-yellow, stencil, depth, alpha */ + KHR_DF_CHANNEL_LABSDA_L = 0U, + KHR_DF_CHANNEL_LABSDA_A = 1U, + KHR_DF_CHANNEL_LABSDA_B = 2U, + KHR_DF_CHANNEL_LABSDA_STENCIL = 13U, + KHR_DF_CHANNEL_LABSDA_S = 13U, + KHR_DF_CHANNEL_LABSDA_DEPTH = 14U, + KHR_DF_CHANNEL_LABSDA_D = 14U, + KHR_DF_CHANNEL_LABSDA_ALPHA = 15U, + /* NOTE: KHR_DF_CHANNEL_LABSDA_A is not a synonym for alpha! */ + /* MODEL_CMYKA - cyan, magenta, yellow, key/blacK, alpha */ + KHR_DF_CHANNEL_CMYKSDA_CYAN = 0U, + KHR_DF_CHANNEL_CMYKSDA_C = 0U, + KHR_DF_CHANNEL_CMYKSDA_MAGENTA = 1U, + KHR_DF_CHANNEL_CMYKSDA_M = 1U, + KHR_DF_CHANNEL_CMYKSDA_YELLOW = 2U, + KHR_DF_CHANNEL_CMYKSDA_Y = 2U, + KHR_DF_CHANNEL_CMYKSDA_KEY = 3U, + KHR_DF_CHANNEL_CMYKSDA_BLACK = 3U, + KHR_DF_CHANNEL_CMYKSDA_K = 3U, + KHR_DF_CHANNEL_CMYKSDA_ALPHA = 15U, + KHR_DF_CHANNEL_CMYKSDA_A = 15U, + /* MODEL_XYZW - coordinates x, y, z, w */ + KHR_DF_CHANNEL_XYZW_X = 0U, + KHR_DF_CHANNEL_XYZW_Y = 1U, + KHR_DF_CHANNEL_XYZW_Z = 2U, + KHR_DF_CHANNEL_XYZW_W = 3U, + /* MODEL_HSVA_ANG - value (luma), saturation, hue, alpha, angular projection, conical space */ + KHR_DF_CHANNEL_HSVA_ANG_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_ANG_V = 0U, + KHR_DF_CHANNEL_HSVA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_ANG_S = 1U, + KHR_DF_CHANNEL_HSVA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSVA_ANG_H = 2U, + KHR_DF_CHANNEL_HSVA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_ANG_A = 15U, + /* MODEL_HSLA_ANG - lightness (luma), saturation, hue, alpha, angular projection, double conical space */ + KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_ANG_L = 0U, + KHR_DF_CHANNEL_HSLA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_ANG_S = 1U, + KHR_DF_CHANNEL_HSLA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSLA_ANG_H = 2U, + KHR_DF_CHANNEL_HSLA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_ANG_A = 15U, + /* MODEL_HSVA_HEX - value (luma), saturation, hue, alpha, hexagonal projection, conical space */ + KHR_DF_CHANNEL_HSVA_HEX_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_HEX_V = 0U, + KHR_DF_CHANNEL_HSVA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_HEX_S = 1U, + KHR_DF_CHANNEL_HSVA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSVA_HEX_H = 2U, + KHR_DF_CHANNEL_HSVA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_HEX_A = 15U, + /* MODEL_HSLA_HEX - lightness (luma), saturation, hue, alpha, hexagonal projection, double conical space */ + KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_HEX_L = 0U, + KHR_DF_CHANNEL_HSLA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_HEX_S = 1U, + KHR_DF_CHANNEL_HSLA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSLA_HEX_H = 2U, + KHR_DF_CHANNEL_HSLA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_HEX_A = 15U, + /* MODEL_YCGCOA - luma, green delta, orange delta, alpha */ + KHR_DF_CHANNEL_YCGCOA_Y = 0U, + KHR_DF_CHANNEL_YCGCOA_CG = 1U, + KHR_DF_CHANNEL_YCGCOA_CO = 2U, + KHR_DF_CHANNEL_YCGCOA_ALPHA = 15U, + KHR_DF_CHANNEL_YCGCOA_A = 15U, + /* MODEL_CIEXYZ - CIE 1931 X, Y, Z */ + KHR_DF_CHANNEL_CIEXYZ_X = 0U, + KHR_DF_CHANNEL_CIEXYZ_Y = 1U, + KHR_DF_CHANNEL_CIEXYZ_Z = 2U, + /* MODEL_CIEXYY - CIE 1931 x, y, Y */ + KHR_DF_CHANNEL_CIEXYY_X = 0U, + KHR_DF_CHANNEL_CIEXYY_YCHROMA = 1U, + KHR_DF_CHANNEL_CIEXYY_YLUMA = 2U, + + /* Compressed formats */ + /* MODEL_DXT1A/MODEL_BC1A */ + KHR_DF_CHANNEL_DXT1A_COLOR = 0U, + KHR_DF_CHANNEL_BC1A_COLOR = 0U, + KHR_DF_CHANNEL_DXT1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_DXT1A_ALPHA = 1U, + KHR_DF_CHANNEL_BC1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_BC1A_ALPHA = 1U, + /* MODEL_DXT2/3/MODEL_BC2 */ + KHR_DF_CHANNEL_DXT2_COLOR = 0U, + KHR_DF_CHANNEL_DXT3_COLOR = 0U, + KHR_DF_CHANNEL_BC2_COLOR = 0U, + KHR_DF_CHANNEL_DXT2_ALPHA = 15U, + KHR_DF_CHANNEL_DXT3_ALPHA = 15U, + KHR_DF_CHANNEL_BC2_ALPHA = 15U, + /* MODEL_DXT4/5/MODEL_BC3 */ + KHR_DF_CHANNEL_DXT4_COLOR = 0U, + KHR_DF_CHANNEL_DXT5_COLOR = 0U, + KHR_DF_CHANNEL_BC3_COLOR = 0U, + KHR_DF_CHANNEL_DXT4_ALPHA = 15U, + KHR_DF_CHANNEL_DXT5_ALPHA = 15U, + KHR_DF_CHANNEL_BC3_ALPHA = 15U, + /* MODEL_BC4 */ + KHR_DF_CHANNEL_BC4_DATA = 0U, + /* MODEL_BC5 */ + KHR_DF_CHANNEL_BC5_RED = 0U, + KHR_DF_CHANNEL_BC5_R = 0U, + KHR_DF_CHANNEL_BC5_GREEN = 1U, + KHR_DF_CHANNEL_BC5_G = 1U, + /* MODEL_BC6H */ + KHR_DF_CHANNEL_BC6H_COLOR = 0U, + KHR_DF_CHANNEL_BC6H_DATA = 0U, + /* MODEL_BC7 */ + KHR_DF_CHANNEL_BC7_DATA = 0U, + KHR_DF_CHANNEL_BC7_COLOR = 0U, + /* MODEL_ETC1 */ + KHR_DF_CHANNEL_ETC1_DATA = 0U, + KHR_DF_CHANNEL_ETC1_COLOR = 0U, + /* MODEL_ETC2 */ + KHR_DF_CHANNEL_ETC2_RED = 0U, + KHR_DF_CHANNEL_ETC2_R = 0U, + KHR_DF_CHANNEL_ETC2_GREEN = 1U, + KHR_DF_CHANNEL_ETC2_G = 1U, + KHR_DF_CHANNEL_ETC2_COLOR = 2U, + KHR_DF_CHANNEL_ETC2_ALPHA = 15U, + KHR_DF_CHANNEL_ETC2_A = 15U, + /* MODEL_ASTC */ + KHR_DF_CHANNEL_ASTC_DATA = 0U, + /* MODEL_ETC1S */ + KHR_DF_CHANNEL_ETC1S_RGB = 0U, + KHR_DF_CHANNEL_ETC1S_RRR = 3U, + KHR_DF_CHANNEL_ETC1S_GGG = 4U, + KHR_DF_CHANNEL_ETC1S_AAA = 15U, + /* MODEL_PVRTC */ + KHR_DF_CHANNEL_PVRTC_DATA = 0U, + KHR_DF_CHANNEL_PVRTC_COLOR = 0U, + /* MODEL_PVRTC2 */ + KHR_DF_CHANNEL_PVRTC2_DATA = 0U, + KHR_DF_CHANNEL_PVRTC2_COLOR = 0U, + /* MODEL UASTC */ + KHR_DF_CHANNEL_UASTC_DATA = 0U, + KHR_DF_CHANNEL_UASTC_RGB = 0U, + KHR_DF_CHANNEL_UASTC_RGBA = 3U, + KHR_DF_CHANNEL_UASTC_RRR = 4U, + KHR_DF_CHANNEL_UASTC_RRRG = 5U, + KHR_DF_CHANNEL_UASTC_RG = 6U, + + /* Common channel names shared by multiple formats */ + KHR_DF_CHANNEL_COMMON_LUMA = 0U, + KHR_DF_CHANNEL_COMMON_L = 0U, + KHR_DF_CHANNEL_COMMON_STENCIL = 13U, + KHR_DF_CHANNEL_COMMON_S = 13U, + KHR_DF_CHANNEL_COMMON_DEPTH = 14U, + KHR_DF_CHANNEL_COMMON_D = 14U, + KHR_DF_CHANNEL_COMMON_ALPHA = 15U, + KHR_DF_CHANNEL_COMMON_A = 15U +} khr_df_model_channels_e; + +/** @~English + @brief Definition of the primary colors in color coordinates. + This is implicitly responsible for defining the conversion + between RGB an YUV color spaces. + LAB and related absolute color models should use + KHR_DF_PRIMARIES_CIEXYZ. */ +typedef enum _khr_df_primaries_e { + /** No color primaries defined */ + KHR_DF_PRIMARIES_UNSPECIFIED = 0U, + /** Color primaries of ITU-R BT.709 and sRGB */ + KHR_DF_PRIMARIES_BT709 = 1U, + /** Synonym for KHR_DF_PRIMARIES_BT709 */ + KHR_DF_PRIMARIES_SRGB = 1U, + /** Color primaries of ITU-R BT.601 (625-line EBU variant) */ + KHR_DF_PRIMARIES_BT601_EBU = 2U, + /** Color primaries of ITU-R BT.601 (525-line SMPTE C variant) */ + KHR_DF_PRIMARIES_BT601_SMPTE = 3U, + /** Color primaries of ITU-R BT.2020 */ + KHR_DF_PRIMARIES_BT2020 = 4U, + /** CIE theoretical color coordinate space */ + KHR_DF_PRIMARIES_CIEXYZ = 5U, + /** Academy Color Encoding System primaries */ + KHR_DF_PRIMARIES_ACES = 6U, + /** Color primaries of ACEScc */ + KHR_DF_PRIMARIES_ACESCC = 7U, + /** Legacy NTSC 1953 primaries */ + KHR_DF_PRIMARIES_NTSC1953 = 8U, + /** Legacy PAL 525-line primaries */ + KHR_DF_PRIMARIES_PAL525 = 9U, + /** Color primaries of Display P3 */ + KHR_DF_PRIMARIES_DISPLAYP3 = 10U, + /** Color primaries of Adobe RGB (1998) */ + KHR_DF_PRIMARIES_ADOBERGB = 11U, + KHR_DF_PRIMARIES_MAX = 0xFFU +} khr_df_primaries_e; + +/** @~English + @brief Definition of the optical to digital transfer function + ("gamma correction"). Most transfer functions are not a pure + power function and also include a linear element. + LAB and related absolute color representations should use + KHR_DF_TRANSFER_UNSPECIFIED. */ +typedef enum _khr_df_transfer_e { + /** No transfer function defined */ + KHR_DF_TRANSFER_UNSPECIFIED = 0U, + /** Linear transfer function (value proportional to intensity) */ + KHR_DF_TRANSFER_LINEAR = 1U, + /** Perceptually-linear transfer function of sRGH (~2.4) */ + KHR_DF_TRANSFER_SRGB = 2U, + /** Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45) */ + KHR_DF_TRANSFER_ITU = 3U, + /** SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) */ + KHR_DF_TRANSFER_SMTPE170M = 3U, + /** Perceptually-linear gamma function of original NTSC (simple 2.2 gamma) */ + KHR_DF_TRANSFER_NTSC = 4U, + /** Sony S-log used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG = 5U, + /** Sony S-log 2 used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG2 = 6U, + /** ITU BT.1886 EOTF */ + KHR_DF_TRANSFER_BT1886 = 7U, + /** ITU BT.2100 HLG OETF */ + KHR_DF_TRANSFER_HLG_OETF = 8U, + /** ITU BT.2100 HLG EOTF */ + KHR_DF_TRANSFER_HLG_EOTF = 9U, + /** ITU BT.2100 PQ EOTF */ + KHR_DF_TRANSFER_PQ_EOTF = 10U, + /** ITU BT.2100 PQ OETF */ + KHR_DF_TRANSFER_PQ_OETF = 11U, + /** DCI P3 transfer function */ + KHR_DF_TRANSFER_DCIP3 = 12U, + /** Legacy PAL OETF */ + KHR_DF_TRANSFER_PAL_OETF = 13U, + /** Legacy PAL 625-line EOTF */ + KHR_DF_TRANSFER_PAL625_EOTF = 14U, + /** Legacy ST240 transfer function */ + KHR_DF_TRANSFER_ST240 = 15U, + /** ACEScc transfer function */ + KHR_DF_TRANSFER_ACESCC = 16U, + /** ACEScct transfer function */ + KHR_DF_TRANSFER_ACESCCT = 17U, + /** Adobe RGB (1998) transfer function */ + KHR_DF_TRANSFER_ADOBERGB = 18U, + KHR_DF_TRANSFER_MAX = 0xFFU +} khr_df_transfer_e; + +typedef enum _khr_df_flags_e { + KHR_DF_FLAG_ALPHA_STRAIGHT = 0U, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1U +} khr_df_flags_e; + +typedef enum _khr_df_sample_datatype_qualifiers_e { + KHR_DF_SAMPLE_DATATYPE_LINEAR = 1U << 4U, + KHR_DF_SAMPLE_DATATYPE_EXPONENT = 1U << 5U, + KHR_DF_SAMPLE_DATATYPE_SIGNED = 1U << 6U, + KHR_DF_SAMPLE_DATATYPE_FLOAT = 1U << 7U +} khr_df_sample_datatype_qualifiers_e; + +#endif diff --git a/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/Headers/ktx.h b/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/Headers/ktx.h new file mode 100644 index 00000000..fd321c30 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/Headers/ktx.h @@ -0,0 +1,1835 @@ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + +#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1 +#define KTX_H_A55A6F00956F42F3A137C11929827FE1 + +/* + * Copyright 2010-2018 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + * + * See the accompanying LICENSE.md for licensing details for all files in + * the KTX library and KTX loader tests. + */ + +/** + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX API. + * + * @author Mark Callow, Edgewise Consulting and while at HI Corporation + * @author Based on original work by Georg Kolling, Imagination Technology + * + * @snippet{doc} version.h API version + */ + +#include +#include +#include + +#include + +/* + * Don't use khrplatform.h in order not to break apps existing + * before these definitions were needed. + */ +#if defined(KHRONOS_STATIC) + #define KTX_API +#elif defined(_WIN32) || defined(__CYGWIN__) + #if !defined(KTX_API) + #if __GNUC__ + #define KTX_API __attribute__ ((dllimport)) + #elif _MSC_VER + #define KTX_API __declspec(dllimport) + #else + #error "Your compiler's equivalent of dllimport is unknown" + #endif + #endif +#elif defined(__ANDROID__) + #define KTX_API __attribute__((visibility("default"))) +#else + #define KTX_API +#endif + +#if defined(_WIN32) && !defined(KHRONOS_STATIC) + #if !defined(KTX_APIENTRY) + #define KTX_APIENTRY __stdcall + #endif +#else + #define KTX_APIENTRY +#endif + +/* To avoid including define our own types. */ +typedef unsigned char ktx_uint8_t; +typedef bool ktx_bool_t; +#ifdef _MSC_VER +typedef unsigned __int16 ktx_uint16_t; +typedef signed __int16 ktx_int16_t; +typedef unsigned __int32 ktx_uint32_t; +typedef signed __int32 ktx_int32_t; +typedef size_t ktx_size_t; +typedef unsigned __int64 ktx_uint64_t; +typedef signed __int64 ktx_int64_t; +#else +#include +typedef uint16_t ktx_uint16_t; +typedef int16_t ktx_int16_t; +typedef uint32_t ktx_uint32_t; +typedef int32_t ktx_int32_t; +typedef size_t ktx_size_t; +typedef uint64_t ktx_uint64_t; +typedef int64_t ktx_int64_t; +#endif + +/* This will cause compilation to fail if size of uint32 != 4. */ +typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4]; + +/* + * This #if allows libktx to be compiled with strict c99. It avoids + * compiler warnings or even errors when a gl.h is already included. + * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if + * gl.h comes after. However nobody has complained about the unguarded typedefs + * since they were introduced so this is unlikely to be a problem in practice. + * Presumably everybody is using platform default compilers not c99 or else + * they are using C++. + */ +#if !defined(GL_NO_ERROR) + /* + * To avoid having to including gl.h ... + */ + typedef unsigned char GLboolean; + typedef unsigned int GLenum; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLuint; + typedef unsigned char GLubyte; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_ANIMDATA_KEY "KTXanimData" +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +#define KTX_ORIENTATION_KEY "KTXorientation" +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +#define KTX_SWIZZLE_KEY "KTXswizzle" +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_WRITER_KEY "KTXwriter" +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams" +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +#define KTX_ORIENTATION1_FMT "S=%c" +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +#define KTX_ORIENTATION2_FMT "S=%c,T=%c" +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c" +/** + * @~English + * @brief Required unpack alignment + */ +#define KTX_GL_UNPACK_ALIGNMENT 4 + +#define KTX_TRUE true +#define KTX_FALSE false + +/** + * @~English + * @brief Error codes returned by library functions. + */ +typedef enum ktx_error_code_e { + KTX_SUCCESS = 0, /*!< Operation was successful. */ + KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */ + KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */ + KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */ + KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */ + KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */ + KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */ + KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */ + KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */ + KTX_GL_ERROR, /*!< GL operations resulted in an error. */ + KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ + KTX_INVALID_VALUE, /*!< A parameter value was not valid */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ + KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ + KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ + KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ + KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */ + KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */ + KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */ + KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */ + KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */ + KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */ +} ktx_error_code_e; +/** + * @deprecated + * @~English + * @brief For backward compatibility + */ +#define KTX_error_code ktx_error_code_e + +#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } +#define KTX_ENDIAN_REF (0x04030201) +#define KTX_ENDIAN_REF_REV (0x01020304) +#define KTX_HEADER_SIZE (64) + +/** + * @~English + * @brief Result codes returned by library functions. + */ + typedef enum ktx_error_code_e ktxResult; + +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ +typedef struct ktxKVListEntry* ktxHashList; + +typedef struct ktxStream ktxStream; + +#define KTX_APIENTRYP KTX_APIENTRY * +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ +typedef struct ktxKVListEntry ktxHashListEntry; + +typedef enum ktxOrientationX { + KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r' +} ktxOrientationX; + +typedef enum ktxOrientationY { + KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd' +} ktxOrientationY; + +typedef enum ktxOrientationZ { + KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o' +} ktxOrientationZ; + +typedef enum class_id { + ktxTexture1_c = 1, + ktxTexture2_c = 2 +} class_id; + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +struct ktxOrientation { + ktxOrientationX x; /*!< Orientation in X */ + ktxOrientationY y; /*!< Orientation in Y */ + ktxOrientationZ z; /*!< Orientation in Z */ +}; + +#define KTXTEXTURECLASSDEFN \ + class_id classId; \ + struct ktxTexture_vtbl* vtbl; \ + struct ktxTexture_vvtbl* vvtbl; \ + struct ktxTexture_protected* _protected; \ + ktx_bool_t isArray; \ + ktx_bool_t isCubemap; \ + ktx_bool_t isCompressed; \ + ktx_bool_t generateMipmaps; \ + ktx_uint32_t baseWidth; \ + ktx_uint32_t baseHeight; \ + ktx_uint32_t baseDepth; \ + ktx_uint32_t numDimensions; \ + ktx_uint32_t numLevels; \ + ktx_uint32_t numLayers; \ + ktx_uint32_t numFaces; \ + struct ktxOrientation orientation; \ + ktxHashList kvDataHead; \ + ktx_uint32_t kvDataLen; \ + ktx_uint8_t* kvData; \ + ktx_size_t dataSize; \ + ktx_uint8_t* pData; + + +/** + * @class ktxTexture + * @~English + * @brief Base class representing a texture. + * + * ktxTextures should be created only by one of the provided + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture { + KTXTEXTURECLASSDEFN +} ktxTexture; +/** + * @typedef ktxTexture::classId + * @~English + * @brief Identify the class type. + * + * Since there are no public ktxTexture constructors, this can only have + * values of ktxTexture1_c or ktxTexture2_c. + */ +/** + * @typedef ktxTexture::vtbl + * @~English + * @brief Pointer to the class's vtble. + */ +/** + * @typedef ktxTexture::vvtbl + * @~English + * @brief Pointer to the class's vtble for Vulkan functions. + * + * A separate vtble is used so this header does not need to include vulkan.h. + */ +/** + * @typedef ktxTexture::_protected + * @~English + * @brief Opaque pointer to the class's protected variables. + */ +/** + * @typedef ktxTexture::isArray + * @~English + * + * KTX_TRUE if the texture is an array texture, i.e, + * a GL_TEXTURE_*_ARRAY target is to be used. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture is a cubemap or cubemap array. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture's format is a block compressed format. + */ +/** + * @typedef ktxTexture::generateMipmaps + * @~English + * + * KTX_TRUE if mipmaps should be generated for the texture by + * ktxTexture_GLUpload() or ktxTexture_VkUpload(). + */ +/**n + * @typedef ktxTexture::baseWidth + * @~English + * @brief Width of the texture's base level. + */ +/** + * @typedef ktxTexture::baseHeight + * @~English + * @brief Height of the texture's base level. + */ +/** + * @typedef ktxTexture::baseDepth + * @~English + * @brief Depth of the texture's base level. + */ +/** + * @typedef ktxTexture::numDimensions + * @~English + * @brief Number of dimensions in the texture: 1, 2 or 3. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of mip levels in the texture. + * + * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a + * full pyramid but always starts at the base level. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of array layers in the texture. + */ +/** + * @typedef ktxTexture::numFaces + * @~English + * @brief Number of faces: 6 for cube maps, 1 otherwise. + */ +/** + * @typedef ktxTexture::orientation + * @~English + * @brief Describes the logical orientation of the images in each dimension. + * + * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z. + */ +/** + * @typedef ktxTexture::kvDataHead + * @~English + * @brief Head of the hash list of metadata. + */ +/** + * @typedef ktxTexture::kvDataLen + * @~English + * @brief Length of the metadata, if it has been extracted in its raw form, + * otherwise 0. + */ +/** + * @typedef ktxTexture::kvData + * @~English + * @brief Pointer to the metadata, if it has been extracted in its raw form, + * otherwise NULL. + */ +/** + * @typedef ktxTexture::dataSize + * @~English + * @brief Byte length of the texture's uncompressed image data. + */ +/** + * @typedef ktxTexture::pData + * @~English + * @brief Pointer to the start of the image data. + */ + +/** + * @memberof ktxTexture + * @~English + * @brief Signature of function called by the ktxTexture_Iterate* + * functions to receive image data. + * + * The function parameters are used to pass values which change for each image. + * Obtain values which are uniform across all images from the @c ktxTexture + * object. + * + * @param [in] miplevel MIP level from 0 to the max level which is + * dependent on the texture size. + * @param [in] face usually 0; for cube maps, one of the 6 cube + * faces in the order +X, -X, +Y, -Y, +Z, -Z, + * 0 to 5. + * @param [in] width width of the image. + * @param [in] height height of the image or, for 1D textures + * textures, 1. + * @param [in] depth depth of the image or, for 1D & 2D + * textures, 1. + * @param [in] faceLodSize number of bytes of data pointed at by + * @p pixels. + * @param [in] pixels pointer to the image data. + * @param [in,out] userdata pointer for the application to pass data to and + * from the callback function. + */ + +typedef KTX_error_code + (* PFNKTXITERCB)(int miplevel, int face, + int width, int height, int depth, + ktx_uint64_t faceLodSize, + void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + ktx_size_t* pOffset); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This, + PFNKTXITERCB iterCb, + void* userdata); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This, + ktx_uint8_t* pBuffer, + ktx_size_t bufSize); +typedef ktx_bool_t + (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + const ktx_uint8_t* src, + ktx_size_t srcSize); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + FILE* src, ktx_size_t srcSize); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This, + const char* const dstname); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, + ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + struct ktxTexture_vtbl { + PFNKTEXDESTROY Destroy; + PFNKTEXGETIMAGEOFFSET GetImageOffset; + PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + PFNKTEXGETIMAGESIZE GetImageSize; + PFNKTEXITERATELEVELS IterateLevels; + PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + PFNKTEXLOADIMAGEDATA LoadImageData; + PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; +}; + +/**************************************************************** + * Macros to give some backward compatibility to the previous API + ****************************************************************/ + +/** + * @~English + * @brief Helper for calling the Destroy virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_Destroy + */ +#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This) + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \ + (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset) + +/** + * @~English + * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture. + * + * For a ktxTexture1 this will always return the value of This->dataSize. + * + * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed + */ +#define ktxTexture_GetDataSizeUncompressed(This) \ + (This)->vtbl->GetDataSizeUncompressed(This) + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +#define ktxTexture_GetImageSize(This, level) \ + (This)->vtbl->GetImageSize(This, level) + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +#define ktxTexture_IterateLevels(This, iterCb, userdata) \ + (This)->vtbl->IterateLevels(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \ + (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \ + (This)->vtbl->LoadImageData(This, pBuffer, bufSize) + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This) + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize) + +/** + * @~English + * @brief Helper for calling the SetImageFromStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream + */ +#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) + +/** + * @~English + * @brief Helper for calling the WriteToStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream + */ +#define ktxTexture_WriteToStdioStream(This, dstsstr) \ + (This)->vtbl->WriteToStdioStream(This, dstsstr) + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +#define ktxTexture_WriteToNamedFile(This, dstname) \ + (This)->vtbl->WriteToNamedFile(This, dstname) + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ + (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + + +/** + * @class ktxTexture1 + * @~English + * @brief Class representing a KTX version 1 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture1 { + KTXTEXTURECLASSDEFN + ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + struct ktxTexture1_private* _private; /*!< Private data. */ +} ktxTexture1; + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +typedef enum ktxSupercmpScheme { + KTX_SS_NONE = 0, /*!< No supercompression. */ + KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */ + KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */ + KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */ + KTX_SS_BEGIN_RANGE = KTX_SS_NONE, + KTX_SS_END_RANGE = KTX_SS_ZLIB, + KTX_SS_BEGIN_VENDOR_RANGE = 0x10000, + KTX_SS_END_VENDOR_RANGE = 0x1ffff, + KTX_SS_BEGIN_RESERVED = 0x20000, + KTX_SUPERCOMPRESSION_BASIS = KTX_SS_BASIS_LZ, + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_BASIS_LZ instead. */ + KTX_SUPERCOMPRESSION_ZSTD = KTX_SS_ZSTD + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_ZSTD instead. */ +} ktxSupercmpScheme; + +/** + * @class ktxTexture2 + * @~English + * @brief Class representing a KTX version 2 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture2 { + KTXTEXTURECLASSDEFN + ktx_uint32_t vkFormat; + ktx_uint32_t* pDfd; + ktxSupercmpScheme supercompressionScheme; + ktx_bool_t isVideo; + ktx_uint32_t duration; + ktx_uint32_t timescale; + ktx_uint32_t loopcount; + struct ktxTexture2_private* _private; /*!< Private data. */ +} ktxTexture2; + +#define ktxTexture(t) ((ktxTexture*)t) + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1_Create() and + * ktxTexture2_Create(). + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef struct +{ + ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an + array texture. Means OpenGL will use a + GL_TEXTURE_*_ARRAY target. */ + ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} ktxTextureCreateInfo; + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef enum { + KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */ + KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */ +} ktxTextureCreateStorageEnum; + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +enum ktxTextureCreateFlagBits { + KTX_TEXTURE_CREATE_NO_FLAGS = 0x00, + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01, + /*!< Load the images from the KTX source. */ + KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08 + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +}; +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +typedef ktx_uint32_t ktxTextureCreateFlags; + +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + ktxStream_write write; /*!< pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< destruct the stream. */ + + enum streamType type; + union { + FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + struct + { + void* address; /**< pointer to the data. */ + void* allocatorAddress; /**< pointer to a memory allocator. */ + ktx_size_t size; /**< size of the data. */ + } custom_ptr; /**< pointer to a struct for custom streams. */ + } data; /**< pointer to the stream data. */ + ktx_off_t readpos; /**< used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +}; + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ +KTX_API ktx_uint8_t* KTX_APIENTRY +ktxTexture_GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ +KTX_API ktx_size_t KTX_APIENTRY +ktxTexture_GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, + GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); +/* + * Create a new ktxTexture1. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture1_NeedsTranscoding(ktxTexture1* This); + +/* + * Write a ktxTexture object to a stdio stream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + +/* + * Write a ktxTexture object to a named file in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname); + +/* + * Write a ktxTexture object to a block of memory in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, + ktx_uint8_t** bytes, ktx_size_t* size); + +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + +/* + * Create a new ktxTexture2. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + +KTX_API void KTX_APIENTRY +ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, + ktx_uint32_t* componentByteLength); + +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetNumComponents(ktxTexture2* This); + +KTX_API khr_df_transfer_e KTX_APIENTRY +ktxTexture2_GetOETF_e(ktxTexture2* This); + +// For backward compatibility +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetOETF(ktxTexture2* This); + +KTX_API khr_df_model_e KTX_APIENTRY +ktxTexture2_GetColorModel_e(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_NeedsTranscoding(ktxTexture2* This); + +/** + * @~English + * @brief Flags specifiying UASTC encoding options. + */ +typedef enum ktx_pack_uastc_flag_bits_e { + KTX_PACK_UASTC_LEVEL_FASTEST = 0, + /*!< Fastest compression. 43.45dB. */ + KTX_PACK_UASTC_LEVEL_FASTER = 1, + /*!< Faster compression. 46.49dB. */ + KTX_PACK_UASTC_LEVEL_DEFAULT = 2, + /*!< Default compression. 47.47dB. */ + KTX_PACK_UASTC_LEVEL_SLOWER = 3, + /*!< Slower compression. 48.01dB. */ + KTX_PACK_UASTC_LEVEL_VERYSLOW = 4, + /*!< Very slow compression. 48.24dB. */ + KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW, + /*!< Maximum supported quality level. */ + KTX_PACK_UASTC_LEVEL_MASK = 0xF, + /*!< Mask to extract the level from the other bits. */ + KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8, + /*!< Optimize for lowest UASTC error. */ + KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16, + /*!< Optimize for lowest BC7 error. */ + KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64, + /*!< Optimize for faster transcoding to ETC1. */ + KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128, + /*!< Optimize for fastest transcoding to ETC1. */ + KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256 + /*!< Not documented in BasisU code. */ +} ktx_pack_uastc_flag_bits_e; +typedef ktx_uint32_t ktx_pack_uastc_flags; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +typedef enum ktx_pack_astc_quality_levels_e { + KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0, + /*!< Fastest compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10, + /*!< Fast compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60, + /*!< Medium compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98, + /*!< Slower compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100, + /*!< Very slow compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE, + /*!< Maximum supported quality level. */ +} ktx_pack_astc_quality_levels_e; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +typedef enum ktx_pack_astc_block_dimension_e { + // 2D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp + // 3D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6 + /*!< Maximum supported blocks. */ +} ktx_pack_astc_block_dimension_e; + +/** + * @~English + * @brief Options specifying ASTC encoder profile mode + * This and function is used later to derive the profile. + */ +typedef enum ktx_pack_astc_encoder_mode_e { + KTX_PACK_ASTC_ENCODER_MODE_DEFAULT, + KTX_PACK_ASTC_ENCODER_MODE_LDR, + KTX_PACK_ASTC_ENCODER_MODE_HDR, + KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR +} ktx_pack_astc_encoder_mode_e; + +extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture_CompressAstc. + * + * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension + * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to + * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended. + */ +typedef struct ktxAstcParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + ktx_uint32_t qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps + In this mode normals are compressed to X,Y components + Discarding Z component, reader will need to generate Z + component in shaders. + */ + + ktx_bool_t perceptual; + /*!< The codec should optimize for perceptual error, instead of direct + RMS error. This aims to improves perceived image quality, but + typically lowers the measured PSNR score. Perceptual methods are + currently only available for normal maps and RGB color data. + */ + + char inputSwizzle[4]; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} ktxAstcParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + +/** + * @memberof ktxTexture2 + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture2_CompressBasisEx(). + * + * If you only want default values, use ktxTexture2_CompressBasis(). Here, at a minimum you + * must initialize the structure as follows: + * @code + * ktxBasisParams params = {0}; + * params.structSize = sizeof(params); + * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e compressionLevel has to be explicitly set because 0 is a valid @e compressionLevel + * but is not the default used by the BasisU encoder when no value is set. Only the other + * settings that are to be non-default must be non-zero. + */ +typedef struct ktxBasisParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + ktx_bool_t uastc; + /*!< True to use UASTC base, false to use ETC1S base. */ + ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + ktx_uint32_t compressionLevel; + /*!< Encoding speed vs. quality tradeoff. Range is [0,5]. Higher values + are slower, but give higher quality. There is no default. Callers + must explicitly set this value. Callers can use + KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL as a default value. + Currently this is 2. + */ + ktx_uint32_t qualityLevel; + /*!< Compression quality. Range is [1,255]. Lower gives better + compression/lower quality/faster. Higher gives less compression + /higher quality/slower. This automatically determines values for + @c maxEndpoints, @c maxSelectors, + @c endpointRDOThreshold and @c selectorRDOThreshold + for the target quality level. Setting these parameters overrides + the values determined by @c qualityLevel which defaults to + 128 if neither it nor both of @c maxEndpoints and + @c maxSelectors have been set. + @note @e Both of @c maxEndpoints and @c maxSelectors + must be set for them to have any effect. + @note qualityLevel will only determine values for + @c endpointRDOThreshold and @c selectorRDOThreshold + when its value exceeds 128, otherwise their defaults will be used. + */ + ktx_uint32_t maxEndpoints; + /*!< Manually set the max number of color endpoint clusters. + Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors + must also be set, otherwise the value will be ignored. + */ + float endpointRDOThreshold; + /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is + higher quality but less quality per output bit (try [1.0,3.0]. + This will override the value chosen by @c qualityLevel. + */ + ktx_uint32_t maxSelectors; + /*!< Manually set the max number of color selector clusters. Range + is [1,16128]. Default is 0, unset. If this is set, maxEndpoints + must also be set, otherwise the value will be ignored. + */ + float selectorRDOThreshold; + /*!< Set selector RDO quality threshold. The default is 1.5. Lower is + higher quality but less quality per output bit (try [1.0,3.0]). + This will override the value chosen by @c qualityLevel. + */ + char inputSwizzle[4]; + /*!< A swizzle to apply before encoding. It must match the regular + expression /^[rgba01]{4}$/. If both this and preSwizzle + are specified ktxTexture_CompressBasisEx will raise + KTX_INVALID_OPERATION. + */ + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps (no + selector RDO, no endpoint RDO) and sets the texture's DFD appropriately. + Only valid for linear textures. + */ + ktx_bool_t separateRGToRGB_A; + /*!< @deprecated. This was and is a no-op. 2-component inputs have always been + automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode. + */ + ktx_bool_t preSwizzle; + /*!< If the texture has @c KTXswizzle metadata, apply it before + compressing. Swizzling, like @c rabb may yield drastically + different error metrics if done after supercompression. + */ + ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + ktx_bool_t noSelectorRDO; + /*!< Disable selector rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + + /* UASTC params */ + + ktx_pack_uastc_flags uastcFlags; + /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC + encoding. The most important value is the level given in the + least-significant 4 bits which selects a speed vs quality tradeoff + as shown in the following table: + + Level/Speed | Quality + :-----: | :-------: + KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB + KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB + KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB + KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB + KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB + */ + ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + float uastcRDOQualityScalar; + /*!< UASTC RDO quality scalar (lambda). Lower values yield higher + quality/larger LZ compressed files, higher values yield lower + quality/smaller LZ compressed files. A good range to try is [.2,4]. + Full range is [.001,50.0]. Default is 1.0. + */ + ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + float uastcRDOMaxSmoothBlockErrorScale; + /*!< UASTC RDO max smooth block error scale. Range is [1,300]. + Default is 10.0, 1.0 is disabled. Larger values suppress more + artifacts (and allocate more bits) on smooth blocks. + */ + float uastcRDOMaxSmoothBlockStdDev; + /*!< UASTC RDO max smooth block standard deviation. Range is + [.01,65536.0]. Default is 18.0. Larger values expand the range of + blocks considered smooth. + */ + ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + +} ktxBasisParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params); + +/** + * @~English + * @brief Enumerators for specifying the transcode target format. + * + * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate + * RGB images, a.k.a slices within the BasisU compressed data. For UASTC + * format they refer to the RGB and the alpha components of the UASTC data. If + * the original image had only 2 components, R will be in the opaque portion + * and G in the alpha portion. The R value will be replicated in the RGB + * components. In the case of BasisU the G value will be replicated in all 3 + * components of the alpha slice. If the original image had only 1 component + * it's value is replicated in all 3 components of the opaque portion and + * there is no alpha. + * + * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R, + * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565, + * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor + * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader + * will not produce correct results if any texture filtering is being used. + */ +typedef enum ktx_transcode_fmt_e { + // Compressed formats + + // ETC1-2 + KTX_TTF_ETC1_RGB = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_RGBA = 1, + /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + + // BC1-5, BC7 (desktop, some mobile devices) + KTX_TTF_BC1_RGB = 2, + /*!< Opaque only, no punchthrough alpha support yet. Returns RGB + or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS + flag is specified. */ + KTX_TTF_BC3_RGBA = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + KTX_TTF_BC4_R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_BC5_RG = 5, + /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should + have an alpha channel (if not G will be all 255's. For tangent + space normal maps. */ + KTX_TTF_BC7_RGBA = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + KTX_TTF_PVRTC1_4_RGB = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_PVRTC1_4_RGBA = 9, + /*!< Opaque+alpha. Most useful for simple opacity maps. If the + texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB + will be used instead. Lowest quality of any supported + texture format. */ + + // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day) + KTX_TTF_ASTC_4x4_RGBA = 10, + /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for + textures without an alpha channel. The transcoder uses + RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and + [0,255]) endpoint precisions. */ + + // ATC and FXT1 formats are not supported by KTX2 as there + // are no equivalent VkFormats. + + KTX_TTF_PVRTC2_4_RGB = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + KTX_TTF_PVRTC2_4_RGBA = 19, + /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB. + Premultiplied alpha is highly recommended, otherwise the + color channel can leak into the alpha channel on transparent + blocks. */ + + KTX_TTF_ETC2_EAC_R11 = 20, + /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_EAC_RG11 = 21, + /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The + texture should have an alpha channel (if not G will be all + 255's. For tangent space normal maps. */ + + // Uncompressed (raw pixel) formats + KTX_TTF_RGBA32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + KTX_TTF_RGB565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + KTX_TTF_BGR565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + KTX_TTF_RGBA4444 = 16, + /*!< 16bpp RGBA image stored in raster (not block) order in memory, + R at bit position 12, A at bit position 0. */ + + // Values for automatic selection of RGB or RGBA depending if alpha + // present. + KTX_TTF_ETC = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + KTX_TTF_BC1_OR_3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + KTX_TTF_NOSELECTION = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + KTX_TF_ETC1 = KTX_TTF_ETC1_RGB, + //!< @deprecated. Use #KTX_TTF_ETC1_RGB. + KTX_TF_ETC2 = KTX_TTF_ETC, + //!< @deprecated. Use #KTX_TTF_ETC. + KTX_TF_BC1 = KTX_TTF_BC1_RGB, + //!< @deprecated. Use #KTX_TTF_BC1_RGB. + KTX_TF_BC3 = KTX_TTF_BC3_RGBA, + //!< @deprecated. Use #KTX_TTF_BC3_RGBA. + KTX_TF_BC4 = KTX_TTF_BC4_R, + //!< @deprecated. Use #KTX_TTF_BC4_R. + KTX_TF_BC5 = KTX_TTF_BC5_RG, + //!< @deprecated. Use #KTX_TTF_BC5_RG. + KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA + KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB + //!< @deprecated. Use #KTX_TTF_PVRTC1_4_RGB. +} ktx_transcode_fmt_e; + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +typedef enum ktx_transcode_flag_bits_e { + KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2, + /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger + power of 2 (not implemented yet, but we're going to support it). + Ignored if the slice's dimensions are already a power of 2. + */ + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4, + /*!< When decoding to an opaque texture format, if the Basis data has + alpha, decode the alpha slice instead of the color slice to the + output texture format. Has no effect if there is no alpha data. + */ + KTX_TF_HIGH_QUALITY = 32, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} ktx_transcode_flag_bits_e; +typedef ktx_uint32_t ktx_transcode_flags; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, + ktx_transcode_flags transcodeFlags); + +/* + * Returns a string corresponding to a KTX error code. + */ +KTX_API const char* KTX_APIENTRY +ktxErrorString(KTX_error_code error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ +KTX_API const char* KTX_APIENTRY +ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ +KTX_API const char* KTX_APIENTRY +ktxTranscodeFormatString(ktx_transcode_fmt_e format); + +KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl); +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl); +KTX_API void KTX_APIENTRY +ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head); +KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_AddKVPair(ktxHashList* pHead, const char* key, + unsigned int valueLen, const void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindEntry(ktxHashList* pHead, const char* key, + ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindValue(ktxHashList* pHead, const char* key, + unsigned int* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ +KTX_API ktxHashListEntry* KTX_APIENTRY +ktxHashList_Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Serialize(ktxHashList* pHead, + unsigned int* kvdLen, unsigned char** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd); + +/* + * Get the key from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetKey(ktxHashListEntry* This, + unsigned int* pKeyLen, char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetValue(ktxHashListEntry* This, + unsigned int* pValueLen, void** ppValue); + +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX2 file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); + +#ifdef __cplusplus +} +#endif + +/*========================================================================* + * For backward compatibilty with the V3 & early versions of the V4 APIs. * + *========================================================================*/ + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_transcode_fmt_e ktx_transcode_fmt_e + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_decode_flags ktx_transcode_flag_bits + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktxTexture_GetSize ktxTexture_GetDatasize + +/** +@~English +@page libktx_history Revision History + +No longer updated. Kept to preserve ancient history. For more recent history see the repo log at +https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo. + +@section v8 Version 4.0 +Added: +@li Support for KTX Version 2. +@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files. +@li Function to print info about a KTX file. + +@section v7 Version 3.0.1 +Fixed: +@li GitHub issue #159: compile failure with recent Vulkan SDKs. +@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents. +@li Incorrect BC4 blocksize. +@li Missing mapping of PVRTC formats from GL to Vulkan. +@li Incorrect block width and height calculations for sizes that are not + a multiple of the block size. +@li Incorrect KTXorientation key in test images. + +@section v6 Version 3.0 +Added: +@li new ktxTexture object based API for reading KTX files without an OpenGL context. +@li Vulkan loader. @#include to use it. + +Changed: +@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h. + Applications using OpenGL must now include these files themselves. +@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures + when the OpenGL context does not support 1D textures. + KTX_UNSUPPORTED_TEXTURE_TYPE is now returned. + +@section v5 Version 2.0.2 +Added: +@li Support for cubemap arrays. + +Changed: +@li New build system + +Fixed: +@li GitHub issue #40: failure to byte-swap key-value lengths. +@li GitHub issue #33: returning incorrect target when loading cubemaps. +@li GitHub PR #42: loading of texture arrays. +@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined. +@li GitHub issue #39: stack-buffer-overflow in toktx +@li Don't use GL_EXTENSIONS on recent OpenGL versions. + +@section v4 Version 2.0.1 +Added: +@li CMake build files. Thanks to Pavel Rotjberg for the initial version. + +Changed: +@li ktxWriteKTXF to check the validity of the type & format combinations + passed to it. + +Fixed: +@li Public Bugzilla 999: 16-bit luminance texture cannot be written. +@li compile warnings from compilers stricter than MS Visual C++. Thanks to + Pavel Rotjberg. + +@section v3 Version 2.0 +Added: +@li support for decoding ETC2 and EAC formats in the absence of a hardware + decoder. +@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA, + etc. formats to the equivalent R, RG, etc. format with an + appropriate swizzle, when loading in OpenGL Core Profile contexts. +@li ktxErrorString function to return a string corresponding to an error code. +@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3. + The latter includes an EGL on WGL wrapper that makes porting apps between + OpenGL ES and OpenGL easier on Windows. +@li more texture formats to ktxLoadTexture[FN] and toktx tests. + +Changed: +@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at + run time and load textures, or not, according to those capabilities. + +Fixed: +@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX + format. +@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write + more than 1 byte of face-LOD padding. + +Although there is only a very minor API change, the addition of ktxErrorString, +the functional changes are large enough to justify bumping the major revision +number. + +@section v2 Version 1.0.1 +Implemented ktxLoadTextureM. +Fixed the following: +@li Public Bugzilla 571: crash when null passed for pIsMipmapped. +@li Public Bugzilla 572: memory leak when unpacking ETC textures. +@li Public Bugzilla 573: potential crash when unpacking ETC textures with unused padding pixels. +@li Public Bugzilla 576: various small fixes. + +Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes. + +@section v1 Version 1.0 +Initial release. + +*/ + +#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ diff --git a/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/libktx.a b/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/libktx.a new file mode 100644 index 00000000..16d48f79 Binary files /dev/null and b/KTXLoader/libktx/ktx.xcframework/macos-arm64_x86_64/libktx.a differ diff --git a/KTXLoader/libktx/ktx.xcframework/tvos-arm64/Headers/KHR/khr_df.h b/KTXLoader/libktx/ktx.xcframework/tvos-arm64/Headers/KHR/khr_df.h new file mode 100644 index 00000000..c0d03aa7 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/tvos-arm64/Headers/KHR/khr_df.h @@ -0,0 +1,630 @@ +/* The Khronos Data Format Specification (version 1.3) */ +/* +** Copyright 2015-2020 The Khronos Group Inc. +** SPDX-License-Identifier: Apache-2.0 +*/ + +/* This header defines a structure that can describe the layout of image + formats in memory. This means that the data format is transparent to + the application, and the expectation is that this should be used when + the layout is defined external to the API. Many Khronos APIs deliberately + keep the internal layout of images opaque, to allow proprietary layouts + and optimisations. This structure is not appropriate for describing + opaque layouts. */ + +/* We stick to standard C89 constructs for simplicity and portability. */ + +#ifndef _KHR_DATA_FORMAT_H_ +#define _KHR_DATA_FORMAT_H_ + +/** @file khr_df.h + + @brief Data Format enums and macros. +*/ + +/* Accessors */ +typedef enum _khr_word_e { + KHR_DF_WORD_VENDORID = 0U, + KHR_DF_WORD_DESCRIPTORTYPE = 0U, + KHR_DF_WORD_VERSIONNUMBER = 1U, + KHR_DF_WORD_DESCRIPTORBLOCKSIZE = 1U, + KHR_DF_WORD_MODEL = 2U, + KHR_DF_WORD_PRIMARIES = 2U, + KHR_DF_WORD_TRANSFER = 2U, + KHR_DF_WORD_FLAGS = 2U, + KHR_DF_WORD_TEXELBLOCKDIMENSION0 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION1 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION2 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION3 = 3U, + KHR_DF_WORD_BYTESPLANE0 = 4U, + KHR_DF_WORD_BYTESPLANE1 = 4U, + KHR_DF_WORD_BYTESPLANE2 = 4U, + KHR_DF_WORD_BYTESPLANE3 = 4U, + KHR_DF_WORD_BYTESPLANE4 = 5U, + KHR_DF_WORD_BYTESPLANE5 = 5U, + KHR_DF_WORD_BYTESPLANE6 = 5U, + KHR_DF_WORD_BYTESPLANE7 = 5U, + KHR_DF_WORD_SAMPLESTART = 6U, + KHR_DF_WORD_SAMPLEWORDS = 4U +} khr_df_word_e; + +typedef enum _khr_df_shift_e { + KHR_DF_SHIFT_VENDORID = 0U, + KHR_DF_SHIFT_DESCRIPTORTYPE = 17U, + KHR_DF_SHIFT_VERSIONNUMBER = 0U, + KHR_DF_SHIFT_DESCRIPTORBLOCKSIZE = 16U, + KHR_DF_SHIFT_MODEL = 0U, + KHR_DF_SHIFT_PRIMARIES = 8U, + KHR_DF_SHIFT_TRANSFER = 16U, + KHR_DF_SHIFT_FLAGS = 24U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION0 = 0U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION1 = 8U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION2 = 16U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION3 = 24U, + KHR_DF_SHIFT_BYTESPLANE0 = 0U, + KHR_DF_SHIFT_BYTESPLANE1 = 8U, + KHR_DF_SHIFT_BYTESPLANE2 = 16U, + KHR_DF_SHIFT_BYTESPLANE3 = 24U, + KHR_DF_SHIFT_BYTESPLANE4 = 0U, + KHR_DF_SHIFT_BYTESPLANE5 = 8U, + KHR_DF_SHIFT_BYTESPLANE6 = 16U, + KHR_DF_SHIFT_BYTESPLANE7 = 24U +} khr_df_shift_e; + +typedef enum _khr_df_mask_e { + KHR_DF_MASK_VENDORID = 0x1FFFFU, + KHR_DF_MASK_DESCRIPTORTYPE = 0x7FFFU, + KHR_DF_MASK_VERSIONNUMBER = 0xFFFFU, + KHR_DF_MASK_DESCRIPTORBLOCKSIZE = 0xFFFFU, + KHR_DF_MASK_MODEL = 0xFFU, + KHR_DF_MASK_PRIMARIES = 0xFFU, + KHR_DF_MASK_TRANSFER = 0xFFU, + KHR_DF_MASK_FLAGS = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION0 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION1 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION2 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE0 = 0xFFU, + KHR_DF_MASK_BYTESPLANE1 = 0xFFU, + KHR_DF_MASK_BYTESPLANE2 = 0xFFU, + KHR_DF_MASK_BYTESPLANE3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE4 = 0xFFU, + KHR_DF_MASK_BYTESPLANE5 = 0xFFU, + KHR_DF_MASK_BYTESPLANE6 = 0xFFU, + KHR_DF_MASK_BYTESPLANE7 = 0xFFU +} khr_df_mask_e; + +/* Helper macro: + Extract field X from basic descriptor block BDB */ +#define KHR_DFDVAL(BDB, X) \ + (((BDB)[KHR_DF_WORD_ ## X] >> (KHR_DF_SHIFT_ ## X)) \ + & (KHR_DF_MASK_ ## X)) + +/* Helper macro: + Set field X of basic descriptor block BDB */ +#define KHR_DFDSETVAL(BDB, X, val) \ + ((BDB)[KHR_DF_WORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_ ## X] & \ + ~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \ + (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X))) + +/* Offsets relative to the start of a sample */ +typedef enum _khr_df_sampleword_e { + KHR_DF_SAMPLEWORD_BITOFFSET = 0U, + KHR_DF_SAMPLEWORD_BITLENGTH = 0U, + KHR_DF_SAMPLEWORD_CHANNELID = 0U, + KHR_DF_SAMPLEWORD_QUALIFIERS = 0U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION0 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION1 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION2 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION3 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL = 1U, + KHR_DF_SAMPLEWORD_SAMPLELOWER = 2U, + KHR_DF_SAMPLEWORD_SAMPLEUPPER = 3U +} khr_df_sampleword_e; + +typedef enum _khr_df_sampleshift_e { + KHR_DF_SAMPLESHIFT_BITOFFSET = 0U, + KHR_DF_SAMPLESHIFT_BITLENGTH = 16U, + KHR_DF_SAMPLESHIFT_CHANNELID = 24U, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLESHIFT_QUALIFIERS = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION0 = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION1 = 8U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION2 = 16U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION3 = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION_ALL = 0U, + KHR_DF_SAMPLESHIFT_SAMPLELOWER = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEUPPER = 0U +} khr_df_sampleshift_e; + +typedef enum _khr_df_samplemask_e { + KHR_DF_SAMPLEMASK_BITOFFSET = 0xFFFFU, + KHR_DF_SAMPLEMASK_BITLENGTH = 0xFF, + KHR_DF_SAMPLEMASK_CHANNELID = 0xF, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLEMASK_QUALIFIERS = 0xF0, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION0 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION1 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION2 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION3 = 0xFF, + /* ISO C restricts enum values to range of int hence the + cast. We do it verbosely instead of using -1 to ensure + it is a 32-bit value even if int is 64 bits. */ + KHR_DF_SAMPLEMASK_SAMPLEPOSITION_ALL = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLELOWER = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLEUPPER = (int) 0xFFFFFFFFU +} khr_df_samplemask_e; + +/* Helper macro: + Extract field X of sample S from basic descriptor block BDB */ +#define KHR_DFDSVAL(BDB, S, X) \ + (((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] >> (KHR_DF_SAMPLESHIFT_ ## X)) \ + & (KHR_DF_SAMPLEMASK_ ## X)) + +/* Helper macro: + Set field X of sample S of basic descriptor block BDB */ +#define KHR_DFDSETSVAL(BDB, S, X, val) \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] & \ + ~((uint32_t)(KHR_DF_SAMPLEMASK_ ## X) << (KHR_DF_SAMPLESHIFT_ ## X))) | \ + (((val) & (uint32_t)(KHR_DF_SAMPLEMASK_ ## X)) << (KHR_DF_SAMPLESHIFT_ ## X))) + +/* Helper macro: + Number of samples in basic descriptor block BDB */ +#define KHR_DFDSAMPLECOUNT(BDB) \ + (((KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) >> 2) - \ + KHR_DF_WORD_SAMPLESTART) \ + / KHR_DF_WORD_SAMPLEWORDS) + +/* Helper macro: + Size in words of basic descriptor block for S samples */ +#define KHR_DFDSIZEWORDS(S) \ + (KHR_DF_WORD_SAMPLESTART + \ + (S) * KHR_DF_WORD_SAMPLEWORDS) + +/* Vendor ids */ +typedef enum _khr_df_vendorid_e { + /* Standard Khronos descriptor */ + KHR_DF_VENDORID_KHRONOS = 0U, + KHR_DF_VENDORID_MAX = 0x1FFFFU +} khr_df_vendorid_e; + +/* Descriptor types */ +typedef enum _khr_df_khr_descriptortype_e { + /* Default Khronos basic descriptor block */ + KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0U, + /* Extension descriptor block for additional planes */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_PLANES = 0x6001U, + /* Extension descriptor block for additional dimensions */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_DIMENSIONS = 0x6002U, + /* Bit indicates modifying requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_WRITE_BIT = 0x2000U, + /* Bit indicates processing requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_DECODE_BIT = 0x4000U, + KHR_DF_KHR_DESCRIPTORTYPE_MAX = 0x7FFFU +} khr_df_khr_descriptortype_e; + +/* Descriptor block version */ +typedef enum _khr_df_versionnumber_e { + /* Standard Khronos descriptor */ + KHR_DF_VERSIONNUMBER_1_0 = 0U, /* Version 1.0 of the specification */ + KHR_DF_VERSIONNUMBER_1_1 = 0U, /* Version 1.1 did not bump the version number */ + KHR_DF_VERSIONNUMBER_1_2 = 1U, /* Version 1.2 increased the version number */ + KHR_DF_VERSIONNUMBER_1_3 = 2U, /* Version 1.3 increased the version number */ + KHR_DF_VERSIONNUMBER_LATEST = KHR_DF_VERSIONNUMBER_1_3, + KHR_DF_VERSIONNUMBER_MAX = 0xFFFFU +} khr_df_versionnumber_e; + +/** @~English + @brief Model in which the color coordinate space is defined. + There is no requirement that a color format use all the + channel types that are defined in the color model. */ +typedef enum _khr_df_model_e { + /** No interpretation of color channels defined */ + KHR_DF_MODEL_UNSPECIFIED = 0U, + /** Color primaries (red, green, blue) + alpha, depth and stencil */ + KHR_DF_MODEL_RGBSDA = 1U, + /** Color differences (Y', Cb, Cr) + alpha, depth and stencil */ + KHR_DF_MODEL_YUVSDA = 2U, + /** Color differences (Y', I, Q) + alpha, depth and stencil */ + KHR_DF_MODEL_YIQSDA = 3U, + /** Perceptual color (CIE L*a*b*) + alpha, depth and stencil */ + KHR_DF_MODEL_LABSDA = 4U, + /** Subtractive colors (cyan, magenta, yellow, black) + alpha */ + KHR_DF_MODEL_CMYKA = 5U, + /** Non-color coordinate data (X, Y, Z, W) */ + KHR_DF_MODEL_XYZW = 6U, + /** Hue, saturation, value, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSVA_ANG = 7U, + /** Hue, saturation, lightness, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSLA_ANG = 8U, + /** Hue, saturation, value, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSVA_HEX = 9U, + /** Hue, saturation, lightness, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSLA_HEX = 10U, + /** Lightweight approximate color difference (luma, orange, green) */ + KHR_DF_MODEL_YCGCOA = 11U, + /** ITU BT.2020 constant luminance YcCbcCrc */ + KHR_DF_MODEL_YCCBCCRC = 12U, + /** ITU BT.2100 constant intensity ICtCp */ + KHR_DF_MODEL_ICTCP = 13U, + /** CIE 1931 XYZ color coordinates (X, Y, Z) */ + KHR_DF_MODEL_CIEXYZ = 14U, + /** CIE 1931 xyY color coordinates (X, Y, Y) */ + KHR_DF_MODEL_CIEXYY = 15U, + + /* Compressed formats start at 128. */ + /* These compressed formats should generally have a single sample, + sited at the 0,0 position of the texel block. Where multiple + channels are used to distinguish formats, these should be cosited. */ + /* Direct3D (and S3) compressed formats */ + /* Note that premultiplied status is recorded separately */ + /** DXT1 "channels" are RGB (0), Alpha (1) + DXT1/BC1 with one channel is opaque + DXT1/BC1 with a cosited alpha sample is transparent */ + KHR_DF_MODEL_DXT1A = 128U, + KHR_DF_MODEL_BC1A = 128U, + /** DXT2/DXT3/BC2, with explicit 4-bit alpha */ + KHR_DF_MODEL_DXT2 = 129U, + KHR_DF_MODEL_DXT3 = 129U, + KHR_DF_MODEL_BC2 = 129U, + /** DXT4/DXT5/BC3, with interpolated alpha */ + KHR_DF_MODEL_DXT4 = 130U, + KHR_DF_MODEL_DXT5 = 130U, + KHR_DF_MODEL_BC3 = 130U, + /** BC4 - single channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC4 = 131U, + /** BC5 - two channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC5 = 132U, + /** BC6H - DX11 format for 16-bit float channels */ + KHR_DF_MODEL_BC6H = 133U, + /** BC7 - DX11 format */ + KHR_DF_MODEL_BC7 = 134U, + /* Gap left for future desktop expansion */ + + /* Mobile compressed formats follow */ + /** A format of ETC1 indicates that the format shall be decodable + by an ETC1-compliant decoder and not rely on ETC2 features */ + KHR_DF_MODEL_ETC1 = 160U, + /** A format of ETC2 is permitted to use ETC2 encodings on top of + the baseline ETC1 specification. + The ETC2 format has channels "red", "green", "RGB" and "alpha", + which should be cosited samples. + Punch-through alpha can be distinguished from full alpha by + the plane size in bytes required for the texel block */ + KHR_DF_MODEL_ETC2 = 161U, + /** Adaptive Scalable Texture Compression */ + /** ASTC HDR vs LDR is determined by the float flag in the channel */ + /** ASTC block size can be distinguished by texel block size */ + KHR_DF_MODEL_ASTC = 162U, + /** ETC1S is a simplified subset of ETC1 */ + KHR_DF_MODEL_ETC1S = 163U, + /** PowerVR Texture Compression v1 */ + KHR_DF_MODEL_PVRTC = 164U, + /** PowerVR Texture Compression v2 */ + KHR_DF_MODEL_PVRTC2 = 165U, + /** UASTC is a transcodable subset of ASTC + with additions to support the transcoding. */ + KHR_DF_MODEL_UASTC = 166U, + /* Proprietary formats (ATITC, etc.) should follow */ + KHR_DF_MODEL_MAX = 0xFFU +} khr_df_model_e; + +/* Definition of channel names for each color model */ +typedef enum _khr_df_model_channels_e { + /* Unspecified format with nominal channel numbering */ + KHR_DF_CHANNEL_UNSPECIFIED_0 = 0U, + KHR_DF_CHANNEL_UNSPECIFIED_1 = 1U, + KHR_DF_CHANNEL_UNSPECIFIED_2 = 2U, + KHR_DF_CHANNEL_UNSPECIFIED_3 = 3U, + KHR_DF_CHANNEL_UNSPECIFIED_4 = 4U, + KHR_DF_CHANNEL_UNSPECIFIED_5 = 5U, + KHR_DF_CHANNEL_UNSPECIFIED_6 = 6U, + KHR_DF_CHANNEL_UNSPECIFIED_7 = 7U, + KHR_DF_CHANNEL_UNSPECIFIED_8 = 8U, + KHR_DF_CHANNEL_UNSPECIFIED_9 = 9U, + KHR_DF_CHANNEL_UNSPECIFIED_10 = 10U, + KHR_DF_CHANNEL_UNSPECIFIED_11 = 11U, + KHR_DF_CHANNEL_UNSPECIFIED_12 = 12U, + KHR_DF_CHANNEL_UNSPECIFIED_13 = 13U, + KHR_DF_CHANNEL_UNSPECIFIED_14 = 14U, + KHR_DF_CHANNEL_UNSPECIFIED_15 = 15U, + /* MODEL_RGBSDA - red, green, blue, stencil, depth, alpha */ + KHR_DF_CHANNEL_RGBSDA_RED = 0U, + KHR_DF_CHANNEL_RGBSDA_R = 0U, + KHR_DF_CHANNEL_RGBSDA_GREEN = 1U, + KHR_DF_CHANNEL_RGBSDA_G = 1U, + KHR_DF_CHANNEL_RGBSDA_BLUE = 2U, + KHR_DF_CHANNEL_RGBSDA_B = 2U, + KHR_DF_CHANNEL_RGBSDA_STENCIL = 13U, + KHR_DF_CHANNEL_RGBSDA_S = 13U, + KHR_DF_CHANNEL_RGBSDA_DEPTH = 14U, + KHR_DF_CHANNEL_RGBSDA_D = 14U, + KHR_DF_CHANNEL_RGBSDA_ALPHA = 15U, + KHR_DF_CHANNEL_RGBSDA_A = 15U, + /* MODEL_YUVSDA - luma, Cb, Cr, stencil, depth, alpha */ + KHR_DF_CHANNEL_YUVSDA_Y = 0U, + KHR_DF_CHANNEL_YUVSDA_CB = 1U, + KHR_DF_CHANNEL_YUVSDA_U = 1U, + KHR_DF_CHANNEL_YUVSDA_CR = 2U, + KHR_DF_CHANNEL_YUVSDA_V = 2U, + KHR_DF_CHANNEL_YUVSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YUVSDA_S = 13U, + KHR_DF_CHANNEL_YUVSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YUVSDA_D = 14U, + KHR_DF_CHANNEL_YUVSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YUVSDA_A = 15U, + /* MODEL_YIQSDA - luma, in-phase, quadrature, stencil, depth, alpha */ + KHR_DF_CHANNEL_YIQSDA_Y = 0U, + KHR_DF_CHANNEL_YIQSDA_I = 1U, + KHR_DF_CHANNEL_YIQSDA_Q = 2U, + KHR_DF_CHANNEL_YIQSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YIQSDA_S = 13U, + KHR_DF_CHANNEL_YIQSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YIQSDA_D = 14U, + KHR_DF_CHANNEL_YIQSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YIQSDA_A = 15U, + /* MODEL_LABSDA - CIELAB/L*a*b* luma, red-green, blue-yellow, stencil, depth, alpha */ + KHR_DF_CHANNEL_LABSDA_L = 0U, + KHR_DF_CHANNEL_LABSDA_A = 1U, + KHR_DF_CHANNEL_LABSDA_B = 2U, + KHR_DF_CHANNEL_LABSDA_STENCIL = 13U, + KHR_DF_CHANNEL_LABSDA_S = 13U, + KHR_DF_CHANNEL_LABSDA_DEPTH = 14U, + KHR_DF_CHANNEL_LABSDA_D = 14U, + KHR_DF_CHANNEL_LABSDA_ALPHA = 15U, + /* NOTE: KHR_DF_CHANNEL_LABSDA_A is not a synonym for alpha! */ + /* MODEL_CMYKA - cyan, magenta, yellow, key/blacK, alpha */ + KHR_DF_CHANNEL_CMYKSDA_CYAN = 0U, + KHR_DF_CHANNEL_CMYKSDA_C = 0U, + KHR_DF_CHANNEL_CMYKSDA_MAGENTA = 1U, + KHR_DF_CHANNEL_CMYKSDA_M = 1U, + KHR_DF_CHANNEL_CMYKSDA_YELLOW = 2U, + KHR_DF_CHANNEL_CMYKSDA_Y = 2U, + KHR_DF_CHANNEL_CMYKSDA_KEY = 3U, + KHR_DF_CHANNEL_CMYKSDA_BLACK = 3U, + KHR_DF_CHANNEL_CMYKSDA_K = 3U, + KHR_DF_CHANNEL_CMYKSDA_ALPHA = 15U, + KHR_DF_CHANNEL_CMYKSDA_A = 15U, + /* MODEL_XYZW - coordinates x, y, z, w */ + KHR_DF_CHANNEL_XYZW_X = 0U, + KHR_DF_CHANNEL_XYZW_Y = 1U, + KHR_DF_CHANNEL_XYZW_Z = 2U, + KHR_DF_CHANNEL_XYZW_W = 3U, + /* MODEL_HSVA_ANG - value (luma), saturation, hue, alpha, angular projection, conical space */ + KHR_DF_CHANNEL_HSVA_ANG_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_ANG_V = 0U, + KHR_DF_CHANNEL_HSVA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_ANG_S = 1U, + KHR_DF_CHANNEL_HSVA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSVA_ANG_H = 2U, + KHR_DF_CHANNEL_HSVA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_ANG_A = 15U, + /* MODEL_HSLA_ANG - lightness (luma), saturation, hue, alpha, angular projection, double conical space */ + KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_ANG_L = 0U, + KHR_DF_CHANNEL_HSLA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_ANG_S = 1U, + KHR_DF_CHANNEL_HSLA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSLA_ANG_H = 2U, + KHR_DF_CHANNEL_HSLA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_ANG_A = 15U, + /* MODEL_HSVA_HEX - value (luma), saturation, hue, alpha, hexagonal projection, conical space */ + KHR_DF_CHANNEL_HSVA_HEX_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_HEX_V = 0U, + KHR_DF_CHANNEL_HSVA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_HEX_S = 1U, + KHR_DF_CHANNEL_HSVA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSVA_HEX_H = 2U, + KHR_DF_CHANNEL_HSVA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_HEX_A = 15U, + /* MODEL_HSLA_HEX - lightness (luma), saturation, hue, alpha, hexagonal projection, double conical space */ + KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_HEX_L = 0U, + KHR_DF_CHANNEL_HSLA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_HEX_S = 1U, + KHR_DF_CHANNEL_HSLA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSLA_HEX_H = 2U, + KHR_DF_CHANNEL_HSLA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_HEX_A = 15U, + /* MODEL_YCGCOA - luma, green delta, orange delta, alpha */ + KHR_DF_CHANNEL_YCGCOA_Y = 0U, + KHR_DF_CHANNEL_YCGCOA_CG = 1U, + KHR_DF_CHANNEL_YCGCOA_CO = 2U, + KHR_DF_CHANNEL_YCGCOA_ALPHA = 15U, + KHR_DF_CHANNEL_YCGCOA_A = 15U, + /* MODEL_CIEXYZ - CIE 1931 X, Y, Z */ + KHR_DF_CHANNEL_CIEXYZ_X = 0U, + KHR_DF_CHANNEL_CIEXYZ_Y = 1U, + KHR_DF_CHANNEL_CIEXYZ_Z = 2U, + /* MODEL_CIEXYY - CIE 1931 x, y, Y */ + KHR_DF_CHANNEL_CIEXYY_X = 0U, + KHR_DF_CHANNEL_CIEXYY_YCHROMA = 1U, + KHR_DF_CHANNEL_CIEXYY_YLUMA = 2U, + + /* Compressed formats */ + /* MODEL_DXT1A/MODEL_BC1A */ + KHR_DF_CHANNEL_DXT1A_COLOR = 0U, + KHR_DF_CHANNEL_BC1A_COLOR = 0U, + KHR_DF_CHANNEL_DXT1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_DXT1A_ALPHA = 1U, + KHR_DF_CHANNEL_BC1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_BC1A_ALPHA = 1U, + /* MODEL_DXT2/3/MODEL_BC2 */ + KHR_DF_CHANNEL_DXT2_COLOR = 0U, + KHR_DF_CHANNEL_DXT3_COLOR = 0U, + KHR_DF_CHANNEL_BC2_COLOR = 0U, + KHR_DF_CHANNEL_DXT2_ALPHA = 15U, + KHR_DF_CHANNEL_DXT3_ALPHA = 15U, + KHR_DF_CHANNEL_BC2_ALPHA = 15U, + /* MODEL_DXT4/5/MODEL_BC3 */ + KHR_DF_CHANNEL_DXT4_COLOR = 0U, + KHR_DF_CHANNEL_DXT5_COLOR = 0U, + KHR_DF_CHANNEL_BC3_COLOR = 0U, + KHR_DF_CHANNEL_DXT4_ALPHA = 15U, + KHR_DF_CHANNEL_DXT5_ALPHA = 15U, + KHR_DF_CHANNEL_BC3_ALPHA = 15U, + /* MODEL_BC4 */ + KHR_DF_CHANNEL_BC4_DATA = 0U, + /* MODEL_BC5 */ + KHR_DF_CHANNEL_BC5_RED = 0U, + KHR_DF_CHANNEL_BC5_R = 0U, + KHR_DF_CHANNEL_BC5_GREEN = 1U, + KHR_DF_CHANNEL_BC5_G = 1U, + /* MODEL_BC6H */ + KHR_DF_CHANNEL_BC6H_COLOR = 0U, + KHR_DF_CHANNEL_BC6H_DATA = 0U, + /* MODEL_BC7 */ + KHR_DF_CHANNEL_BC7_DATA = 0U, + KHR_DF_CHANNEL_BC7_COLOR = 0U, + /* MODEL_ETC1 */ + KHR_DF_CHANNEL_ETC1_DATA = 0U, + KHR_DF_CHANNEL_ETC1_COLOR = 0U, + /* MODEL_ETC2 */ + KHR_DF_CHANNEL_ETC2_RED = 0U, + KHR_DF_CHANNEL_ETC2_R = 0U, + KHR_DF_CHANNEL_ETC2_GREEN = 1U, + KHR_DF_CHANNEL_ETC2_G = 1U, + KHR_DF_CHANNEL_ETC2_COLOR = 2U, + KHR_DF_CHANNEL_ETC2_ALPHA = 15U, + KHR_DF_CHANNEL_ETC2_A = 15U, + /* MODEL_ASTC */ + KHR_DF_CHANNEL_ASTC_DATA = 0U, + /* MODEL_ETC1S */ + KHR_DF_CHANNEL_ETC1S_RGB = 0U, + KHR_DF_CHANNEL_ETC1S_RRR = 3U, + KHR_DF_CHANNEL_ETC1S_GGG = 4U, + KHR_DF_CHANNEL_ETC1S_AAA = 15U, + /* MODEL_PVRTC */ + KHR_DF_CHANNEL_PVRTC_DATA = 0U, + KHR_DF_CHANNEL_PVRTC_COLOR = 0U, + /* MODEL_PVRTC2 */ + KHR_DF_CHANNEL_PVRTC2_DATA = 0U, + KHR_DF_CHANNEL_PVRTC2_COLOR = 0U, + /* MODEL UASTC */ + KHR_DF_CHANNEL_UASTC_DATA = 0U, + KHR_DF_CHANNEL_UASTC_RGB = 0U, + KHR_DF_CHANNEL_UASTC_RGBA = 3U, + KHR_DF_CHANNEL_UASTC_RRR = 4U, + KHR_DF_CHANNEL_UASTC_RRRG = 5U, + KHR_DF_CHANNEL_UASTC_RG = 6U, + + /* Common channel names shared by multiple formats */ + KHR_DF_CHANNEL_COMMON_LUMA = 0U, + KHR_DF_CHANNEL_COMMON_L = 0U, + KHR_DF_CHANNEL_COMMON_STENCIL = 13U, + KHR_DF_CHANNEL_COMMON_S = 13U, + KHR_DF_CHANNEL_COMMON_DEPTH = 14U, + KHR_DF_CHANNEL_COMMON_D = 14U, + KHR_DF_CHANNEL_COMMON_ALPHA = 15U, + KHR_DF_CHANNEL_COMMON_A = 15U +} khr_df_model_channels_e; + +/** @~English + @brief Definition of the primary colors in color coordinates. + This is implicitly responsible for defining the conversion + between RGB an YUV color spaces. + LAB and related absolute color models should use + KHR_DF_PRIMARIES_CIEXYZ. */ +typedef enum _khr_df_primaries_e { + /** No color primaries defined */ + KHR_DF_PRIMARIES_UNSPECIFIED = 0U, + /** Color primaries of ITU-R BT.709 and sRGB */ + KHR_DF_PRIMARIES_BT709 = 1U, + /** Synonym for KHR_DF_PRIMARIES_BT709 */ + KHR_DF_PRIMARIES_SRGB = 1U, + /** Color primaries of ITU-R BT.601 (625-line EBU variant) */ + KHR_DF_PRIMARIES_BT601_EBU = 2U, + /** Color primaries of ITU-R BT.601 (525-line SMPTE C variant) */ + KHR_DF_PRIMARIES_BT601_SMPTE = 3U, + /** Color primaries of ITU-R BT.2020 */ + KHR_DF_PRIMARIES_BT2020 = 4U, + /** CIE theoretical color coordinate space */ + KHR_DF_PRIMARIES_CIEXYZ = 5U, + /** Academy Color Encoding System primaries */ + KHR_DF_PRIMARIES_ACES = 6U, + /** Color primaries of ACEScc */ + KHR_DF_PRIMARIES_ACESCC = 7U, + /** Legacy NTSC 1953 primaries */ + KHR_DF_PRIMARIES_NTSC1953 = 8U, + /** Legacy PAL 525-line primaries */ + KHR_DF_PRIMARIES_PAL525 = 9U, + /** Color primaries of Display P3 */ + KHR_DF_PRIMARIES_DISPLAYP3 = 10U, + /** Color primaries of Adobe RGB (1998) */ + KHR_DF_PRIMARIES_ADOBERGB = 11U, + KHR_DF_PRIMARIES_MAX = 0xFFU +} khr_df_primaries_e; + +/** @~English + @brief Definition of the optical to digital transfer function + ("gamma correction"). Most transfer functions are not a pure + power function and also include a linear element. + LAB and related absolute color representations should use + KHR_DF_TRANSFER_UNSPECIFIED. */ +typedef enum _khr_df_transfer_e { + /** No transfer function defined */ + KHR_DF_TRANSFER_UNSPECIFIED = 0U, + /** Linear transfer function (value proportional to intensity) */ + KHR_DF_TRANSFER_LINEAR = 1U, + /** Perceptually-linear transfer function of sRGH (~2.4) */ + KHR_DF_TRANSFER_SRGB = 2U, + /** Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45) */ + KHR_DF_TRANSFER_ITU = 3U, + /** SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) */ + KHR_DF_TRANSFER_SMTPE170M = 3U, + /** Perceptually-linear gamma function of original NTSC (simple 2.2 gamma) */ + KHR_DF_TRANSFER_NTSC = 4U, + /** Sony S-log used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG = 5U, + /** Sony S-log 2 used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG2 = 6U, + /** ITU BT.1886 EOTF */ + KHR_DF_TRANSFER_BT1886 = 7U, + /** ITU BT.2100 HLG OETF */ + KHR_DF_TRANSFER_HLG_OETF = 8U, + /** ITU BT.2100 HLG EOTF */ + KHR_DF_TRANSFER_HLG_EOTF = 9U, + /** ITU BT.2100 PQ EOTF */ + KHR_DF_TRANSFER_PQ_EOTF = 10U, + /** ITU BT.2100 PQ OETF */ + KHR_DF_TRANSFER_PQ_OETF = 11U, + /** DCI P3 transfer function */ + KHR_DF_TRANSFER_DCIP3 = 12U, + /** Legacy PAL OETF */ + KHR_DF_TRANSFER_PAL_OETF = 13U, + /** Legacy PAL 625-line EOTF */ + KHR_DF_TRANSFER_PAL625_EOTF = 14U, + /** Legacy ST240 transfer function */ + KHR_DF_TRANSFER_ST240 = 15U, + /** ACEScc transfer function */ + KHR_DF_TRANSFER_ACESCC = 16U, + /** ACEScct transfer function */ + KHR_DF_TRANSFER_ACESCCT = 17U, + /** Adobe RGB (1998) transfer function */ + KHR_DF_TRANSFER_ADOBERGB = 18U, + KHR_DF_TRANSFER_MAX = 0xFFU +} khr_df_transfer_e; + +typedef enum _khr_df_flags_e { + KHR_DF_FLAG_ALPHA_STRAIGHT = 0U, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1U +} khr_df_flags_e; + +typedef enum _khr_df_sample_datatype_qualifiers_e { + KHR_DF_SAMPLE_DATATYPE_LINEAR = 1U << 4U, + KHR_DF_SAMPLE_DATATYPE_EXPONENT = 1U << 5U, + KHR_DF_SAMPLE_DATATYPE_SIGNED = 1U << 6U, + KHR_DF_SAMPLE_DATATYPE_FLOAT = 1U << 7U +} khr_df_sample_datatype_qualifiers_e; + +#endif diff --git a/KTXLoader/libktx/ktx.xcframework/tvos-arm64/Headers/ktx.h b/KTXLoader/libktx/ktx.xcframework/tvos-arm64/Headers/ktx.h new file mode 100644 index 00000000..fd321c30 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/tvos-arm64/Headers/ktx.h @@ -0,0 +1,1835 @@ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + +#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1 +#define KTX_H_A55A6F00956F42F3A137C11929827FE1 + +/* + * Copyright 2010-2018 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + * + * See the accompanying LICENSE.md for licensing details for all files in + * the KTX library and KTX loader tests. + */ + +/** + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX API. + * + * @author Mark Callow, Edgewise Consulting and while at HI Corporation + * @author Based on original work by Georg Kolling, Imagination Technology + * + * @snippet{doc} version.h API version + */ + +#include +#include +#include + +#include + +/* + * Don't use khrplatform.h in order not to break apps existing + * before these definitions were needed. + */ +#if defined(KHRONOS_STATIC) + #define KTX_API +#elif defined(_WIN32) || defined(__CYGWIN__) + #if !defined(KTX_API) + #if __GNUC__ + #define KTX_API __attribute__ ((dllimport)) + #elif _MSC_VER + #define KTX_API __declspec(dllimport) + #else + #error "Your compiler's equivalent of dllimport is unknown" + #endif + #endif +#elif defined(__ANDROID__) + #define KTX_API __attribute__((visibility("default"))) +#else + #define KTX_API +#endif + +#if defined(_WIN32) && !defined(KHRONOS_STATIC) + #if !defined(KTX_APIENTRY) + #define KTX_APIENTRY __stdcall + #endif +#else + #define KTX_APIENTRY +#endif + +/* To avoid including define our own types. */ +typedef unsigned char ktx_uint8_t; +typedef bool ktx_bool_t; +#ifdef _MSC_VER +typedef unsigned __int16 ktx_uint16_t; +typedef signed __int16 ktx_int16_t; +typedef unsigned __int32 ktx_uint32_t; +typedef signed __int32 ktx_int32_t; +typedef size_t ktx_size_t; +typedef unsigned __int64 ktx_uint64_t; +typedef signed __int64 ktx_int64_t; +#else +#include +typedef uint16_t ktx_uint16_t; +typedef int16_t ktx_int16_t; +typedef uint32_t ktx_uint32_t; +typedef int32_t ktx_int32_t; +typedef size_t ktx_size_t; +typedef uint64_t ktx_uint64_t; +typedef int64_t ktx_int64_t; +#endif + +/* This will cause compilation to fail if size of uint32 != 4. */ +typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4]; + +/* + * This #if allows libktx to be compiled with strict c99. It avoids + * compiler warnings or even errors when a gl.h is already included. + * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if + * gl.h comes after. However nobody has complained about the unguarded typedefs + * since they were introduced so this is unlikely to be a problem in practice. + * Presumably everybody is using platform default compilers not c99 or else + * they are using C++. + */ +#if !defined(GL_NO_ERROR) + /* + * To avoid having to including gl.h ... + */ + typedef unsigned char GLboolean; + typedef unsigned int GLenum; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLuint; + typedef unsigned char GLubyte; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_ANIMDATA_KEY "KTXanimData" +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +#define KTX_ORIENTATION_KEY "KTXorientation" +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +#define KTX_SWIZZLE_KEY "KTXswizzle" +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_WRITER_KEY "KTXwriter" +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams" +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +#define KTX_ORIENTATION1_FMT "S=%c" +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +#define KTX_ORIENTATION2_FMT "S=%c,T=%c" +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c" +/** + * @~English + * @brief Required unpack alignment + */ +#define KTX_GL_UNPACK_ALIGNMENT 4 + +#define KTX_TRUE true +#define KTX_FALSE false + +/** + * @~English + * @brief Error codes returned by library functions. + */ +typedef enum ktx_error_code_e { + KTX_SUCCESS = 0, /*!< Operation was successful. */ + KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */ + KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */ + KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */ + KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */ + KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */ + KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */ + KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */ + KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */ + KTX_GL_ERROR, /*!< GL operations resulted in an error. */ + KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ + KTX_INVALID_VALUE, /*!< A parameter value was not valid */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ + KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ + KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ + KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ + KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */ + KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */ + KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */ + KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */ + KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */ + KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */ +} ktx_error_code_e; +/** + * @deprecated + * @~English + * @brief For backward compatibility + */ +#define KTX_error_code ktx_error_code_e + +#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } +#define KTX_ENDIAN_REF (0x04030201) +#define KTX_ENDIAN_REF_REV (0x01020304) +#define KTX_HEADER_SIZE (64) + +/** + * @~English + * @brief Result codes returned by library functions. + */ + typedef enum ktx_error_code_e ktxResult; + +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ +typedef struct ktxKVListEntry* ktxHashList; + +typedef struct ktxStream ktxStream; + +#define KTX_APIENTRYP KTX_APIENTRY * +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ +typedef struct ktxKVListEntry ktxHashListEntry; + +typedef enum ktxOrientationX { + KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r' +} ktxOrientationX; + +typedef enum ktxOrientationY { + KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd' +} ktxOrientationY; + +typedef enum ktxOrientationZ { + KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o' +} ktxOrientationZ; + +typedef enum class_id { + ktxTexture1_c = 1, + ktxTexture2_c = 2 +} class_id; + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +struct ktxOrientation { + ktxOrientationX x; /*!< Orientation in X */ + ktxOrientationY y; /*!< Orientation in Y */ + ktxOrientationZ z; /*!< Orientation in Z */ +}; + +#define KTXTEXTURECLASSDEFN \ + class_id classId; \ + struct ktxTexture_vtbl* vtbl; \ + struct ktxTexture_vvtbl* vvtbl; \ + struct ktxTexture_protected* _protected; \ + ktx_bool_t isArray; \ + ktx_bool_t isCubemap; \ + ktx_bool_t isCompressed; \ + ktx_bool_t generateMipmaps; \ + ktx_uint32_t baseWidth; \ + ktx_uint32_t baseHeight; \ + ktx_uint32_t baseDepth; \ + ktx_uint32_t numDimensions; \ + ktx_uint32_t numLevels; \ + ktx_uint32_t numLayers; \ + ktx_uint32_t numFaces; \ + struct ktxOrientation orientation; \ + ktxHashList kvDataHead; \ + ktx_uint32_t kvDataLen; \ + ktx_uint8_t* kvData; \ + ktx_size_t dataSize; \ + ktx_uint8_t* pData; + + +/** + * @class ktxTexture + * @~English + * @brief Base class representing a texture. + * + * ktxTextures should be created only by one of the provided + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture { + KTXTEXTURECLASSDEFN +} ktxTexture; +/** + * @typedef ktxTexture::classId + * @~English + * @brief Identify the class type. + * + * Since there are no public ktxTexture constructors, this can only have + * values of ktxTexture1_c or ktxTexture2_c. + */ +/** + * @typedef ktxTexture::vtbl + * @~English + * @brief Pointer to the class's vtble. + */ +/** + * @typedef ktxTexture::vvtbl + * @~English + * @brief Pointer to the class's vtble for Vulkan functions. + * + * A separate vtble is used so this header does not need to include vulkan.h. + */ +/** + * @typedef ktxTexture::_protected + * @~English + * @brief Opaque pointer to the class's protected variables. + */ +/** + * @typedef ktxTexture::isArray + * @~English + * + * KTX_TRUE if the texture is an array texture, i.e, + * a GL_TEXTURE_*_ARRAY target is to be used. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture is a cubemap or cubemap array. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture's format is a block compressed format. + */ +/** + * @typedef ktxTexture::generateMipmaps + * @~English + * + * KTX_TRUE if mipmaps should be generated for the texture by + * ktxTexture_GLUpload() or ktxTexture_VkUpload(). + */ +/**n + * @typedef ktxTexture::baseWidth + * @~English + * @brief Width of the texture's base level. + */ +/** + * @typedef ktxTexture::baseHeight + * @~English + * @brief Height of the texture's base level. + */ +/** + * @typedef ktxTexture::baseDepth + * @~English + * @brief Depth of the texture's base level. + */ +/** + * @typedef ktxTexture::numDimensions + * @~English + * @brief Number of dimensions in the texture: 1, 2 or 3. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of mip levels in the texture. + * + * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a + * full pyramid but always starts at the base level. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of array layers in the texture. + */ +/** + * @typedef ktxTexture::numFaces + * @~English + * @brief Number of faces: 6 for cube maps, 1 otherwise. + */ +/** + * @typedef ktxTexture::orientation + * @~English + * @brief Describes the logical orientation of the images in each dimension. + * + * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z. + */ +/** + * @typedef ktxTexture::kvDataHead + * @~English + * @brief Head of the hash list of metadata. + */ +/** + * @typedef ktxTexture::kvDataLen + * @~English + * @brief Length of the metadata, if it has been extracted in its raw form, + * otherwise 0. + */ +/** + * @typedef ktxTexture::kvData + * @~English + * @brief Pointer to the metadata, if it has been extracted in its raw form, + * otherwise NULL. + */ +/** + * @typedef ktxTexture::dataSize + * @~English + * @brief Byte length of the texture's uncompressed image data. + */ +/** + * @typedef ktxTexture::pData + * @~English + * @brief Pointer to the start of the image data. + */ + +/** + * @memberof ktxTexture + * @~English + * @brief Signature of function called by the ktxTexture_Iterate* + * functions to receive image data. + * + * The function parameters are used to pass values which change for each image. + * Obtain values which are uniform across all images from the @c ktxTexture + * object. + * + * @param [in] miplevel MIP level from 0 to the max level which is + * dependent on the texture size. + * @param [in] face usually 0; for cube maps, one of the 6 cube + * faces in the order +X, -X, +Y, -Y, +Z, -Z, + * 0 to 5. + * @param [in] width width of the image. + * @param [in] height height of the image or, for 1D textures + * textures, 1. + * @param [in] depth depth of the image or, for 1D & 2D + * textures, 1. + * @param [in] faceLodSize number of bytes of data pointed at by + * @p pixels. + * @param [in] pixels pointer to the image data. + * @param [in,out] userdata pointer for the application to pass data to and + * from the callback function. + */ + +typedef KTX_error_code + (* PFNKTXITERCB)(int miplevel, int face, + int width, int height, int depth, + ktx_uint64_t faceLodSize, + void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + ktx_size_t* pOffset); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This, + PFNKTXITERCB iterCb, + void* userdata); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This, + ktx_uint8_t* pBuffer, + ktx_size_t bufSize); +typedef ktx_bool_t + (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + const ktx_uint8_t* src, + ktx_size_t srcSize); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + FILE* src, ktx_size_t srcSize); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This, + const char* const dstname); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, + ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + struct ktxTexture_vtbl { + PFNKTEXDESTROY Destroy; + PFNKTEXGETIMAGEOFFSET GetImageOffset; + PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + PFNKTEXGETIMAGESIZE GetImageSize; + PFNKTEXITERATELEVELS IterateLevels; + PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + PFNKTEXLOADIMAGEDATA LoadImageData; + PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; +}; + +/**************************************************************** + * Macros to give some backward compatibility to the previous API + ****************************************************************/ + +/** + * @~English + * @brief Helper for calling the Destroy virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_Destroy + */ +#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This) + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \ + (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset) + +/** + * @~English + * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture. + * + * For a ktxTexture1 this will always return the value of This->dataSize. + * + * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed + */ +#define ktxTexture_GetDataSizeUncompressed(This) \ + (This)->vtbl->GetDataSizeUncompressed(This) + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +#define ktxTexture_GetImageSize(This, level) \ + (This)->vtbl->GetImageSize(This, level) + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +#define ktxTexture_IterateLevels(This, iterCb, userdata) \ + (This)->vtbl->IterateLevels(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \ + (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \ + (This)->vtbl->LoadImageData(This, pBuffer, bufSize) + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This) + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize) + +/** + * @~English + * @brief Helper for calling the SetImageFromStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream + */ +#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) + +/** + * @~English + * @brief Helper for calling the WriteToStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream + */ +#define ktxTexture_WriteToStdioStream(This, dstsstr) \ + (This)->vtbl->WriteToStdioStream(This, dstsstr) + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +#define ktxTexture_WriteToNamedFile(This, dstname) \ + (This)->vtbl->WriteToNamedFile(This, dstname) + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ + (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + + +/** + * @class ktxTexture1 + * @~English + * @brief Class representing a KTX version 1 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture1 { + KTXTEXTURECLASSDEFN + ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + struct ktxTexture1_private* _private; /*!< Private data. */ +} ktxTexture1; + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +typedef enum ktxSupercmpScheme { + KTX_SS_NONE = 0, /*!< No supercompression. */ + KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */ + KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */ + KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */ + KTX_SS_BEGIN_RANGE = KTX_SS_NONE, + KTX_SS_END_RANGE = KTX_SS_ZLIB, + KTX_SS_BEGIN_VENDOR_RANGE = 0x10000, + KTX_SS_END_VENDOR_RANGE = 0x1ffff, + KTX_SS_BEGIN_RESERVED = 0x20000, + KTX_SUPERCOMPRESSION_BASIS = KTX_SS_BASIS_LZ, + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_BASIS_LZ instead. */ + KTX_SUPERCOMPRESSION_ZSTD = KTX_SS_ZSTD + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_ZSTD instead. */ +} ktxSupercmpScheme; + +/** + * @class ktxTexture2 + * @~English + * @brief Class representing a KTX version 2 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture2 { + KTXTEXTURECLASSDEFN + ktx_uint32_t vkFormat; + ktx_uint32_t* pDfd; + ktxSupercmpScheme supercompressionScheme; + ktx_bool_t isVideo; + ktx_uint32_t duration; + ktx_uint32_t timescale; + ktx_uint32_t loopcount; + struct ktxTexture2_private* _private; /*!< Private data. */ +} ktxTexture2; + +#define ktxTexture(t) ((ktxTexture*)t) + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1_Create() and + * ktxTexture2_Create(). + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef struct +{ + ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an + array texture. Means OpenGL will use a + GL_TEXTURE_*_ARRAY target. */ + ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} ktxTextureCreateInfo; + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef enum { + KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */ + KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */ +} ktxTextureCreateStorageEnum; + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +enum ktxTextureCreateFlagBits { + KTX_TEXTURE_CREATE_NO_FLAGS = 0x00, + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01, + /*!< Load the images from the KTX source. */ + KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08 + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +}; +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +typedef ktx_uint32_t ktxTextureCreateFlags; + +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + ktxStream_write write; /*!< pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< destruct the stream. */ + + enum streamType type; + union { + FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + struct + { + void* address; /**< pointer to the data. */ + void* allocatorAddress; /**< pointer to a memory allocator. */ + ktx_size_t size; /**< size of the data. */ + } custom_ptr; /**< pointer to a struct for custom streams. */ + } data; /**< pointer to the stream data. */ + ktx_off_t readpos; /**< used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +}; + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ +KTX_API ktx_uint8_t* KTX_APIENTRY +ktxTexture_GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ +KTX_API ktx_size_t KTX_APIENTRY +ktxTexture_GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, + GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); +/* + * Create a new ktxTexture1. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture1_NeedsTranscoding(ktxTexture1* This); + +/* + * Write a ktxTexture object to a stdio stream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + +/* + * Write a ktxTexture object to a named file in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname); + +/* + * Write a ktxTexture object to a block of memory in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, + ktx_uint8_t** bytes, ktx_size_t* size); + +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + +/* + * Create a new ktxTexture2. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + +KTX_API void KTX_APIENTRY +ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, + ktx_uint32_t* componentByteLength); + +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetNumComponents(ktxTexture2* This); + +KTX_API khr_df_transfer_e KTX_APIENTRY +ktxTexture2_GetOETF_e(ktxTexture2* This); + +// For backward compatibility +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetOETF(ktxTexture2* This); + +KTX_API khr_df_model_e KTX_APIENTRY +ktxTexture2_GetColorModel_e(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_NeedsTranscoding(ktxTexture2* This); + +/** + * @~English + * @brief Flags specifiying UASTC encoding options. + */ +typedef enum ktx_pack_uastc_flag_bits_e { + KTX_PACK_UASTC_LEVEL_FASTEST = 0, + /*!< Fastest compression. 43.45dB. */ + KTX_PACK_UASTC_LEVEL_FASTER = 1, + /*!< Faster compression. 46.49dB. */ + KTX_PACK_UASTC_LEVEL_DEFAULT = 2, + /*!< Default compression. 47.47dB. */ + KTX_PACK_UASTC_LEVEL_SLOWER = 3, + /*!< Slower compression. 48.01dB. */ + KTX_PACK_UASTC_LEVEL_VERYSLOW = 4, + /*!< Very slow compression. 48.24dB. */ + KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW, + /*!< Maximum supported quality level. */ + KTX_PACK_UASTC_LEVEL_MASK = 0xF, + /*!< Mask to extract the level from the other bits. */ + KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8, + /*!< Optimize for lowest UASTC error. */ + KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16, + /*!< Optimize for lowest BC7 error. */ + KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64, + /*!< Optimize for faster transcoding to ETC1. */ + KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128, + /*!< Optimize for fastest transcoding to ETC1. */ + KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256 + /*!< Not documented in BasisU code. */ +} ktx_pack_uastc_flag_bits_e; +typedef ktx_uint32_t ktx_pack_uastc_flags; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +typedef enum ktx_pack_astc_quality_levels_e { + KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0, + /*!< Fastest compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10, + /*!< Fast compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60, + /*!< Medium compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98, + /*!< Slower compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100, + /*!< Very slow compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE, + /*!< Maximum supported quality level. */ +} ktx_pack_astc_quality_levels_e; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +typedef enum ktx_pack_astc_block_dimension_e { + // 2D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp + // 3D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6 + /*!< Maximum supported blocks. */ +} ktx_pack_astc_block_dimension_e; + +/** + * @~English + * @brief Options specifying ASTC encoder profile mode + * This and function is used later to derive the profile. + */ +typedef enum ktx_pack_astc_encoder_mode_e { + KTX_PACK_ASTC_ENCODER_MODE_DEFAULT, + KTX_PACK_ASTC_ENCODER_MODE_LDR, + KTX_PACK_ASTC_ENCODER_MODE_HDR, + KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR +} ktx_pack_astc_encoder_mode_e; + +extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture_CompressAstc. + * + * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension + * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to + * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended. + */ +typedef struct ktxAstcParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + ktx_uint32_t qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps + In this mode normals are compressed to X,Y components + Discarding Z component, reader will need to generate Z + component in shaders. + */ + + ktx_bool_t perceptual; + /*!< The codec should optimize for perceptual error, instead of direct + RMS error. This aims to improves perceived image quality, but + typically lowers the measured PSNR score. Perceptual methods are + currently only available for normal maps and RGB color data. + */ + + char inputSwizzle[4]; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} ktxAstcParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + +/** + * @memberof ktxTexture2 + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture2_CompressBasisEx(). + * + * If you only want default values, use ktxTexture2_CompressBasis(). Here, at a minimum you + * must initialize the structure as follows: + * @code + * ktxBasisParams params = {0}; + * params.structSize = sizeof(params); + * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e compressionLevel has to be explicitly set because 0 is a valid @e compressionLevel + * but is not the default used by the BasisU encoder when no value is set. Only the other + * settings that are to be non-default must be non-zero. + */ +typedef struct ktxBasisParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + ktx_bool_t uastc; + /*!< True to use UASTC base, false to use ETC1S base. */ + ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + ktx_uint32_t compressionLevel; + /*!< Encoding speed vs. quality tradeoff. Range is [0,5]. Higher values + are slower, but give higher quality. There is no default. Callers + must explicitly set this value. Callers can use + KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL as a default value. + Currently this is 2. + */ + ktx_uint32_t qualityLevel; + /*!< Compression quality. Range is [1,255]. Lower gives better + compression/lower quality/faster. Higher gives less compression + /higher quality/slower. This automatically determines values for + @c maxEndpoints, @c maxSelectors, + @c endpointRDOThreshold and @c selectorRDOThreshold + for the target quality level. Setting these parameters overrides + the values determined by @c qualityLevel which defaults to + 128 if neither it nor both of @c maxEndpoints and + @c maxSelectors have been set. + @note @e Both of @c maxEndpoints and @c maxSelectors + must be set for them to have any effect. + @note qualityLevel will only determine values for + @c endpointRDOThreshold and @c selectorRDOThreshold + when its value exceeds 128, otherwise their defaults will be used. + */ + ktx_uint32_t maxEndpoints; + /*!< Manually set the max number of color endpoint clusters. + Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors + must also be set, otherwise the value will be ignored. + */ + float endpointRDOThreshold; + /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is + higher quality but less quality per output bit (try [1.0,3.0]. + This will override the value chosen by @c qualityLevel. + */ + ktx_uint32_t maxSelectors; + /*!< Manually set the max number of color selector clusters. Range + is [1,16128]. Default is 0, unset. If this is set, maxEndpoints + must also be set, otherwise the value will be ignored. + */ + float selectorRDOThreshold; + /*!< Set selector RDO quality threshold. The default is 1.5. Lower is + higher quality but less quality per output bit (try [1.0,3.0]). + This will override the value chosen by @c qualityLevel. + */ + char inputSwizzle[4]; + /*!< A swizzle to apply before encoding. It must match the regular + expression /^[rgba01]{4}$/. If both this and preSwizzle + are specified ktxTexture_CompressBasisEx will raise + KTX_INVALID_OPERATION. + */ + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps (no + selector RDO, no endpoint RDO) and sets the texture's DFD appropriately. + Only valid for linear textures. + */ + ktx_bool_t separateRGToRGB_A; + /*!< @deprecated. This was and is a no-op. 2-component inputs have always been + automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode. + */ + ktx_bool_t preSwizzle; + /*!< If the texture has @c KTXswizzle metadata, apply it before + compressing. Swizzling, like @c rabb may yield drastically + different error metrics if done after supercompression. + */ + ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + ktx_bool_t noSelectorRDO; + /*!< Disable selector rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + + /* UASTC params */ + + ktx_pack_uastc_flags uastcFlags; + /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC + encoding. The most important value is the level given in the + least-significant 4 bits which selects a speed vs quality tradeoff + as shown in the following table: + + Level/Speed | Quality + :-----: | :-------: + KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB + KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB + KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB + KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB + KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB + */ + ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + float uastcRDOQualityScalar; + /*!< UASTC RDO quality scalar (lambda). Lower values yield higher + quality/larger LZ compressed files, higher values yield lower + quality/smaller LZ compressed files. A good range to try is [.2,4]. + Full range is [.001,50.0]. Default is 1.0. + */ + ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + float uastcRDOMaxSmoothBlockErrorScale; + /*!< UASTC RDO max smooth block error scale. Range is [1,300]. + Default is 10.0, 1.0 is disabled. Larger values suppress more + artifacts (and allocate more bits) on smooth blocks. + */ + float uastcRDOMaxSmoothBlockStdDev; + /*!< UASTC RDO max smooth block standard deviation. Range is + [.01,65536.0]. Default is 18.0. Larger values expand the range of + blocks considered smooth. + */ + ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + +} ktxBasisParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params); + +/** + * @~English + * @brief Enumerators for specifying the transcode target format. + * + * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate + * RGB images, a.k.a slices within the BasisU compressed data. For UASTC + * format they refer to the RGB and the alpha components of the UASTC data. If + * the original image had only 2 components, R will be in the opaque portion + * and G in the alpha portion. The R value will be replicated in the RGB + * components. In the case of BasisU the G value will be replicated in all 3 + * components of the alpha slice. If the original image had only 1 component + * it's value is replicated in all 3 components of the opaque portion and + * there is no alpha. + * + * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R, + * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565, + * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor + * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader + * will not produce correct results if any texture filtering is being used. + */ +typedef enum ktx_transcode_fmt_e { + // Compressed formats + + // ETC1-2 + KTX_TTF_ETC1_RGB = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_RGBA = 1, + /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + + // BC1-5, BC7 (desktop, some mobile devices) + KTX_TTF_BC1_RGB = 2, + /*!< Opaque only, no punchthrough alpha support yet. Returns RGB + or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS + flag is specified. */ + KTX_TTF_BC3_RGBA = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + KTX_TTF_BC4_R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_BC5_RG = 5, + /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should + have an alpha channel (if not G will be all 255's. For tangent + space normal maps. */ + KTX_TTF_BC7_RGBA = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + KTX_TTF_PVRTC1_4_RGB = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_PVRTC1_4_RGBA = 9, + /*!< Opaque+alpha. Most useful for simple opacity maps. If the + texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB + will be used instead. Lowest quality of any supported + texture format. */ + + // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day) + KTX_TTF_ASTC_4x4_RGBA = 10, + /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for + textures without an alpha channel. The transcoder uses + RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and + [0,255]) endpoint precisions. */ + + // ATC and FXT1 formats are not supported by KTX2 as there + // are no equivalent VkFormats. + + KTX_TTF_PVRTC2_4_RGB = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + KTX_TTF_PVRTC2_4_RGBA = 19, + /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB. + Premultiplied alpha is highly recommended, otherwise the + color channel can leak into the alpha channel on transparent + blocks. */ + + KTX_TTF_ETC2_EAC_R11 = 20, + /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_EAC_RG11 = 21, + /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The + texture should have an alpha channel (if not G will be all + 255's. For tangent space normal maps. */ + + // Uncompressed (raw pixel) formats + KTX_TTF_RGBA32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + KTX_TTF_RGB565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + KTX_TTF_BGR565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + KTX_TTF_RGBA4444 = 16, + /*!< 16bpp RGBA image stored in raster (not block) order in memory, + R at bit position 12, A at bit position 0. */ + + // Values for automatic selection of RGB or RGBA depending if alpha + // present. + KTX_TTF_ETC = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + KTX_TTF_BC1_OR_3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + KTX_TTF_NOSELECTION = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + KTX_TF_ETC1 = KTX_TTF_ETC1_RGB, + //!< @deprecated. Use #KTX_TTF_ETC1_RGB. + KTX_TF_ETC2 = KTX_TTF_ETC, + //!< @deprecated. Use #KTX_TTF_ETC. + KTX_TF_BC1 = KTX_TTF_BC1_RGB, + //!< @deprecated. Use #KTX_TTF_BC1_RGB. + KTX_TF_BC3 = KTX_TTF_BC3_RGBA, + //!< @deprecated. Use #KTX_TTF_BC3_RGBA. + KTX_TF_BC4 = KTX_TTF_BC4_R, + //!< @deprecated. Use #KTX_TTF_BC4_R. + KTX_TF_BC5 = KTX_TTF_BC5_RG, + //!< @deprecated. Use #KTX_TTF_BC5_RG. + KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA + KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB + //!< @deprecated. Use #KTX_TTF_PVRTC1_4_RGB. +} ktx_transcode_fmt_e; + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +typedef enum ktx_transcode_flag_bits_e { + KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2, + /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger + power of 2 (not implemented yet, but we're going to support it). + Ignored if the slice's dimensions are already a power of 2. + */ + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4, + /*!< When decoding to an opaque texture format, if the Basis data has + alpha, decode the alpha slice instead of the color slice to the + output texture format. Has no effect if there is no alpha data. + */ + KTX_TF_HIGH_QUALITY = 32, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} ktx_transcode_flag_bits_e; +typedef ktx_uint32_t ktx_transcode_flags; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, + ktx_transcode_flags transcodeFlags); + +/* + * Returns a string corresponding to a KTX error code. + */ +KTX_API const char* KTX_APIENTRY +ktxErrorString(KTX_error_code error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ +KTX_API const char* KTX_APIENTRY +ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ +KTX_API const char* KTX_APIENTRY +ktxTranscodeFormatString(ktx_transcode_fmt_e format); + +KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl); +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl); +KTX_API void KTX_APIENTRY +ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head); +KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_AddKVPair(ktxHashList* pHead, const char* key, + unsigned int valueLen, const void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindEntry(ktxHashList* pHead, const char* key, + ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindValue(ktxHashList* pHead, const char* key, + unsigned int* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ +KTX_API ktxHashListEntry* KTX_APIENTRY +ktxHashList_Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Serialize(ktxHashList* pHead, + unsigned int* kvdLen, unsigned char** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd); + +/* + * Get the key from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetKey(ktxHashListEntry* This, + unsigned int* pKeyLen, char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetValue(ktxHashListEntry* This, + unsigned int* pValueLen, void** ppValue); + +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX2 file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); + +#ifdef __cplusplus +} +#endif + +/*========================================================================* + * For backward compatibilty with the V3 & early versions of the V4 APIs. * + *========================================================================*/ + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_transcode_fmt_e ktx_transcode_fmt_e + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_decode_flags ktx_transcode_flag_bits + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktxTexture_GetSize ktxTexture_GetDatasize + +/** +@~English +@page libktx_history Revision History + +No longer updated. Kept to preserve ancient history. For more recent history see the repo log at +https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo. + +@section v8 Version 4.0 +Added: +@li Support for KTX Version 2. +@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files. +@li Function to print info about a KTX file. + +@section v7 Version 3.0.1 +Fixed: +@li GitHub issue #159: compile failure with recent Vulkan SDKs. +@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents. +@li Incorrect BC4 blocksize. +@li Missing mapping of PVRTC formats from GL to Vulkan. +@li Incorrect block width and height calculations for sizes that are not + a multiple of the block size. +@li Incorrect KTXorientation key in test images. + +@section v6 Version 3.0 +Added: +@li new ktxTexture object based API for reading KTX files without an OpenGL context. +@li Vulkan loader. @#include to use it. + +Changed: +@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h. + Applications using OpenGL must now include these files themselves. +@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures + when the OpenGL context does not support 1D textures. + KTX_UNSUPPORTED_TEXTURE_TYPE is now returned. + +@section v5 Version 2.0.2 +Added: +@li Support for cubemap arrays. + +Changed: +@li New build system + +Fixed: +@li GitHub issue #40: failure to byte-swap key-value lengths. +@li GitHub issue #33: returning incorrect target when loading cubemaps. +@li GitHub PR #42: loading of texture arrays. +@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined. +@li GitHub issue #39: stack-buffer-overflow in toktx +@li Don't use GL_EXTENSIONS on recent OpenGL versions. + +@section v4 Version 2.0.1 +Added: +@li CMake build files. Thanks to Pavel Rotjberg for the initial version. + +Changed: +@li ktxWriteKTXF to check the validity of the type & format combinations + passed to it. + +Fixed: +@li Public Bugzilla 999: 16-bit luminance texture cannot be written. +@li compile warnings from compilers stricter than MS Visual C++. Thanks to + Pavel Rotjberg. + +@section v3 Version 2.0 +Added: +@li support for decoding ETC2 and EAC formats in the absence of a hardware + decoder. +@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA, + etc. formats to the equivalent R, RG, etc. format with an + appropriate swizzle, when loading in OpenGL Core Profile contexts. +@li ktxErrorString function to return a string corresponding to an error code. +@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3. + The latter includes an EGL on WGL wrapper that makes porting apps between + OpenGL ES and OpenGL easier on Windows. +@li more texture formats to ktxLoadTexture[FN] and toktx tests. + +Changed: +@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at + run time and load textures, or not, according to those capabilities. + +Fixed: +@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX + format. +@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write + more than 1 byte of face-LOD padding. + +Although there is only a very minor API change, the addition of ktxErrorString, +the functional changes are large enough to justify bumping the major revision +number. + +@section v2 Version 1.0.1 +Implemented ktxLoadTextureM. +Fixed the following: +@li Public Bugzilla 571: crash when null passed for pIsMipmapped. +@li Public Bugzilla 572: memory leak when unpacking ETC textures. +@li Public Bugzilla 573: potential crash when unpacking ETC textures with unused padding pixels. +@li Public Bugzilla 576: various small fixes. + +Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes. + +@section v1 Version 1.0 +Initial release. + +*/ + +#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ diff --git a/KTXLoader/libktx/ktx.xcframework/tvos-arm64/libktx.a b/KTXLoader/libktx/ktx.xcframework/tvos-arm64/libktx.a new file mode 100644 index 00000000..f5581d76 Binary files /dev/null and b/KTXLoader/libktx/ktx.xcframework/tvos-arm64/libktx.a differ diff --git a/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/Headers/KHR/khr_df.h b/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/Headers/KHR/khr_df.h new file mode 100644 index 00000000..c0d03aa7 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/Headers/KHR/khr_df.h @@ -0,0 +1,630 @@ +/* The Khronos Data Format Specification (version 1.3) */ +/* +** Copyright 2015-2020 The Khronos Group Inc. +** SPDX-License-Identifier: Apache-2.0 +*/ + +/* This header defines a structure that can describe the layout of image + formats in memory. This means that the data format is transparent to + the application, and the expectation is that this should be used when + the layout is defined external to the API. Many Khronos APIs deliberately + keep the internal layout of images opaque, to allow proprietary layouts + and optimisations. This structure is not appropriate for describing + opaque layouts. */ + +/* We stick to standard C89 constructs for simplicity and portability. */ + +#ifndef _KHR_DATA_FORMAT_H_ +#define _KHR_DATA_FORMAT_H_ + +/** @file khr_df.h + + @brief Data Format enums and macros. +*/ + +/* Accessors */ +typedef enum _khr_word_e { + KHR_DF_WORD_VENDORID = 0U, + KHR_DF_WORD_DESCRIPTORTYPE = 0U, + KHR_DF_WORD_VERSIONNUMBER = 1U, + KHR_DF_WORD_DESCRIPTORBLOCKSIZE = 1U, + KHR_DF_WORD_MODEL = 2U, + KHR_DF_WORD_PRIMARIES = 2U, + KHR_DF_WORD_TRANSFER = 2U, + KHR_DF_WORD_FLAGS = 2U, + KHR_DF_WORD_TEXELBLOCKDIMENSION0 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION1 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION2 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION3 = 3U, + KHR_DF_WORD_BYTESPLANE0 = 4U, + KHR_DF_WORD_BYTESPLANE1 = 4U, + KHR_DF_WORD_BYTESPLANE2 = 4U, + KHR_DF_WORD_BYTESPLANE3 = 4U, + KHR_DF_WORD_BYTESPLANE4 = 5U, + KHR_DF_WORD_BYTESPLANE5 = 5U, + KHR_DF_WORD_BYTESPLANE6 = 5U, + KHR_DF_WORD_BYTESPLANE7 = 5U, + KHR_DF_WORD_SAMPLESTART = 6U, + KHR_DF_WORD_SAMPLEWORDS = 4U +} khr_df_word_e; + +typedef enum _khr_df_shift_e { + KHR_DF_SHIFT_VENDORID = 0U, + KHR_DF_SHIFT_DESCRIPTORTYPE = 17U, + KHR_DF_SHIFT_VERSIONNUMBER = 0U, + KHR_DF_SHIFT_DESCRIPTORBLOCKSIZE = 16U, + KHR_DF_SHIFT_MODEL = 0U, + KHR_DF_SHIFT_PRIMARIES = 8U, + KHR_DF_SHIFT_TRANSFER = 16U, + KHR_DF_SHIFT_FLAGS = 24U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION0 = 0U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION1 = 8U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION2 = 16U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION3 = 24U, + KHR_DF_SHIFT_BYTESPLANE0 = 0U, + KHR_DF_SHIFT_BYTESPLANE1 = 8U, + KHR_DF_SHIFT_BYTESPLANE2 = 16U, + KHR_DF_SHIFT_BYTESPLANE3 = 24U, + KHR_DF_SHIFT_BYTESPLANE4 = 0U, + KHR_DF_SHIFT_BYTESPLANE5 = 8U, + KHR_DF_SHIFT_BYTESPLANE6 = 16U, + KHR_DF_SHIFT_BYTESPLANE7 = 24U +} khr_df_shift_e; + +typedef enum _khr_df_mask_e { + KHR_DF_MASK_VENDORID = 0x1FFFFU, + KHR_DF_MASK_DESCRIPTORTYPE = 0x7FFFU, + KHR_DF_MASK_VERSIONNUMBER = 0xFFFFU, + KHR_DF_MASK_DESCRIPTORBLOCKSIZE = 0xFFFFU, + KHR_DF_MASK_MODEL = 0xFFU, + KHR_DF_MASK_PRIMARIES = 0xFFU, + KHR_DF_MASK_TRANSFER = 0xFFU, + KHR_DF_MASK_FLAGS = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION0 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION1 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION2 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE0 = 0xFFU, + KHR_DF_MASK_BYTESPLANE1 = 0xFFU, + KHR_DF_MASK_BYTESPLANE2 = 0xFFU, + KHR_DF_MASK_BYTESPLANE3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE4 = 0xFFU, + KHR_DF_MASK_BYTESPLANE5 = 0xFFU, + KHR_DF_MASK_BYTESPLANE6 = 0xFFU, + KHR_DF_MASK_BYTESPLANE7 = 0xFFU +} khr_df_mask_e; + +/* Helper macro: + Extract field X from basic descriptor block BDB */ +#define KHR_DFDVAL(BDB, X) \ + (((BDB)[KHR_DF_WORD_ ## X] >> (KHR_DF_SHIFT_ ## X)) \ + & (KHR_DF_MASK_ ## X)) + +/* Helper macro: + Set field X of basic descriptor block BDB */ +#define KHR_DFDSETVAL(BDB, X, val) \ + ((BDB)[KHR_DF_WORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_ ## X] & \ + ~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \ + (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X))) + +/* Offsets relative to the start of a sample */ +typedef enum _khr_df_sampleword_e { + KHR_DF_SAMPLEWORD_BITOFFSET = 0U, + KHR_DF_SAMPLEWORD_BITLENGTH = 0U, + KHR_DF_SAMPLEWORD_CHANNELID = 0U, + KHR_DF_SAMPLEWORD_QUALIFIERS = 0U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION0 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION1 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION2 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION3 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL = 1U, + KHR_DF_SAMPLEWORD_SAMPLELOWER = 2U, + KHR_DF_SAMPLEWORD_SAMPLEUPPER = 3U +} khr_df_sampleword_e; + +typedef enum _khr_df_sampleshift_e { + KHR_DF_SAMPLESHIFT_BITOFFSET = 0U, + KHR_DF_SAMPLESHIFT_BITLENGTH = 16U, + KHR_DF_SAMPLESHIFT_CHANNELID = 24U, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLESHIFT_QUALIFIERS = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION0 = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION1 = 8U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION2 = 16U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION3 = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION_ALL = 0U, + KHR_DF_SAMPLESHIFT_SAMPLELOWER = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEUPPER = 0U +} khr_df_sampleshift_e; + +typedef enum _khr_df_samplemask_e { + KHR_DF_SAMPLEMASK_BITOFFSET = 0xFFFFU, + KHR_DF_SAMPLEMASK_BITLENGTH = 0xFF, + KHR_DF_SAMPLEMASK_CHANNELID = 0xF, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLEMASK_QUALIFIERS = 0xF0, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION0 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION1 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION2 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION3 = 0xFF, + /* ISO C restricts enum values to range of int hence the + cast. We do it verbosely instead of using -1 to ensure + it is a 32-bit value even if int is 64 bits. */ + KHR_DF_SAMPLEMASK_SAMPLEPOSITION_ALL = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLELOWER = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLEUPPER = (int) 0xFFFFFFFFU +} khr_df_samplemask_e; + +/* Helper macro: + Extract field X of sample S from basic descriptor block BDB */ +#define KHR_DFDSVAL(BDB, S, X) \ + (((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] >> (KHR_DF_SAMPLESHIFT_ ## X)) \ + & (KHR_DF_SAMPLEMASK_ ## X)) + +/* Helper macro: + Set field X of sample S of basic descriptor block BDB */ +#define KHR_DFDSETSVAL(BDB, S, X, val) \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] & \ + ~((uint32_t)(KHR_DF_SAMPLEMASK_ ## X) << (KHR_DF_SAMPLESHIFT_ ## X))) | \ + (((val) & (uint32_t)(KHR_DF_SAMPLEMASK_ ## X)) << (KHR_DF_SAMPLESHIFT_ ## X))) + +/* Helper macro: + Number of samples in basic descriptor block BDB */ +#define KHR_DFDSAMPLECOUNT(BDB) \ + (((KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) >> 2) - \ + KHR_DF_WORD_SAMPLESTART) \ + / KHR_DF_WORD_SAMPLEWORDS) + +/* Helper macro: + Size in words of basic descriptor block for S samples */ +#define KHR_DFDSIZEWORDS(S) \ + (KHR_DF_WORD_SAMPLESTART + \ + (S) * KHR_DF_WORD_SAMPLEWORDS) + +/* Vendor ids */ +typedef enum _khr_df_vendorid_e { + /* Standard Khronos descriptor */ + KHR_DF_VENDORID_KHRONOS = 0U, + KHR_DF_VENDORID_MAX = 0x1FFFFU +} khr_df_vendorid_e; + +/* Descriptor types */ +typedef enum _khr_df_khr_descriptortype_e { + /* Default Khronos basic descriptor block */ + KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0U, + /* Extension descriptor block for additional planes */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_PLANES = 0x6001U, + /* Extension descriptor block for additional dimensions */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_DIMENSIONS = 0x6002U, + /* Bit indicates modifying requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_WRITE_BIT = 0x2000U, + /* Bit indicates processing requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_DECODE_BIT = 0x4000U, + KHR_DF_KHR_DESCRIPTORTYPE_MAX = 0x7FFFU +} khr_df_khr_descriptortype_e; + +/* Descriptor block version */ +typedef enum _khr_df_versionnumber_e { + /* Standard Khronos descriptor */ + KHR_DF_VERSIONNUMBER_1_0 = 0U, /* Version 1.0 of the specification */ + KHR_DF_VERSIONNUMBER_1_1 = 0U, /* Version 1.1 did not bump the version number */ + KHR_DF_VERSIONNUMBER_1_2 = 1U, /* Version 1.2 increased the version number */ + KHR_DF_VERSIONNUMBER_1_3 = 2U, /* Version 1.3 increased the version number */ + KHR_DF_VERSIONNUMBER_LATEST = KHR_DF_VERSIONNUMBER_1_3, + KHR_DF_VERSIONNUMBER_MAX = 0xFFFFU +} khr_df_versionnumber_e; + +/** @~English + @brief Model in which the color coordinate space is defined. + There is no requirement that a color format use all the + channel types that are defined in the color model. */ +typedef enum _khr_df_model_e { + /** No interpretation of color channels defined */ + KHR_DF_MODEL_UNSPECIFIED = 0U, + /** Color primaries (red, green, blue) + alpha, depth and stencil */ + KHR_DF_MODEL_RGBSDA = 1U, + /** Color differences (Y', Cb, Cr) + alpha, depth and stencil */ + KHR_DF_MODEL_YUVSDA = 2U, + /** Color differences (Y', I, Q) + alpha, depth and stencil */ + KHR_DF_MODEL_YIQSDA = 3U, + /** Perceptual color (CIE L*a*b*) + alpha, depth and stencil */ + KHR_DF_MODEL_LABSDA = 4U, + /** Subtractive colors (cyan, magenta, yellow, black) + alpha */ + KHR_DF_MODEL_CMYKA = 5U, + /** Non-color coordinate data (X, Y, Z, W) */ + KHR_DF_MODEL_XYZW = 6U, + /** Hue, saturation, value, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSVA_ANG = 7U, + /** Hue, saturation, lightness, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSLA_ANG = 8U, + /** Hue, saturation, value, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSVA_HEX = 9U, + /** Hue, saturation, lightness, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSLA_HEX = 10U, + /** Lightweight approximate color difference (luma, orange, green) */ + KHR_DF_MODEL_YCGCOA = 11U, + /** ITU BT.2020 constant luminance YcCbcCrc */ + KHR_DF_MODEL_YCCBCCRC = 12U, + /** ITU BT.2100 constant intensity ICtCp */ + KHR_DF_MODEL_ICTCP = 13U, + /** CIE 1931 XYZ color coordinates (X, Y, Z) */ + KHR_DF_MODEL_CIEXYZ = 14U, + /** CIE 1931 xyY color coordinates (X, Y, Y) */ + KHR_DF_MODEL_CIEXYY = 15U, + + /* Compressed formats start at 128. */ + /* These compressed formats should generally have a single sample, + sited at the 0,0 position of the texel block. Where multiple + channels are used to distinguish formats, these should be cosited. */ + /* Direct3D (and S3) compressed formats */ + /* Note that premultiplied status is recorded separately */ + /** DXT1 "channels" are RGB (0), Alpha (1) + DXT1/BC1 with one channel is opaque + DXT1/BC1 with a cosited alpha sample is transparent */ + KHR_DF_MODEL_DXT1A = 128U, + KHR_DF_MODEL_BC1A = 128U, + /** DXT2/DXT3/BC2, with explicit 4-bit alpha */ + KHR_DF_MODEL_DXT2 = 129U, + KHR_DF_MODEL_DXT3 = 129U, + KHR_DF_MODEL_BC2 = 129U, + /** DXT4/DXT5/BC3, with interpolated alpha */ + KHR_DF_MODEL_DXT4 = 130U, + KHR_DF_MODEL_DXT5 = 130U, + KHR_DF_MODEL_BC3 = 130U, + /** BC4 - single channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC4 = 131U, + /** BC5 - two channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC5 = 132U, + /** BC6H - DX11 format for 16-bit float channels */ + KHR_DF_MODEL_BC6H = 133U, + /** BC7 - DX11 format */ + KHR_DF_MODEL_BC7 = 134U, + /* Gap left for future desktop expansion */ + + /* Mobile compressed formats follow */ + /** A format of ETC1 indicates that the format shall be decodable + by an ETC1-compliant decoder and not rely on ETC2 features */ + KHR_DF_MODEL_ETC1 = 160U, + /** A format of ETC2 is permitted to use ETC2 encodings on top of + the baseline ETC1 specification. + The ETC2 format has channels "red", "green", "RGB" and "alpha", + which should be cosited samples. + Punch-through alpha can be distinguished from full alpha by + the plane size in bytes required for the texel block */ + KHR_DF_MODEL_ETC2 = 161U, + /** Adaptive Scalable Texture Compression */ + /** ASTC HDR vs LDR is determined by the float flag in the channel */ + /** ASTC block size can be distinguished by texel block size */ + KHR_DF_MODEL_ASTC = 162U, + /** ETC1S is a simplified subset of ETC1 */ + KHR_DF_MODEL_ETC1S = 163U, + /** PowerVR Texture Compression v1 */ + KHR_DF_MODEL_PVRTC = 164U, + /** PowerVR Texture Compression v2 */ + KHR_DF_MODEL_PVRTC2 = 165U, + /** UASTC is a transcodable subset of ASTC + with additions to support the transcoding. */ + KHR_DF_MODEL_UASTC = 166U, + /* Proprietary formats (ATITC, etc.) should follow */ + KHR_DF_MODEL_MAX = 0xFFU +} khr_df_model_e; + +/* Definition of channel names for each color model */ +typedef enum _khr_df_model_channels_e { + /* Unspecified format with nominal channel numbering */ + KHR_DF_CHANNEL_UNSPECIFIED_0 = 0U, + KHR_DF_CHANNEL_UNSPECIFIED_1 = 1U, + KHR_DF_CHANNEL_UNSPECIFIED_2 = 2U, + KHR_DF_CHANNEL_UNSPECIFIED_3 = 3U, + KHR_DF_CHANNEL_UNSPECIFIED_4 = 4U, + KHR_DF_CHANNEL_UNSPECIFIED_5 = 5U, + KHR_DF_CHANNEL_UNSPECIFIED_6 = 6U, + KHR_DF_CHANNEL_UNSPECIFIED_7 = 7U, + KHR_DF_CHANNEL_UNSPECIFIED_8 = 8U, + KHR_DF_CHANNEL_UNSPECIFIED_9 = 9U, + KHR_DF_CHANNEL_UNSPECIFIED_10 = 10U, + KHR_DF_CHANNEL_UNSPECIFIED_11 = 11U, + KHR_DF_CHANNEL_UNSPECIFIED_12 = 12U, + KHR_DF_CHANNEL_UNSPECIFIED_13 = 13U, + KHR_DF_CHANNEL_UNSPECIFIED_14 = 14U, + KHR_DF_CHANNEL_UNSPECIFIED_15 = 15U, + /* MODEL_RGBSDA - red, green, blue, stencil, depth, alpha */ + KHR_DF_CHANNEL_RGBSDA_RED = 0U, + KHR_DF_CHANNEL_RGBSDA_R = 0U, + KHR_DF_CHANNEL_RGBSDA_GREEN = 1U, + KHR_DF_CHANNEL_RGBSDA_G = 1U, + KHR_DF_CHANNEL_RGBSDA_BLUE = 2U, + KHR_DF_CHANNEL_RGBSDA_B = 2U, + KHR_DF_CHANNEL_RGBSDA_STENCIL = 13U, + KHR_DF_CHANNEL_RGBSDA_S = 13U, + KHR_DF_CHANNEL_RGBSDA_DEPTH = 14U, + KHR_DF_CHANNEL_RGBSDA_D = 14U, + KHR_DF_CHANNEL_RGBSDA_ALPHA = 15U, + KHR_DF_CHANNEL_RGBSDA_A = 15U, + /* MODEL_YUVSDA - luma, Cb, Cr, stencil, depth, alpha */ + KHR_DF_CHANNEL_YUVSDA_Y = 0U, + KHR_DF_CHANNEL_YUVSDA_CB = 1U, + KHR_DF_CHANNEL_YUVSDA_U = 1U, + KHR_DF_CHANNEL_YUVSDA_CR = 2U, + KHR_DF_CHANNEL_YUVSDA_V = 2U, + KHR_DF_CHANNEL_YUVSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YUVSDA_S = 13U, + KHR_DF_CHANNEL_YUVSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YUVSDA_D = 14U, + KHR_DF_CHANNEL_YUVSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YUVSDA_A = 15U, + /* MODEL_YIQSDA - luma, in-phase, quadrature, stencil, depth, alpha */ + KHR_DF_CHANNEL_YIQSDA_Y = 0U, + KHR_DF_CHANNEL_YIQSDA_I = 1U, + KHR_DF_CHANNEL_YIQSDA_Q = 2U, + KHR_DF_CHANNEL_YIQSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YIQSDA_S = 13U, + KHR_DF_CHANNEL_YIQSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YIQSDA_D = 14U, + KHR_DF_CHANNEL_YIQSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YIQSDA_A = 15U, + /* MODEL_LABSDA - CIELAB/L*a*b* luma, red-green, blue-yellow, stencil, depth, alpha */ + KHR_DF_CHANNEL_LABSDA_L = 0U, + KHR_DF_CHANNEL_LABSDA_A = 1U, + KHR_DF_CHANNEL_LABSDA_B = 2U, + KHR_DF_CHANNEL_LABSDA_STENCIL = 13U, + KHR_DF_CHANNEL_LABSDA_S = 13U, + KHR_DF_CHANNEL_LABSDA_DEPTH = 14U, + KHR_DF_CHANNEL_LABSDA_D = 14U, + KHR_DF_CHANNEL_LABSDA_ALPHA = 15U, + /* NOTE: KHR_DF_CHANNEL_LABSDA_A is not a synonym for alpha! */ + /* MODEL_CMYKA - cyan, magenta, yellow, key/blacK, alpha */ + KHR_DF_CHANNEL_CMYKSDA_CYAN = 0U, + KHR_DF_CHANNEL_CMYKSDA_C = 0U, + KHR_DF_CHANNEL_CMYKSDA_MAGENTA = 1U, + KHR_DF_CHANNEL_CMYKSDA_M = 1U, + KHR_DF_CHANNEL_CMYKSDA_YELLOW = 2U, + KHR_DF_CHANNEL_CMYKSDA_Y = 2U, + KHR_DF_CHANNEL_CMYKSDA_KEY = 3U, + KHR_DF_CHANNEL_CMYKSDA_BLACK = 3U, + KHR_DF_CHANNEL_CMYKSDA_K = 3U, + KHR_DF_CHANNEL_CMYKSDA_ALPHA = 15U, + KHR_DF_CHANNEL_CMYKSDA_A = 15U, + /* MODEL_XYZW - coordinates x, y, z, w */ + KHR_DF_CHANNEL_XYZW_X = 0U, + KHR_DF_CHANNEL_XYZW_Y = 1U, + KHR_DF_CHANNEL_XYZW_Z = 2U, + KHR_DF_CHANNEL_XYZW_W = 3U, + /* MODEL_HSVA_ANG - value (luma), saturation, hue, alpha, angular projection, conical space */ + KHR_DF_CHANNEL_HSVA_ANG_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_ANG_V = 0U, + KHR_DF_CHANNEL_HSVA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_ANG_S = 1U, + KHR_DF_CHANNEL_HSVA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSVA_ANG_H = 2U, + KHR_DF_CHANNEL_HSVA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_ANG_A = 15U, + /* MODEL_HSLA_ANG - lightness (luma), saturation, hue, alpha, angular projection, double conical space */ + KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_ANG_L = 0U, + KHR_DF_CHANNEL_HSLA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_ANG_S = 1U, + KHR_DF_CHANNEL_HSLA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSLA_ANG_H = 2U, + KHR_DF_CHANNEL_HSLA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_ANG_A = 15U, + /* MODEL_HSVA_HEX - value (luma), saturation, hue, alpha, hexagonal projection, conical space */ + KHR_DF_CHANNEL_HSVA_HEX_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_HEX_V = 0U, + KHR_DF_CHANNEL_HSVA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_HEX_S = 1U, + KHR_DF_CHANNEL_HSVA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSVA_HEX_H = 2U, + KHR_DF_CHANNEL_HSVA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_HEX_A = 15U, + /* MODEL_HSLA_HEX - lightness (luma), saturation, hue, alpha, hexagonal projection, double conical space */ + KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_HEX_L = 0U, + KHR_DF_CHANNEL_HSLA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_HEX_S = 1U, + KHR_DF_CHANNEL_HSLA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSLA_HEX_H = 2U, + KHR_DF_CHANNEL_HSLA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_HEX_A = 15U, + /* MODEL_YCGCOA - luma, green delta, orange delta, alpha */ + KHR_DF_CHANNEL_YCGCOA_Y = 0U, + KHR_DF_CHANNEL_YCGCOA_CG = 1U, + KHR_DF_CHANNEL_YCGCOA_CO = 2U, + KHR_DF_CHANNEL_YCGCOA_ALPHA = 15U, + KHR_DF_CHANNEL_YCGCOA_A = 15U, + /* MODEL_CIEXYZ - CIE 1931 X, Y, Z */ + KHR_DF_CHANNEL_CIEXYZ_X = 0U, + KHR_DF_CHANNEL_CIEXYZ_Y = 1U, + KHR_DF_CHANNEL_CIEXYZ_Z = 2U, + /* MODEL_CIEXYY - CIE 1931 x, y, Y */ + KHR_DF_CHANNEL_CIEXYY_X = 0U, + KHR_DF_CHANNEL_CIEXYY_YCHROMA = 1U, + KHR_DF_CHANNEL_CIEXYY_YLUMA = 2U, + + /* Compressed formats */ + /* MODEL_DXT1A/MODEL_BC1A */ + KHR_DF_CHANNEL_DXT1A_COLOR = 0U, + KHR_DF_CHANNEL_BC1A_COLOR = 0U, + KHR_DF_CHANNEL_DXT1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_DXT1A_ALPHA = 1U, + KHR_DF_CHANNEL_BC1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_BC1A_ALPHA = 1U, + /* MODEL_DXT2/3/MODEL_BC2 */ + KHR_DF_CHANNEL_DXT2_COLOR = 0U, + KHR_DF_CHANNEL_DXT3_COLOR = 0U, + KHR_DF_CHANNEL_BC2_COLOR = 0U, + KHR_DF_CHANNEL_DXT2_ALPHA = 15U, + KHR_DF_CHANNEL_DXT3_ALPHA = 15U, + KHR_DF_CHANNEL_BC2_ALPHA = 15U, + /* MODEL_DXT4/5/MODEL_BC3 */ + KHR_DF_CHANNEL_DXT4_COLOR = 0U, + KHR_DF_CHANNEL_DXT5_COLOR = 0U, + KHR_DF_CHANNEL_BC3_COLOR = 0U, + KHR_DF_CHANNEL_DXT4_ALPHA = 15U, + KHR_DF_CHANNEL_DXT5_ALPHA = 15U, + KHR_DF_CHANNEL_BC3_ALPHA = 15U, + /* MODEL_BC4 */ + KHR_DF_CHANNEL_BC4_DATA = 0U, + /* MODEL_BC5 */ + KHR_DF_CHANNEL_BC5_RED = 0U, + KHR_DF_CHANNEL_BC5_R = 0U, + KHR_DF_CHANNEL_BC5_GREEN = 1U, + KHR_DF_CHANNEL_BC5_G = 1U, + /* MODEL_BC6H */ + KHR_DF_CHANNEL_BC6H_COLOR = 0U, + KHR_DF_CHANNEL_BC6H_DATA = 0U, + /* MODEL_BC7 */ + KHR_DF_CHANNEL_BC7_DATA = 0U, + KHR_DF_CHANNEL_BC7_COLOR = 0U, + /* MODEL_ETC1 */ + KHR_DF_CHANNEL_ETC1_DATA = 0U, + KHR_DF_CHANNEL_ETC1_COLOR = 0U, + /* MODEL_ETC2 */ + KHR_DF_CHANNEL_ETC2_RED = 0U, + KHR_DF_CHANNEL_ETC2_R = 0U, + KHR_DF_CHANNEL_ETC2_GREEN = 1U, + KHR_DF_CHANNEL_ETC2_G = 1U, + KHR_DF_CHANNEL_ETC2_COLOR = 2U, + KHR_DF_CHANNEL_ETC2_ALPHA = 15U, + KHR_DF_CHANNEL_ETC2_A = 15U, + /* MODEL_ASTC */ + KHR_DF_CHANNEL_ASTC_DATA = 0U, + /* MODEL_ETC1S */ + KHR_DF_CHANNEL_ETC1S_RGB = 0U, + KHR_DF_CHANNEL_ETC1S_RRR = 3U, + KHR_DF_CHANNEL_ETC1S_GGG = 4U, + KHR_DF_CHANNEL_ETC1S_AAA = 15U, + /* MODEL_PVRTC */ + KHR_DF_CHANNEL_PVRTC_DATA = 0U, + KHR_DF_CHANNEL_PVRTC_COLOR = 0U, + /* MODEL_PVRTC2 */ + KHR_DF_CHANNEL_PVRTC2_DATA = 0U, + KHR_DF_CHANNEL_PVRTC2_COLOR = 0U, + /* MODEL UASTC */ + KHR_DF_CHANNEL_UASTC_DATA = 0U, + KHR_DF_CHANNEL_UASTC_RGB = 0U, + KHR_DF_CHANNEL_UASTC_RGBA = 3U, + KHR_DF_CHANNEL_UASTC_RRR = 4U, + KHR_DF_CHANNEL_UASTC_RRRG = 5U, + KHR_DF_CHANNEL_UASTC_RG = 6U, + + /* Common channel names shared by multiple formats */ + KHR_DF_CHANNEL_COMMON_LUMA = 0U, + KHR_DF_CHANNEL_COMMON_L = 0U, + KHR_DF_CHANNEL_COMMON_STENCIL = 13U, + KHR_DF_CHANNEL_COMMON_S = 13U, + KHR_DF_CHANNEL_COMMON_DEPTH = 14U, + KHR_DF_CHANNEL_COMMON_D = 14U, + KHR_DF_CHANNEL_COMMON_ALPHA = 15U, + KHR_DF_CHANNEL_COMMON_A = 15U +} khr_df_model_channels_e; + +/** @~English + @brief Definition of the primary colors in color coordinates. + This is implicitly responsible for defining the conversion + between RGB an YUV color spaces. + LAB and related absolute color models should use + KHR_DF_PRIMARIES_CIEXYZ. */ +typedef enum _khr_df_primaries_e { + /** No color primaries defined */ + KHR_DF_PRIMARIES_UNSPECIFIED = 0U, + /** Color primaries of ITU-R BT.709 and sRGB */ + KHR_DF_PRIMARIES_BT709 = 1U, + /** Synonym for KHR_DF_PRIMARIES_BT709 */ + KHR_DF_PRIMARIES_SRGB = 1U, + /** Color primaries of ITU-R BT.601 (625-line EBU variant) */ + KHR_DF_PRIMARIES_BT601_EBU = 2U, + /** Color primaries of ITU-R BT.601 (525-line SMPTE C variant) */ + KHR_DF_PRIMARIES_BT601_SMPTE = 3U, + /** Color primaries of ITU-R BT.2020 */ + KHR_DF_PRIMARIES_BT2020 = 4U, + /** CIE theoretical color coordinate space */ + KHR_DF_PRIMARIES_CIEXYZ = 5U, + /** Academy Color Encoding System primaries */ + KHR_DF_PRIMARIES_ACES = 6U, + /** Color primaries of ACEScc */ + KHR_DF_PRIMARIES_ACESCC = 7U, + /** Legacy NTSC 1953 primaries */ + KHR_DF_PRIMARIES_NTSC1953 = 8U, + /** Legacy PAL 525-line primaries */ + KHR_DF_PRIMARIES_PAL525 = 9U, + /** Color primaries of Display P3 */ + KHR_DF_PRIMARIES_DISPLAYP3 = 10U, + /** Color primaries of Adobe RGB (1998) */ + KHR_DF_PRIMARIES_ADOBERGB = 11U, + KHR_DF_PRIMARIES_MAX = 0xFFU +} khr_df_primaries_e; + +/** @~English + @brief Definition of the optical to digital transfer function + ("gamma correction"). Most transfer functions are not a pure + power function and also include a linear element. + LAB and related absolute color representations should use + KHR_DF_TRANSFER_UNSPECIFIED. */ +typedef enum _khr_df_transfer_e { + /** No transfer function defined */ + KHR_DF_TRANSFER_UNSPECIFIED = 0U, + /** Linear transfer function (value proportional to intensity) */ + KHR_DF_TRANSFER_LINEAR = 1U, + /** Perceptually-linear transfer function of sRGH (~2.4) */ + KHR_DF_TRANSFER_SRGB = 2U, + /** Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45) */ + KHR_DF_TRANSFER_ITU = 3U, + /** SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) */ + KHR_DF_TRANSFER_SMTPE170M = 3U, + /** Perceptually-linear gamma function of original NTSC (simple 2.2 gamma) */ + KHR_DF_TRANSFER_NTSC = 4U, + /** Sony S-log used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG = 5U, + /** Sony S-log 2 used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG2 = 6U, + /** ITU BT.1886 EOTF */ + KHR_DF_TRANSFER_BT1886 = 7U, + /** ITU BT.2100 HLG OETF */ + KHR_DF_TRANSFER_HLG_OETF = 8U, + /** ITU BT.2100 HLG EOTF */ + KHR_DF_TRANSFER_HLG_EOTF = 9U, + /** ITU BT.2100 PQ EOTF */ + KHR_DF_TRANSFER_PQ_EOTF = 10U, + /** ITU BT.2100 PQ OETF */ + KHR_DF_TRANSFER_PQ_OETF = 11U, + /** DCI P3 transfer function */ + KHR_DF_TRANSFER_DCIP3 = 12U, + /** Legacy PAL OETF */ + KHR_DF_TRANSFER_PAL_OETF = 13U, + /** Legacy PAL 625-line EOTF */ + KHR_DF_TRANSFER_PAL625_EOTF = 14U, + /** Legacy ST240 transfer function */ + KHR_DF_TRANSFER_ST240 = 15U, + /** ACEScc transfer function */ + KHR_DF_TRANSFER_ACESCC = 16U, + /** ACEScct transfer function */ + KHR_DF_TRANSFER_ACESCCT = 17U, + /** Adobe RGB (1998) transfer function */ + KHR_DF_TRANSFER_ADOBERGB = 18U, + KHR_DF_TRANSFER_MAX = 0xFFU +} khr_df_transfer_e; + +typedef enum _khr_df_flags_e { + KHR_DF_FLAG_ALPHA_STRAIGHT = 0U, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1U +} khr_df_flags_e; + +typedef enum _khr_df_sample_datatype_qualifiers_e { + KHR_DF_SAMPLE_DATATYPE_LINEAR = 1U << 4U, + KHR_DF_SAMPLE_DATATYPE_EXPONENT = 1U << 5U, + KHR_DF_SAMPLE_DATATYPE_SIGNED = 1U << 6U, + KHR_DF_SAMPLE_DATATYPE_FLOAT = 1U << 7U +} khr_df_sample_datatype_qualifiers_e; + +#endif diff --git a/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/Headers/ktx.h b/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/Headers/ktx.h new file mode 100644 index 00000000..fd321c30 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/Headers/ktx.h @@ -0,0 +1,1835 @@ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + +#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1 +#define KTX_H_A55A6F00956F42F3A137C11929827FE1 + +/* + * Copyright 2010-2018 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + * + * See the accompanying LICENSE.md for licensing details for all files in + * the KTX library and KTX loader tests. + */ + +/** + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX API. + * + * @author Mark Callow, Edgewise Consulting and while at HI Corporation + * @author Based on original work by Georg Kolling, Imagination Technology + * + * @snippet{doc} version.h API version + */ + +#include +#include +#include + +#include + +/* + * Don't use khrplatform.h in order not to break apps existing + * before these definitions were needed. + */ +#if defined(KHRONOS_STATIC) + #define KTX_API +#elif defined(_WIN32) || defined(__CYGWIN__) + #if !defined(KTX_API) + #if __GNUC__ + #define KTX_API __attribute__ ((dllimport)) + #elif _MSC_VER + #define KTX_API __declspec(dllimport) + #else + #error "Your compiler's equivalent of dllimport is unknown" + #endif + #endif +#elif defined(__ANDROID__) + #define KTX_API __attribute__((visibility("default"))) +#else + #define KTX_API +#endif + +#if defined(_WIN32) && !defined(KHRONOS_STATIC) + #if !defined(KTX_APIENTRY) + #define KTX_APIENTRY __stdcall + #endif +#else + #define KTX_APIENTRY +#endif + +/* To avoid including define our own types. */ +typedef unsigned char ktx_uint8_t; +typedef bool ktx_bool_t; +#ifdef _MSC_VER +typedef unsigned __int16 ktx_uint16_t; +typedef signed __int16 ktx_int16_t; +typedef unsigned __int32 ktx_uint32_t; +typedef signed __int32 ktx_int32_t; +typedef size_t ktx_size_t; +typedef unsigned __int64 ktx_uint64_t; +typedef signed __int64 ktx_int64_t; +#else +#include +typedef uint16_t ktx_uint16_t; +typedef int16_t ktx_int16_t; +typedef uint32_t ktx_uint32_t; +typedef int32_t ktx_int32_t; +typedef size_t ktx_size_t; +typedef uint64_t ktx_uint64_t; +typedef int64_t ktx_int64_t; +#endif + +/* This will cause compilation to fail if size of uint32 != 4. */ +typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4]; + +/* + * This #if allows libktx to be compiled with strict c99. It avoids + * compiler warnings or even errors when a gl.h is already included. + * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if + * gl.h comes after. However nobody has complained about the unguarded typedefs + * since they were introduced so this is unlikely to be a problem in practice. + * Presumably everybody is using platform default compilers not c99 or else + * they are using C++. + */ +#if !defined(GL_NO_ERROR) + /* + * To avoid having to including gl.h ... + */ + typedef unsigned char GLboolean; + typedef unsigned int GLenum; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLuint; + typedef unsigned char GLubyte; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_ANIMDATA_KEY "KTXanimData" +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +#define KTX_ORIENTATION_KEY "KTXorientation" +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +#define KTX_SWIZZLE_KEY "KTXswizzle" +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_WRITER_KEY "KTXwriter" +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams" +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +#define KTX_ORIENTATION1_FMT "S=%c" +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +#define KTX_ORIENTATION2_FMT "S=%c,T=%c" +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c" +/** + * @~English + * @brief Required unpack alignment + */ +#define KTX_GL_UNPACK_ALIGNMENT 4 + +#define KTX_TRUE true +#define KTX_FALSE false + +/** + * @~English + * @brief Error codes returned by library functions. + */ +typedef enum ktx_error_code_e { + KTX_SUCCESS = 0, /*!< Operation was successful. */ + KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */ + KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */ + KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */ + KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */ + KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */ + KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */ + KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */ + KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */ + KTX_GL_ERROR, /*!< GL operations resulted in an error. */ + KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ + KTX_INVALID_VALUE, /*!< A parameter value was not valid */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ + KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ + KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ + KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ + KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */ + KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */ + KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */ + KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */ + KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */ + KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */ +} ktx_error_code_e; +/** + * @deprecated + * @~English + * @brief For backward compatibility + */ +#define KTX_error_code ktx_error_code_e + +#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } +#define KTX_ENDIAN_REF (0x04030201) +#define KTX_ENDIAN_REF_REV (0x01020304) +#define KTX_HEADER_SIZE (64) + +/** + * @~English + * @brief Result codes returned by library functions. + */ + typedef enum ktx_error_code_e ktxResult; + +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ +typedef struct ktxKVListEntry* ktxHashList; + +typedef struct ktxStream ktxStream; + +#define KTX_APIENTRYP KTX_APIENTRY * +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ +typedef struct ktxKVListEntry ktxHashListEntry; + +typedef enum ktxOrientationX { + KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r' +} ktxOrientationX; + +typedef enum ktxOrientationY { + KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd' +} ktxOrientationY; + +typedef enum ktxOrientationZ { + KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o' +} ktxOrientationZ; + +typedef enum class_id { + ktxTexture1_c = 1, + ktxTexture2_c = 2 +} class_id; + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +struct ktxOrientation { + ktxOrientationX x; /*!< Orientation in X */ + ktxOrientationY y; /*!< Orientation in Y */ + ktxOrientationZ z; /*!< Orientation in Z */ +}; + +#define KTXTEXTURECLASSDEFN \ + class_id classId; \ + struct ktxTexture_vtbl* vtbl; \ + struct ktxTexture_vvtbl* vvtbl; \ + struct ktxTexture_protected* _protected; \ + ktx_bool_t isArray; \ + ktx_bool_t isCubemap; \ + ktx_bool_t isCompressed; \ + ktx_bool_t generateMipmaps; \ + ktx_uint32_t baseWidth; \ + ktx_uint32_t baseHeight; \ + ktx_uint32_t baseDepth; \ + ktx_uint32_t numDimensions; \ + ktx_uint32_t numLevels; \ + ktx_uint32_t numLayers; \ + ktx_uint32_t numFaces; \ + struct ktxOrientation orientation; \ + ktxHashList kvDataHead; \ + ktx_uint32_t kvDataLen; \ + ktx_uint8_t* kvData; \ + ktx_size_t dataSize; \ + ktx_uint8_t* pData; + + +/** + * @class ktxTexture + * @~English + * @brief Base class representing a texture. + * + * ktxTextures should be created only by one of the provided + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture { + KTXTEXTURECLASSDEFN +} ktxTexture; +/** + * @typedef ktxTexture::classId + * @~English + * @brief Identify the class type. + * + * Since there are no public ktxTexture constructors, this can only have + * values of ktxTexture1_c or ktxTexture2_c. + */ +/** + * @typedef ktxTexture::vtbl + * @~English + * @brief Pointer to the class's vtble. + */ +/** + * @typedef ktxTexture::vvtbl + * @~English + * @brief Pointer to the class's vtble for Vulkan functions. + * + * A separate vtble is used so this header does not need to include vulkan.h. + */ +/** + * @typedef ktxTexture::_protected + * @~English + * @brief Opaque pointer to the class's protected variables. + */ +/** + * @typedef ktxTexture::isArray + * @~English + * + * KTX_TRUE if the texture is an array texture, i.e, + * a GL_TEXTURE_*_ARRAY target is to be used. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture is a cubemap or cubemap array. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture's format is a block compressed format. + */ +/** + * @typedef ktxTexture::generateMipmaps + * @~English + * + * KTX_TRUE if mipmaps should be generated for the texture by + * ktxTexture_GLUpload() or ktxTexture_VkUpload(). + */ +/**n + * @typedef ktxTexture::baseWidth + * @~English + * @brief Width of the texture's base level. + */ +/** + * @typedef ktxTexture::baseHeight + * @~English + * @brief Height of the texture's base level. + */ +/** + * @typedef ktxTexture::baseDepth + * @~English + * @brief Depth of the texture's base level. + */ +/** + * @typedef ktxTexture::numDimensions + * @~English + * @brief Number of dimensions in the texture: 1, 2 or 3. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of mip levels in the texture. + * + * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a + * full pyramid but always starts at the base level. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of array layers in the texture. + */ +/** + * @typedef ktxTexture::numFaces + * @~English + * @brief Number of faces: 6 for cube maps, 1 otherwise. + */ +/** + * @typedef ktxTexture::orientation + * @~English + * @brief Describes the logical orientation of the images in each dimension. + * + * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z. + */ +/** + * @typedef ktxTexture::kvDataHead + * @~English + * @brief Head of the hash list of metadata. + */ +/** + * @typedef ktxTexture::kvDataLen + * @~English + * @brief Length of the metadata, if it has been extracted in its raw form, + * otherwise 0. + */ +/** + * @typedef ktxTexture::kvData + * @~English + * @brief Pointer to the metadata, if it has been extracted in its raw form, + * otherwise NULL. + */ +/** + * @typedef ktxTexture::dataSize + * @~English + * @brief Byte length of the texture's uncompressed image data. + */ +/** + * @typedef ktxTexture::pData + * @~English + * @brief Pointer to the start of the image data. + */ + +/** + * @memberof ktxTexture + * @~English + * @brief Signature of function called by the ktxTexture_Iterate* + * functions to receive image data. + * + * The function parameters are used to pass values which change for each image. + * Obtain values which are uniform across all images from the @c ktxTexture + * object. + * + * @param [in] miplevel MIP level from 0 to the max level which is + * dependent on the texture size. + * @param [in] face usually 0; for cube maps, one of the 6 cube + * faces in the order +X, -X, +Y, -Y, +Z, -Z, + * 0 to 5. + * @param [in] width width of the image. + * @param [in] height height of the image or, for 1D textures + * textures, 1. + * @param [in] depth depth of the image or, for 1D & 2D + * textures, 1. + * @param [in] faceLodSize number of bytes of data pointed at by + * @p pixels. + * @param [in] pixels pointer to the image data. + * @param [in,out] userdata pointer for the application to pass data to and + * from the callback function. + */ + +typedef KTX_error_code + (* PFNKTXITERCB)(int miplevel, int face, + int width, int height, int depth, + ktx_uint64_t faceLodSize, + void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + ktx_size_t* pOffset); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This, + PFNKTXITERCB iterCb, + void* userdata); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This, + ktx_uint8_t* pBuffer, + ktx_size_t bufSize); +typedef ktx_bool_t + (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + const ktx_uint8_t* src, + ktx_size_t srcSize); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + FILE* src, ktx_size_t srcSize); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This, + const char* const dstname); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, + ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + struct ktxTexture_vtbl { + PFNKTEXDESTROY Destroy; + PFNKTEXGETIMAGEOFFSET GetImageOffset; + PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + PFNKTEXGETIMAGESIZE GetImageSize; + PFNKTEXITERATELEVELS IterateLevels; + PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + PFNKTEXLOADIMAGEDATA LoadImageData; + PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; +}; + +/**************************************************************** + * Macros to give some backward compatibility to the previous API + ****************************************************************/ + +/** + * @~English + * @brief Helper for calling the Destroy virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_Destroy + */ +#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This) + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \ + (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset) + +/** + * @~English + * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture. + * + * For a ktxTexture1 this will always return the value of This->dataSize. + * + * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed + */ +#define ktxTexture_GetDataSizeUncompressed(This) \ + (This)->vtbl->GetDataSizeUncompressed(This) + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +#define ktxTexture_GetImageSize(This, level) \ + (This)->vtbl->GetImageSize(This, level) + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +#define ktxTexture_IterateLevels(This, iterCb, userdata) \ + (This)->vtbl->IterateLevels(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \ + (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \ + (This)->vtbl->LoadImageData(This, pBuffer, bufSize) + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This) + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize) + +/** + * @~English + * @brief Helper for calling the SetImageFromStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream + */ +#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) + +/** + * @~English + * @brief Helper for calling the WriteToStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream + */ +#define ktxTexture_WriteToStdioStream(This, dstsstr) \ + (This)->vtbl->WriteToStdioStream(This, dstsstr) + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +#define ktxTexture_WriteToNamedFile(This, dstname) \ + (This)->vtbl->WriteToNamedFile(This, dstname) + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ + (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + + +/** + * @class ktxTexture1 + * @~English + * @brief Class representing a KTX version 1 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture1 { + KTXTEXTURECLASSDEFN + ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + struct ktxTexture1_private* _private; /*!< Private data. */ +} ktxTexture1; + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +typedef enum ktxSupercmpScheme { + KTX_SS_NONE = 0, /*!< No supercompression. */ + KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */ + KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */ + KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */ + KTX_SS_BEGIN_RANGE = KTX_SS_NONE, + KTX_SS_END_RANGE = KTX_SS_ZLIB, + KTX_SS_BEGIN_VENDOR_RANGE = 0x10000, + KTX_SS_END_VENDOR_RANGE = 0x1ffff, + KTX_SS_BEGIN_RESERVED = 0x20000, + KTX_SUPERCOMPRESSION_BASIS = KTX_SS_BASIS_LZ, + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_BASIS_LZ instead. */ + KTX_SUPERCOMPRESSION_ZSTD = KTX_SS_ZSTD + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_ZSTD instead. */ +} ktxSupercmpScheme; + +/** + * @class ktxTexture2 + * @~English + * @brief Class representing a KTX version 2 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture2 { + KTXTEXTURECLASSDEFN + ktx_uint32_t vkFormat; + ktx_uint32_t* pDfd; + ktxSupercmpScheme supercompressionScheme; + ktx_bool_t isVideo; + ktx_uint32_t duration; + ktx_uint32_t timescale; + ktx_uint32_t loopcount; + struct ktxTexture2_private* _private; /*!< Private data. */ +} ktxTexture2; + +#define ktxTexture(t) ((ktxTexture*)t) + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1_Create() and + * ktxTexture2_Create(). + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef struct +{ + ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an + array texture. Means OpenGL will use a + GL_TEXTURE_*_ARRAY target. */ + ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} ktxTextureCreateInfo; + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef enum { + KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */ + KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */ +} ktxTextureCreateStorageEnum; + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +enum ktxTextureCreateFlagBits { + KTX_TEXTURE_CREATE_NO_FLAGS = 0x00, + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01, + /*!< Load the images from the KTX source. */ + KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08 + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +}; +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +typedef ktx_uint32_t ktxTextureCreateFlags; + +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + ktxStream_write write; /*!< pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< destruct the stream. */ + + enum streamType type; + union { + FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + struct + { + void* address; /**< pointer to the data. */ + void* allocatorAddress; /**< pointer to a memory allocator. */ + ktx_size_t size; /**< size of the data. */ + } custom_ptr; /**< pointer to a struct for custom streams. */ + } data; /**< pointer to the stream data. */ + ktx_off_t readpos; /**< used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +}; + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ +KTX_API ktx_uint8_t* KTX_APIENTRY +ktxTexture_GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ +KTX_API ktx_size_t KTX_APIENTRY +ktxTexture_GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, + GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); +/* + * Create a new ktxTexture1. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture1_NeedsTranscoding(ktxTexture1* This); + +/* + * Write a ktxTexture object to a stdio stream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + +/* + * Write a ktxTexture object to a named file in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname); + +/* + * Write a ktxTexture object to a block of memory in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, + ktx_uint8_t** bytes, ktx_size_t* size); + +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + +/* + * Create a new ktxTexture2. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + +KTX_API void KTX_APIENTRY +ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, + ktx_uint32_t* componentByteLength); + +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetNumComponents(ktxTexture2* This); + +KTX_API khr_df_transfer_e KTX_APIENTRY +ktxTexture2_GetOETF_e(ktxTexture2* This); + +// For backward compatibility +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetOETF(ktxTexture2* This); + +KTX_API khr_df_model_e KTX_APIENTRY +ktxTexture2_GetColorModel_e(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_NeedsTranscoding(ktxTexture2* This); + +/** + * @~English + * @brief Flags specifiying UASTC encoding options. + */ +typedef enum ktx_pack_uastc_flag_bits_e { + KTX_PACK_UASTC_LEVEL_FASTEST = 0, + /*!< Fastest compression. 43.45dB. */ + KTX_PACK_UASTC_LEVEL_FASTER = 1, + /*!< Faster compression. 46.49dB. */ + KTX_PACK_UASTC_LEVEL_DEFAULT = 2, + /*!< Default compression. 47.47dB. */ + KTX_PACK_UASTC_LEVEL_SLOWER = 3, + /*!< Slower compression. 48.01dB. */ + KTX_PACK_UASTC_LEVEL_VERYSLOW = 4, + /*!< Very slow compression. 48.24dB. */ + KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW, + /*!< Maximum supported quality level. */ + KTX_PACK_UASTC_LEVEL_MASK = 0xF, + /*!< Mask to extract the level from the other bits. */ + KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8, + /*!< Optimize for lowest UASTC error. */ + KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16, + /*!< Optimize for lowest BC7 error. */ + KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64, + /*!< Optimize for faster transcoding to ETC1. */ + KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128, + /*!< Optimize for fastest transcoding to ETC1. */ + KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256 + /*!< Not documented in BasisU code. */ +} ktx_pack_uastc_flag_bits_e; +typedef ktx_uint32_t ktx_pack_uastc_flags; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +typedef enum ktx_pack_astc_quality_levels_e { + KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0, + /*!< Fastest compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10, + /*!< Fast compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60, + /*!< Medium compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98, + /*!< Slower compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100, + /*!< Very slow compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE, + /*!< Maximum supported quality level. */ +} ktx_pack_astc_quality_levels_e; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +typedef enum ktx_pack_astc_block_dimension_e { + // 2D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp + // 3D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6 + /*!< Maximum supported blocks. */ +} ktx_pack_astc_block_dimension_e; + +/** + * @~English + * @brief Options specifying ASTC encoder profile mode + * This and function is used later to derive the profile. + */ +typedef enum ktx_pack_astc_encoder_mode_e { + KTX_PACK_ASTC_ENCODER_MODE_DEFAULT, + KTX_PACK_ASTC_ENCODER_MODE_LDR, + KTX_PACK_ASTC_ENCODER_MODE_HDR, + KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR +} ktx_pack_astc_encoder_mode_e; + +extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture_CompressAstc. + * + * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension + * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to + * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended. + */ +typedef struct ktxAstcParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + ktx_uint32_t qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps + In this mode normals are compressed to X,Y components + Discarding Z component, reader will need to generate Z + component in shaders. + */ + + ktx_bool_t perceptual; + /*!< The codec should optimize for perceptual error, instead of direct + RMS error. This aims to improves perceived image quality, but + typically lowers the measured PSNR score. Perceptual methods are + currently only available for normal maps and RGB color data. + */ + + char inputSwizzle[4]; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} ktxAstcParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + +/** + * @memberof ktxTexture2 + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture2_CompressBasisEx(). + * + * If you only want default values, use ktxTexture2_CompressBasis(). Here, at a minimum you + * must initialize the structure as follows: + * @code + * ktxBasisParams params = {0}; + * params.structSize = sizeof(params); + * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e compressionLevel has to be explicitly set because 0 is a valid @e compressionLevel + * but is not the default used by the BasisU encoder when no value is set. Only the other + * settings that are to be non-default must be non-zero. + */ +typedef struct ktxBasisParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + ktx_bool_t uastc; + /*!< True to use UASTC base, false to use ETC1S base. */ + ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + ktx_uint32_t compressionLevel; + /*!< Encoding speed vs. quality tradeoff. Range is [0,5]. Higher values + are slower, but give higher quality. There is no default. Callers + must explicitly set this value. Callers can use + KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL as a default value. + Currently this is 2. + */ + ktx_uint32_t qualityLevel; + /*!< Compression quality. Range is [1,255]. Lower gives better + compression/lower quality/faster. Higher gives less compression + /higher quality/slower. This automatically determines values for + @c maxEndpoints, @c maxSelectors, + @c endpointRDOThreshold and @c selectorRDOThreshold + for the target quality level. Setting these parameters overrides + the values determined by @c qualityLevel which defaults to + 128 if neither it nor both of @c maxEndpoints and + @c maxSelectors have been set. + @note @e Both of @c maxEndpoints and @c maxSelectors + must be set for them to have any effect. + @note qualityLevel will only determine values for + @c endpointRDOThreshold and @c selectorRDOThreshold + when its value exceeds 128, otherwise their defaults will be used. + */ + ktx_uint32_t maxEndpoints; + /*!< Manually set the max number of color endpoint clusters. + Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors + must also be set, otherwise the value will be ignored. + */ + float endpointRDOThreshold; + /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is + higher quality but less quality per output bit (try [1.0,3.0]. + This will override the value chosen by @c qualityLevel. + */ + ktx_uint32_t maxSelectors; + /*!< Manually set the max number of color selector clusters. Range + is [1,16128]. Default is 0, unset. If this is set, maxEndpoints + must also be set, otherwise the value will be ignored. + */ + float selectorRDOThreshold; + /*!< Set selector RDO quality threshold. The default is 1.5. Lower is + higher quality but less quality per output bit (try [1.0,3.0]). + This will override the value chosen by @c qualityLevel. + */ + char inputSwizzle[4]; + /*!< A swizzle to apply before encoding. It must match the regular + expression /^[rgba01]{4}$/. If both this and preSwizzle + are specified ktxTexture_CompressBasisEx will raise + KTX_INVALID_OPERATION. + */ + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps (no + selector RDO, no endpoint RDO) and sets the texture's DFD appropriately. + Only valid for linear textures. + */ + ktx_bool_t separateRGToRGB_A; + /*!< @deprecated. This was and is a no-op. 2-component inputs have always been + automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode. + */ + ktx_bool_t preSwizzle; + /*!< If the texture has @c KTXswizzle metadata, apply it before + compressing. Swizzling, like @c rabb may yield drastically + different error metrics if done after supercompression. + */ + ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + ktx_bool_t noSelectorRDO; + /*!< Disable selector rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + + /* UASTC params */ + + ktx_pack_uastc_flags uastcFlags; + /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC + encoding. The most important value is the level given in the + least-significant 4 bits which selects a speed vs quality tradeoff + as shown in the following table: + + Level/Speed | Quality + :-----: | :-------: + KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB + KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB + KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB + KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB + KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB + */ + ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + float uastcRDOQualityScalar; + /*!< UASTC RDO quality scalar (lambda). Lower values yield higher + quality/larger LZ compressed files, higher values yield lower + quality/smaller LZ compressed files. A good range to try is [.2,4]. + Full range is [.001,50.0]. Default is 1.0. + */ + ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + float uastcRDOMaxSmoothBlockErrorScale; + /*!< UASTC RDO max smooth block error scale. Range is [1,300]. + Default is 10.0, 1.0 is disabled. Larger values suppress more + artifacts (and allocate more bits) on smooth blocks. + */ + float uastcRDOMaxSmoothBlockStdDev; + /*!< UASTC RDO max smooth block standard deviation. Range is + [.01,65536.0]. Default is 18.0. Larger values expand the range of + blocks considered smooth. + */ + ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + +} ktxBasisParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params); + +/** + * @~English + * @brief Enumerators for specifying the transcode target format. + * + * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate + * RGB images, a.k.a slices within the BasisU compressed data. For UASTC + * format they refer to the RGB and the alpha components of the UASTC data. If + * the original image had only 2 components, R will be in the opaque portion + * and G in the alpha portion. The R value will be replicated in the RGB + * components. In the case of BasisU the G value will be replicated in all 3 + * components of the alpha slice. If the original image had only 1 component + * it's value is replicated in all 3 components of the opaque portion and + * there is no alpha. + * + * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R, + * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565, + * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor + * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader + * will not produce correct results if any texture filtering is being used. + */ +typedef enum ktx_transcode_fmt_e { + // Compressed formats + + // ETC1-2 + KTX_TTF_ETC1_RGB = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_RGBA = 1, + /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + + // BC1-5, BC7 (desktop, some mobile devices) + KTX_TTF_BC1_RGB = 2, + /*!< Opaque only, no punchthrough alpha support yet. Returns RGB + or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS + flag is specified. */ + KTX_TTF_BC3_RGBA = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + KTX_TTF_BC4_R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_BC5_RG = 5, + /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should + have an alpha channel (if not G will be all 255's. For tangent + space normal maps. */ + KTX_TTF_BC7_RGBA = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + KTX_TTF_PVRTC1_4_RGB = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_PVRTC1_4_RGBA = 9, + /*!< Opaque+alpha. Most useful for simple opacity maps. If the + texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB + will be used instead. Lowest quality of any supported + texture format. */ + + // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day) + KTX_TTF_ASTC_4x4_RGBA = 10, + /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for + textures without an alpha channel. The transcoder uses + RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and + [0,255]) endpoint precisions. */ + + // ATC and FXT1 formats are not supported by KTX2 as there + // are no equivalent VkFormats. + + KTX_TTF_PVRTC2_4_RGB = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + KTX_TTF_PVRTC2_4_RGBA = 19, + /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB. + Premultiplied alpha is highly recommended, otherwise the + color channel can leak into the alpha channel on transparent + blocks. */ + + KTX_TTF_ETC2_EAC_R11 = 20, + /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_EAC_RG11 = 21, + /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The + texture should have an alpha channel (if not G will be all + 255's. For tangent space normal maps. */ + + // Uncompressed (raw pixel) formats + KTX_TTF_RGBA32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + KTX_TTF_RGB565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + KTX_TTF_BGR565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + KTX_TTF_RGBA4444 = 16, + /*!< 16bpp RGBA image stored in raster (not block) order in memory, + R at bit position 12, A at bit position 0. */ + + // Values for automatic selection of RGB or RGBA depending if alpha + // present. + KTX_TTF_ETC = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + KTX_TTF_BC1_OR_3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + KTX_TTF_NOSELECTION = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + KTX_TF_ETC1 = KTX_TTF_ETC1_RGB, + //!< @deprecated. Use #KTX_TTF_ETC1_RGB. + KTX_TF_ETC2 = KTX_TTF_ETC, + //!< @deprecated. Use #KTX_TTF_ETC. + KTX_TF_BC1 = KTX_TTF_BC1_RGB, + //!< @deprecated. Use #KTX_TTF_BC1_RGB. + KTX_TF_BC3 = KTX_TTF_BC3_RGBA, + //!< @deprecated. Use #KTX_TTF_BC3_RGBA. + KTX_TF_BC4 = KTX_TTF_BC4_R, + //!< @deprecated. Use #KTX_TTF_BC4_R. + KTX_TF_BC5 = KTX_TTF_BC5_RG, + //!< @deprecated. Use #KTX_TTF_BC5_RG. + KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA + KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB + //!< @deprecated. Use #KTX_TTF_PVRTC1_4_RGB. +} ktx_transcode_fmt_e; + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +typedef enum ktx_transcode_flag_bits_e { + KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2, + /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger + power of 2 (not implemented yet, but we're going to support it). + Ignored if the slice's dimensions are already a power of 2. + */ + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4, + /*!< When decoding to an opaque texture format, if the Basis data has + alpha, decode the alpha slice instead of the color slice to the + output texture format. Has no effect if there is no alpha data. + */ + KTX_TF_HIGH_QUALITY = 32, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} ktx_transcode_flag_bits_e; +typedef ktx_uint32_t ktx_transcode_flags; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, + ktx_transcode_flags transcodeFlags); + +/* + * Returns a string corresponding to a KTX error code. + */ +KTX_API const char* KTX_APIENTRY +ktxErrorString(KTX_error_code error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ +KTX_API const char* KTX_APIENTRY +ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ +KTX_API const char* KTX_APIENTRY +ktxTranscodeFormatString(ktx_transcode_fmt_e format); + +KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl); +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl); +KTX_API void KTX_APIENTRY +ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head); +KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_AddKVPair(ktxHashList* pHead, const char* key, + unsigned int valueLen, const void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindEntry(ktxHashList* pHead, const char* key, + ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindValue(ktxHashList* pHead, const char* key, + unsigned int* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ +KTX_API ktxHashListEntry* KTX_APIENTRY +ktxHashList_Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Serialize(ktxHashList* pHead, + unsigned int* kvdLen, unsigned char** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd); + +/* + * Get the key from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetKey(ktxHashListEntry* This, + unsigned int* pKeyLen, char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetValue(ktxHashListEntry* This, + unsigned int* pValueLen, void** ppValue); + +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX2 file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); + +#ifdef __cplusplus +} +#endif + +/*========================================================================* + * For backward compatibilty with the V3 & early versions of the V4 APIs. * + *========================================================================*/ + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_transcode_fmt_e ktx_transcode_fmt_e + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_decode_flags ktx_transcode_flag_bits + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktxTexture_GetSize ktxTexture_GetDatasize + +/** +@~English +@page libktx_history Revision History + +No longer updated. Kept to preserve ancient history. For more recent history see the repo log at +https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo. + +@section v8 Version 4.0 +Added: +@li Support for KTX Version 2. +@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files. +@li Function to print info about a KTX file. + +@section v7 Version 3.0.1 +Fixed: +@li GitHub issue #159: compile failure with recent Vulkan SDKs. +@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents. +@li Incorrect BC4 blocksize. +@li Missing mapping of PVRTC formats from GL to Vulkan. +@li Incorrect block width and height calculations for sizes that are not + a multiple of the block size. +@li Incorrect KTXorientation key in test images. + +@section v6 Version 3.0 +Added: +@li new ktxTexture object based API for reading KTX files without an OpenGL context. +@li Vulkan loader. @#include to use it. + +Changed: +@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h. + Applications using OpenGL must now include these files themselves. +@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures + when the OpenGL context does not support 1D textures. + KTX_UNSUPPORTED_TEXTURE_TYPE is now returned. + +@section v5 Version 2.0.2 +Added: +@li Support for cubemap arrays. + +Changed: +@li New build system + +Fixed: +@li GitHub issue #40: failure to byte-swap key-value lengths. +@li GitHub issue #33: returning incorrect target when loading cubemaps. +@li GitHub PR #42: loading of texture arrays. +@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined. +@li GitHub issue #39: stack-buffer-overflow in toktx +@li Don't use GL_EXTENSIONS on recent OpenGL versions. + +@section v4 Version 2.0.1 +Added: +@li CMake build files. Thanks to Pavel Rotjberg for the initial version. + +Changed: +@li ktxWriteKTXF to check the validity of the type & format combinations + passed to it. + +Fixed: +@li Public Bugzilla 999: 16-bit luminance texture cannot be written. +@li compile warnings from compilers stricter than MS Visual C++. Thanks to + Pavel Rotjberg. + +@section v3 Version 2.0 +Added: +@li support for decoding ETC2 and EAC formats in the absence of a hardware + decoder. +@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA, + etc. formats to the equivalent R, RG, etc. format with an + appropriate swizzle, when loading in OpenGL Core Profile contexts. +@li ktxErrorString function to return a string corresponding to an error code. +@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3. + The latter includes an EGL on WGL wrapper that makes porting apps between + OpenGL ES and OpenGL easier on Windows. +@li more texture formats to ktxLoadTexture[FN] and toktx tests. + +Changed: +@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at + run time and load textures, or not, according to those capabilities. + +Fixed: +@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX + format. +@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write + more than 1 byte of face-LOD padding. + +Although there is only a very minor API change, the addition of ktxErrorString, +the functional changes are large enough to justify bumping the major revision +number. + +@section v2 Version 1.0.1 +Implemented ktxLoadTextureM. +Fixed the following: +@li Public Bugzilla 571: crash when null passed for pIsMipmapped. +@li Public Bugzilla 572: memory leak when unpacking ETC textures. +@li Public Bugzilla 573: potential crash when unpacking ETC textures with unused padding pixels. +@li Public Bugzilla 576: various small fixes. + +Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes. + +@section v1 Version 1.0 +Initial release. + +*/ + +#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ diff --git a/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/libktx.a b/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/libktx.a new file mode 100644 index 00000000..e07b95dc Binary files /dev/null and b/KTXLoader/libktx/ktx.xcframework/tvos-arm64_x86_64-simulator/libktx.a differ diff --git a/KTXLoader/libktx/ktx.xcframework/xros-arm64/Headers/KHR/khr_df.h b/KTXLoader/libktx/ktx.xcframework/xros-arm64/Headers/KHR/khr_df.h new file mode 100644 index 00000000..c0d03aa7 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/xros-arm64/Headers/KHR/khr_df.h @@ -0,0 +1,630 @@ +/* The Khronos Data Format Specification (version 1.3) */ +/* +** Copyright 2015-2020 The Khronos Group Inc. +** SPDX-License-Identifier: Apache-2.0 +*/ + +/* This header defines a structure that can describe the layout of image + formats in memory. This means that the data format is transparent to + the application, and the expectation is that this should be used when + the layout is defined external to the API. Many Khronos APIs deliberately + keep the internal layout of images opaque, to allow proprietary layouts + and optimisations. This structure is not appropriate for describing + opaque layouts. */ + +/* We stick to standard C89 constructs for simplicity and portability. */ + +#ifndef _KHR_DATA_FORMAT_H_ +#define _KHR_DATA_FORMAT_H_ + +/** @file khr_df.h + + @brief Data Format enums and macros. +*/ + +/* Accessors */ +typedef enum _khr_word_e { + KHR_DF_WORD_VENDORID = 0U, + KHR_DF_WORD_DESCRIPTORTYPE = 0U, + KHR_DF_WORD_VERSIONNUMBER = 1U, + KHR_DF_WORD_DESCRIPTORBLOCKSIZE = 1U, + KHR_DF_WORD_MODEL = 2U, + KHR_DF_WORD_PRIMARIES = 2U, + KHR_DF_WORD_TRANSFER = 2U, + KHR_DF_WORD_FLAGS = 2U, + KHR_DF_WORD_TEXELBLOCKDIMENSION0 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION1 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION2 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION3 = 3U, + KHR_DF_WORD_BYTESPLANE0 = 4U, + KHR_DF_WORD_BYTESPLANE1 = 4U, + KHR_DF_WORD_BYTESPLANE2 = 4U, + KHR_DF_WORD_BYTESPLANE3 = 4U, + KHR_DF_WORD_BYTESPLANE4 = 5U, + KHR_DF_WORD_BYTESPLANE5 = 5U, + KHR_DF_WORD_BYTESPLANE6 = 5U, + KHR_DF_WORD_BYTESPLANE7 = 5U, + KHR_DF_WORD_SAMPLESTART = 6U, + KHR_DF_WORD_SAMPLEWORDS = 4U +} khr_df_word_e; + +typedef enum _khr_df_shift_e { + KHR_DF_SHIFT_VENDORID = 0U, + KHR_DF_SHIFT_DESCRIPTORTYPE = 17U, + KHR_DF_SHIFT_VERSIONNUMBER = 0U, + KHR_DF_SHIFT_DESCRIPTORBLOCKSIZE = 16U, + KHR_DF_SHIFT_MODEL = 0U, + KHR_DF_SHIFT_PRIMARIES = 8U, + KHR_DF_SHIFT_TRANSFER = 16U, + KHR_DF_SHIFT_FLAGS = 24U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION0 = 0U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION1 = 8U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION2 = 16U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION3 = 24U, + KHR_DF_SHIFT_BYTESPLANE0 = 0U, + KHR_DF_SHIFT_BYTESPLANE1 = 8U, + KHR_DF_SHIFT_BYTESPLANE2 = 16U, + KHR_DF_SHIFT_BYTESPLANE3 = 24U, + KHR_DF_SHIFT_BYTESPLANE4 = 0U, + KHR_DF_SHIFT_BYTESPLANE5 = 8U, + KHR_DF_SHIFT_BYTESPLANE6 = 16U, + KHR_DF_SHIFT_BYTESPLANE7 = 24U +} khr_df_shift_e; + +typedef enum _khr_df_mask_e { + KHR_DF_MASK_VENDORID = 0x1FFFFU, + KHR_DF_MASK_DESCRIPTORTYPE = 0x7FFFU, + KHR_DF_MASK_VERSIONNUMBER = 0xFFFFU, + KHR_DF_MASK_DESCRIPTORBLOCKSIZE = 0xFFFFU, + KHR_DF_MASK_MODEL = 0xFFU, + KHR_DF_MASK_PRIMARIES = 0xFFU, + KHR_DF_MASK_TRANSFER = 0xFFU, + KHR_DF_MASK_FLAGS = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION0 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION1 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION2 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE0 = 0xFFU, + KHR_DF_MASK_BYTESPLANE1 = 0xFFU, + KHR_DF_MASK_BYTESPLANE2 = 0xFFU, + KHR_DF_MASK_BYTESPLANE3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE4 = 0xFFU, + KHR_DF_MASK_BYTESPLANE5 = 0xFFU, + KHR_DF_MASK_BYTESPLANE6 = 0xFFU, + KHR_DF_MASK_BYTESPLANE7 = 0xFFU +} khr_df_mask_e; + +/* Helper macro: + Extract field X from basic descriptor block BDB */ +#define KHR_DFDVAL(BDB, X) \ + (((BDB)[KHR_DF_WORD_ ## X] >> (KHR_DF_SHIFT_ ## X)) \ + & (KHR_DF_MASK_ ## X)) + +/* Helper macro: + Set field X of basic descriptor block BDB */ +#define KHR_DFDSETVAL(BDB, X, val) \ + ((BDB)[KHR_DF_WORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_ ## X] & \ + ~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \ + (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X))) + +/* Offsets relative to the start of a sample */ +typedef enum _khr_df_sampleword_e { + KHR_DF_SAMPLEWORD_BITOFFSET = 0U, + KHR_DF_SAMPLEWORD_BITLENGTH = 0U, + KHR_DF_SAMPLEWORD_CHANNELID = 0U, + KHR_DF_SAMPLEWORD_QUALIFIERS = 0U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION0 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION1 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION2 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION3 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL = 1U, + KHR_DF_SAMPLEWORD_SAMPLELOWER = 2U, + KHR_DF_SAMPLEWORD_SAMPLEUPPER = 3U +} khr_df_sampleword_e; + +typedef enum _khr_df_sampleshift_e { + KHR_DF_SAMPLESHIFT_BITOFFSET = 0U, + KHR_DF_SAMPLESHIFT_BITLENGTH = 16U, + KHR_DF_SAMPLESHIFT_CHANNELID = 24U, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLESHIFT_QUALIFIERS = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION0 = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION1 = 8U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION2 = 16U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION3 = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION_ALL = 0U, + KHR_DF_SAMPLESHIFT_SAMPLELOWER = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEUPPER = 0U +} khr_df_sampleshift_e; + +typedef enum _khr_df_samplemask_e { + KHR_DF_SAMPLEMASK_BITOFFSET = 0xFFFFU, + KHR_DF_SAMPLEMASK_BITLENGTH = 0xFF, + KHR_DF_SAMPLEMASK_CHANNELID = 0xF, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLEMASK_QUALIFIERS = 0xF0, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION0 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION1 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION2 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION3 = 0xFF, + /* ISO C restricts enum values to range of int hence the + cast. We do it verbosely instead of using -1 to ensure + it is a 32-bit value even if int is 64 bits. */ + KHR_DF_SAMPLEMASK_SAMPLEPOSITION_ALL = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLELOWER = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLEUPPER = (int) 0xFFFFFFFFU +} khr_df_samplemask_e; + +/* Helper macro: + Extract field X of sample S from basic descriptor block BDB */ +#define KHR_DFDSVAL(BDB, S, X) \ + (((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] >> (KHR_DF_SAMPLESHIFT_ ## X)) \ + & (KHR_DF_SAMPLEMASK_ ## X)) + +/* Helper macro: + Set field X of sample S of basic descriptor block BDB */ +#define KHR_DFDSETSVAL(BDB, S, X, val) \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] & \ + ~((uint32_t)(KHR_DF_SAMPLEMASK_ ## X) << (KHR_DF_SAMPLESHIFT_ ## X))) | \ + (((val) & (uint32_t)(KHR_DF_SAMPLEMASK_ ## X)) << (KHR_DF_SAMPLESHIFT_ ## X))) + +/* Helper macro: + Number of samples in basic descriptor block BDB */ +#define KHR_DFDSAMPLECOUNT(BDB) \ + (((KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) >> 2) - \ + KHR_DF_WORD_SAMPLESTART) \ + / KHR_DF_WORD_SAMPLEWORDS) + +/* Helper macro: + Size in words of basic descriptor block for S samples */ +#define KHR_DFDSIZEWORDS(S) \ + (KHR_DF_WORD_SAMPLESTART + \ + (S) * KHR_DF_WORD_SAMPLEWORDS) + +/* Vendor ids */ +typedef enum _khr_df_vendorid_e { + /* Standard Khronos descriptor */ + KHR_DF_VENDORID_KHRONOS = 0U, + KHR_DF_VENDORID_MAX = 0x1FFFFU +} khr_df_vendorid_e; + +/* Descriptor types */ +typedef enum _khr_df_khr_descriptortype_e { + /* Default Khronos basic descriptor block */ + KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0U, + /* Extension descriptor block for additional planes */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_PLANES = 0x6001U, + /* Extension descriptor block for additional dimensions */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_DIMENSIONS = 0x6002U, + /* Bit indicates modifying requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_WRITE_BIT = 0x2000U, + /* Bit indicates processing requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_DECODE_BIT = 0x4000U, + KHR_DF_KHR_DESCRIPTORTYPE_MAX = 0x7FFFU +} khr_df_khr_descriptortype_e; + +/* Descriptor block version */ +typedef enum _khr_df_versionnumber_e { + /* Standard Khronos descriptor */ + KHR_DF_VERSIONNUMBER_1_0 = 0U, /* Version 1.0 of the specification */ + KHR_DF_VERSIONNUMBER_1_1 = 0U, /* Version 1.1 did not bump the version number */ + KHR_DF_VERSIONNUMBER_1_2 = 1U, /* Version 1.2 increased the version number */ + KHR_DF_VERSIONNUMBER_1_3 = 2U, /* Version 1.3 increased the version number */ + KHR_DF_VERSIONNUMBER_LATEST = KHR_DF_VERSIONNUMBER_1_3, + KHR_DF_VERSIONNUMBER_MAX = 0xFFFFU +} khr_df_versionnumber_e; + +/** @~English + @brief Model in which the color coordinate space is defined. + There is no requirement that a color format use all the + channel types that are defined in the color model. */ +typedef enum _khr_df_model_e { + /** No interpretation of color channels defined */ + KHR_DF_MODEL_UNSPECIFIED = 0U, + /** Color primaries (red, green, blue) + alpha, depth and stencil */ + KHR_DF_MODEL_RGBSDA = 1U, + /** Color differences (Y', Cb, Cr) + alpha, depth and stencil */ + KHR_DF_MODEL_YUVSDA = 2U, + /** Color differences (Y', I, Q) + alpha, depth and stencil */ + KHR_DF_MODEL_YIQSDA = 3U, + /** Perceptual color (CIE L*a*b*) + alpha, depth and stencil */ + KHR_DF_MODEL_LABSDA = 4U, + /** Subtractive colors (cyan, magenta, yellow, black) + alpha */ + KHR_DF_MODEL_CMYKA = 5U, + /** Non-color coordinate data (X, Y, Z, W) */ + KHR_DF_MODEL_XYZW = 6U, + /** Hue, saturation, value, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSVA_ANG = 7U, + /** Hue, saturation, lightness, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSLA_ANG = 8U, + /** Hue, saturation, value, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSVA_HEX = 9U, + /** Hue, saturation, lightness, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSLA_HEX = 10U, + /** Lightweight approximate color difference (luma, orange, green) */ + KHR_DF_MODEL_YCGCOA = 11U, + /** ITU BT.2020 constant luminance YcCbcCrc */ + KHR_DF_MODEL_YCCBCCRC = 12U, + /** ITU BT.2100 constant intensity ICtCp */ + KHR_DF_MODEL_ICTCP = 13U, + /** CIE 1931 XYZ color coordinates (X, Y, Z) */ + KHR_DF_MODEL_CIEXYZ = 14U, + /** CIE 1931 xyY color coordinates (X, Y, Y) */ + KHR_DF_MODEL_CIEXYY = 15U, + + /* Compressed formats start at 128. */ + /* These compressed formats should generally have a single sample, + sited at the 0,0 position of the texel block. Where multiple + channels are used to distinguish formats, these should be cosited. */ + /* Direct3D (and S3) compressed formats */ + /* Note that premultiplied status is recorded separately */ + /** DXT1 "channels" are RGB (0), Alpha (1) + DXT1/BC1 with one channel is opaque + DXT1/BC1 with a cosited alpha sample is transparent */ + KHR_DF_MODEL_DXT1A = 128U, + KHR_DF_MODEL_BC1A = 128U, + /** DXT2/DXT3/BC2, with explicit 4-bit alpha */ + KHR_DF_MODEL_DXT2 = 129U, + KHR_DF_MODEL_DXT3 = 129U, + KHR_DF_MODEL_BC2 = 129U, + /** DXT4/DXT5/BC3, with interpolated alpha */ + KHR_DF_MODEL_DXT4 = 130U, + KHR_DF_MODEL_DXT5 = 130U, + KHR_DF_MODEL_BC3 = 130U, + /** BC4 - single channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC4 = 131U, + /** BC5 - two channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC5 = 132U, + /** BC6H - DX11 format for 16-bit float channels */ + KHR_DF_MODEL_BC6H = 133U, + /** BC7 - DX11 format */ + KHR_DF_MODEL_BC7 = 134U, + /* Gap left for future desktop expansion */ + + /* Mobile compressed formats follow */ + /** A format of ETC1 indicates that the format shall be decodable + by an ETC1-compliant decoder and not rely on ETC2 features */ + KHR_DF_MODEL_ETC1 = 160U, + /** A format of ETC2 is permitted to use ETC2 encodings on top of + the baseline ETC1 specification. + The ETC2 format has channels "red", "green", "RGB" and "alpha", + which should be cosited samples. + Punch-through alpha can be distinguished from full alpha by + the plane size in bytes required for the texel block */ + KHR_DF_MODEL_ETC2 = 161U, + /** Adaptive Scalable Texture Compression */ + /** ASTC HDR vs LDR is determined by the float flag in the channel */ + /** ASTC block size can be distinguished by texel block size */ + KHR_DF_MODEL_ASTC = 162U, + /** ETC1S is a simplified subset of ETC1 */ + KHR_DF_MODEL_ETC1S = 163U, + /** PowerVR Texture Compression v1 */ + KHR_DF_MODEL_PVRTC = 164U, + /** PowerVR Texture Compression v2 */ + KHR_DF_MODEL_PVRTC2 = 165U, + /** UASTC is a transcodable subset of ASTC + with additions to support the transcoding. */ + KHR_DF_MODEL_UASTC = 166U, + /* Proprietary formats (ATITC, etc.) should follow */ + KHR_DF_MODEL_MAX = 0xFFU +} khr_df_model_e; + +/* Definition of channel names for each color model */ +typedef enum _khr_df_model_channels_e { + /* Unspecified format with nominal channel numbering */ + KHR_DF_CHANNEL_UNSPECIFIED_0 = 0U, + KHR_DF_CHANNEL_UNSPECIFIED_1 = 1U, + KHR_DF_CHANNEL_UNSPECIFIED_2 = 2U, + KHR_DF_CHANNEL_UNSPECIFIED_3 = 3U, + KHR_DF_CHANNEL_UNSPECIFIED_4 = 4U, + KHR_DF_CHANNEL_UNSPECIFIED_5 = 5U, + KHR_DF_CHANNEL_UNSPECIFIED_6 = 6U, + KHR_DF_CHANNEL_UNSPECIFIED_7 = 7U, + KHR_DF_CHANNEL_UNSPECIFIED_8 = 8U, + KHR_DF_CHANNEL_UNSPECIFIED_9 = 9U, + KHR_DF_CHANNEL_UNSPECIFIED_10 = 10U, + KHR_DF_CHANNEL_UNSPECIFIED_11 = 11U, + KHR_DF_CHANNEL_UNSPECIFIED_12 = 12U, + KHR_DF_CHANNEL_UNSPECIFIED_13 = 13U, + KHR_DF_CHANNEL_UNSPECIFIED_14 = 14U, + KHR_DF_CHANNEL_UNSPECIFIED_15 = 15U, + /* MODEL_RGBSDA - red, green, blue, stencil, depth, alpha */ + KHR_DF_CHANNEL_RGBSDA_RED = 0U, + KHR_DF_CHANNEL_RGBSDA_R = 0U, + KHR_DF_CHANNEL_RGBSDA_GREEN = 1U, + KHR_DF_CHANNEL_RGBSDA_G = 1U, + KHR_DF_CHANNEL_RGBSDA_BLUE = 2U, + KHR_DF_CHANNEL_RGBSDA_B = 2U, + KHR_DF_CHANNEL_RGBSDA_STENCIL = 13U, + KHR_DF_CHANNEL_RGBSDA_S = 13U, + KHR_DF_CHANNEL_RGBSDA_DEPTH = 14U, + KHR_DF_CHANNEL_RGBSDA_D = 14U, + KHR_DF_CHANNEL_RGBSDA_ALPHA = 15U, + KHR_DF_CHANNEL_RGBSDA_A = 15U, + /* MODEL_YUVSDA - luma, Cb, Cr, stencil, depth, alpha */ + KHR_DF_CHANNEL_YUVSDA_Y = 0U, + KHR_DF_CHANNEL_YUVSDA_CB = 1U, + KHR_DF_CHANNEL_YUVSDA_U = 1U, + KHR_DF_CHANNEL_YUVSDA_CR = 2U, + KHR_DF_CHANNEL_YUVSDA_V = 2U, + KHR_DF_CHANNEL_YUVSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YUVSDA_S = 13U, + KHR_DF_CHANNEL_YUVSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YUVSDA_D = 14U, + KHR_DF_CHANNEL_YUVSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YUVSDA_A = 15U, + /* MODEL_YIQSDA - luma, in-phase, quadrature, stencil, depth, alpha */ + KHR_DF_CHANNEL_YIQSDA_Y = 0U, + KHR_DF_CHANNEL_YIQSDA_I = 1U, + KHR_DF_CHANNEL_YIQSDA_Q = 2U, + KHR_DF_CHANNEL_YIQSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YIQSDA_S = 13U, + KHR_DF_CHANNEL_YIQSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YIQSDA_D = 14U, + KHR_DF_CHANNEL_YIQSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YIQSDA_A = 15U, + /* MODEL_LABSDA - CIELAB/L*a*b* luma, red-green, blue-yellow, stencil, depth, alpha */ + KHR_DF_CHANNEL_LABSDA_L = 0U, + KHR_DF_CHANNEL_LABSDA_A = 1U, + KHR_DF_CHANNEL_LABSDA_B = 2U, + KHR_DF_CHANNEL_LABSDA_STENCIL = 13U, + KHR_DF_CHANNEL_LABSDA_S = 13U, + KHR_DF_CHANNEL_LABSDA_DEPTH = 14U, + KHR_DF_CHANNEL_LABSDA_D = 14U, + KHR_DF_CHANNEL_LABSDA_ALPHA = 15U, + /* NOTE: KHR_DF_CHANNEL_LABSDA_A is not a synonym for alpha! */ + /* MODEL_CMYKA - cyan, magenta, yellow, key/blacK, alpha */ + KHR_DF_CHANNEL_CMYKSDA_CYAN = 0U, + KHR_DF_CHANNEL_CMYKSDA_C = 0U, + KHR_DF_CHANNEL_CMYKSDA_MAGENTA = 1U, + KHR_DF_CHANNEL_CMYKSDA_M = 1U, + KHR_DF_CHANNEL_CMYKSDA_YELLOW = 2U, + KHR_DF_CHANNEL_CMYKSDA_Y = 2U, + KHR_DF_CHANNEL_CMYKSDA_KEY = 3U, + KHR_DF_CHANNEL_CMYKSDA_BLACK = 3U, + KHR_DF_CHANNEL_CMYKSDA_K = 3U, + KHR_DF_CHANNEL_CMYKSDA_ALPHA = 15U, + KHR_DF_CHANNEL_CMYKSDA_A = 15U, + /* MODEL_XYZW - coordinates x, y, z, w */ + KHR_DF_CHANNEL_XYZW_X = 0U, + KHR_DF_CHANNEL_XYZW_Y = 1U, + KHR_DF_CHANNEL_XYZW_Z = 2U, + KHR_DF_CHANNEL_XYZW_W = 3U, + /* MODEL_HSVA_ANG - value (luma), saturation, hue, alpha, angular projection, conical space */ + KHR_DF_CHANNEL_HSVA_ANG_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_ANG_V = 0U, + KHR_DF_CHANNEL_HSVA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_ANG_S = 1U, + KHR_DF_CHANNEL_HSVA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSVA_ANG_H = 2U, + KHR_DF_CHANNEL_HSVA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_ANG_A = 15U, + /* MODEL_HSLA_ANG - lightness (luma), saturation, hue, alpha, angular projection, double conical space */ + KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_ANG_L = 0U, + KHR_DF_CHANNEL_HSLA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_ANG_S = 1U, + KHR_DF_CHANNEL_HSLA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSLA_ANG_H = 2U, + KHR_DF_CHANNEL_HSLA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_ANG_A = 15U, + /* MODEL_HSVA_HEX - value (luma), saturation, hue, alpha, hexagonal projection, conical space */ + KHR_DF_CHANNEL_HSVA_HEX_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_HEX_V = 0U, + KHR_DF_CHANNEL_HSVA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_HEX_S = 1U, + KHR_DF_CHANNEL_HSVA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSVA_HEX_H = 2U, + KHR_DF_CHANNEL_HSVA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_HEX_A = 15U, + /* MODEL_HSLA_HEX - lightness (luma), saturation, hue, alpha, hexagonal projection, double conical space */ + KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_HEX_L = 0U, + KHR_DF_CHANNEL_HSLA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_HEX_S = 1U, + KHR_DF_CHANNEL_HSLA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSLA_HEX_H = 2U, + KHR_DF_CHANNEL_HSLA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_HEX_A = 15U, + /* MODEL_YCGCOA - luma, green delta, orange delta, alpha */ + KHR_DF_CHANNEL_YCGCOA_Y = 0U, + KHR_DF_CHANNEL_YCGCOA_CG = 1U, + KHR_DF_CHANNEL_YCGCOA_CO = 2U, + KHR_DF_CHANNEL_YCGCOA_ALPHA = 15U, + KHR_DF_CHANNEL_YCGCOA_A = 15U, + /* MODEL_CIEXYZ - CIE 1931 X, Y, Z */ + KHR_DF_CHANNEL_CIEXYZ_X = 0U, + KHR_DF_CHANNEL_CIEXYZ_Y = 1U, + KHR_DF_CHANNEL_CIEXYZ_Z = 2U, + /* MODEL_CIEXYY - CIE 1931 x, y, Y */ + KHR_DF_CHANNEL_CIEXYY_X = 0U, + KHR_DF_CHANNEL_CIEXYY_YCHROMA = 1U, + KHR_DF_CHANNEL_CIEXYY_YLUMA = 2U, + + /* Compressed formats */ + /* MODEL_DXT1A/MODEL_BC1A */ + KHR_DF_CHANNEL_DXT1A_COLOR = 0U, + KHR_DF_CHANNEL_BC1A_COLOR = 0U, + KHR_DF_CHANNEL_DXT1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_DXT1A_ALPHA = 1U, + KHR_DF_CHANNEL_BC1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_BC1A_ALPHA = 1U, + /* MODEL_DXT2/3/MODEL_BC2 */ + KHR_DF_CHANNEL_DXT2_COLOR = 0U, + KHR_DF_CHANNEL_DXT3_COLOR = 0U, + KHR_DF_CHANNEL_BC2_COLOR = 0U, + KHR_DF_CHANNEL_DXT2_ALPHA = 15U, + KHR_DF_CHANNEL_DXT3_ALPHA = 15U, + KHR_DF_CHANNEL_BC2_ALPHA = 15U, + /* MODEL_DXT4/5/MODEL_BC3 */ + KHR_DF_CHANNEL_DXT4_COLOR = 0U, + KHR_DF_CHANNEL_DXT5_COLOR = 0U, + KHR_DF_CHANNEL_BC3_COLOR = 0U, + KHR_DF_CHANNEL_DXT4_ALPHA = 15U, + KHR_DF_CHANNEL_DXT5_ALPHA = 15U, + KHR_DF_CHANNEL_BC3_ALPHA = 15U, + /* MODEL_BC4 */ + KHR_DF_CHANNEL_BC4_DATA = 0U, + /* MODEL_BC5 */ + KHR_DF_CHANNEL_BC5_RED = 0U, + KHR_DF_CHANNEL_BC5_R = 0U, + KHR_DF_CHANNEL_BC5_GREEN = 1U, + KHR_DF_CHANNEL_BC5_G = 1U, + /* MODEL_BC6H */ + KHR_DF_CHANNEL_BC6H_COLOR = 0U, + KHR_DF_CHANNEL_BC6H_DATA = 0U, + /* MODEL_BC7 */ + KHR_DF_CHANNEL_BC7_DATA = 0U, + KHR_DF_CHANNEL_BC7_COLOR = 0U, + /* MODEL_ETC1 */ + KHR_DF_CHANNEL_ETC1_DATA = 0U, + KHR_DF_CHANNEL_ETC1_COLOR = 0U, + /* MODEL_ETC2 */ + KHR_DF_CHANNEL_ETC2_RED = 0U, + KHR_DF_CHANNEL_ETC2_R = 0U, + KHR_DF_CHANNEL_ETC2_GREEN = 1U, + KHR_DF_CHANNEL_ETC2_G = 1U, + KHR_DF_CHANNEL_ETC2_COLOR = 2U, + KHR_DF_CHANNEL_ETC2_ALPHA = 15U, + KHR_DF_CHANNEL_ETC2_A = 15U, + /* MODEL_ASTC */ + KHR_DF_CHANNEL_ASTC_DATA = 0U, + /* MODEL_ETC1S */ + KHR_DF_CHANNEL_ETC1S_RGB = 0U, + KHR_DF_CHANNEL_ETC1S_RRR = 3U, + KHR_DF_CHANNEL_ETC1S_GGG = 4U, + KHR_DF_CHANNEL_ETC1S_AAA = 15U, + /* MODEL_PVRTC */ + KHR_DF_CHANNEL_PVRTC_DATA = 0U, + KHR_DF_CHANNEL_PVRTC_COLOR = 0U, + /* MODEL_PVRTC2 */ + KHR_DF_CHANNEL_PVRTC2_DATA = 0U, + KHR_DF_CHANNEL_PVRTC2_COLOR = 0U, + /* MODEL UASTC */ + KHR_DF_CHANNEL_UASTC_DATA = 0U, + KHR_DF_CHANNEL_UASTC_RGB = 0U, + KHR_DF_CHANNEL_UASTC_RGBA = 3U, + KHR_DF_CHANNEL_UASTC_RRR = 4U, + KHR_DF_CHANNEL_UASTC_RRRG = 5U, + KHR_DF_CHANNEL_UASTC_RG = 6U, + + /* Common channel names shared by multiple formats */ + KHR_DF_CHANNEL_COMMON_LUMA = 0U, + KHR_DF_CHANNEL_COMMON_L = 0U, + KHR_DF_CHANNEL_COMMON_STENCIL = 13U, + KHR_DF_CHANNEL_COMMON_S = 13U, + KHR_DF_CHANNEL_COMMON_DEPTH = 14U, + KHR_DF_CHANNEL_COMMON_D = 14U, + KHR_DF_CHANNEL_COMMON_ALPHA = 15U, + KHR_DF_CHANNEL_COMMON_A = 15U +} khr_df_model_channels_e; + +/** @~English + @brief Definition of the primary colors in color coordinates. + This is implicitly responsible for defining the conversion + between RGB an YUV color spaces. + LAB and related absolute color models should use + KHR_DF_PRIMARIES_CIEXYZ. */ +typedef enum _khr_df_primaries_e { + /** No color primaries defined */ + KHR_DF_PRIMARIES_UNSPECIFIED = 0U, + /** Color primaries of ITU-R BT.709 and sRGB */ + KHR_DF_PRIMARIES_BT709 = 1U, + /** Synonym for KHR_DF_PRIMARIES_BT709 */ + KHR_DF_PRIMARIES_SRGB = 1U, + /** Color primaries of ITU-R BT.601 (625-line EBU variant) */ + KHR_DF_PRIMARIES_BT601_EBU = 2U, + /** Color primaries of ITU-R BT.601 (525-line SMPTE C variant) */ + KHR_DF_PRIMARIES_BT601_SMPTE = 3U, + /** Color primaries of ITU-R BT.2020 */ + KHR_DF_PRIMARIES_BT2020 = 4U, + /** CIE theoretical color coordinate space */ + KHR_DF_PRIMARIES_CIEXYZ = 5U, + /** Academy Color Encoding System primaries */ + KHR_DF_PRIMARIES_ACES = 6U, + /** Color primaries of ACEScc */ + KHR_DF_PRIMARIES_ACESCC = 7U, + /** Legacy NTSC 1953 primaries */ + KHR_DF_PRIMARIES_NTSC1953 = 8U, + /** Legacy PAL 525-line primaries */ + KHR_DF_PRIMARIES_PAL525 = 9U, + /** Color primaries of Display P3 */ + KHR_DF_PRIMARIES_DISPLAYP3 = 10U, + /** Color primaries of Adobe RGB (1998) */ + KHR_DF_PRIMARIES_ADOBERGB = 11U, + KHR_DF_PRIMARIES_MAX = 0xFFU +} khr_df_primaries_e; + +/** @~English + @brief Definition of the optical to digital transfer function + ("gamma correction"). Most transfer functions are not a pure + power function and also include a linear element. + LAB and related absolute color representations should use + KHR_DF_TRANSFER_UNSPECIFIED. */ +typedef enum _khr_df_transfer_e { + /** No transfer function defined */ + KHR_DF_TRANSFER_UNSPECIFIED = 0U, + /** Linear transfer function (value proportional to intensity) */ + KHR_DF_TRANSFER_LINEAR = 1U, + /** Perceptually-linear transfer function of sRGH (~2.4) */ + KHR_DF_TRANSFER_SRGB = 2U, + /** Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45) */ + KHR_DF_TRANSFER_ITU = 3U, + /** SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) */ + KHR_DF_TRANSFER_SMTPE170M = 3U, + /** Perceptually-linear gamma function of original NTSC (simple 2.2 gamma) */ + KHR_DF_TRANSFER_NTSC = 4U, + /** Sony S-log used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG = 5U, + /** Sony S-log 2 used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG2 = 6U, + /** ITU BT.1886 EOTF */ + KHR_DF_TRANSFER_BT1886 = 7U, + /** ITU BT.2100 HLG OETF */ + KHR_DF_TRANSFER_HLG_OETF = 8U, + /** ITU BT.2100 HLG EOTF */ + KHR_DF_TRANSFER_HLG_EOTF = 9U, + /** ITU BT.2100 PQ EOTF */ + KHR_DF_TRANSFER_PQ_EOTF = 10U, + /** ITU BT.2100 PQ OETF */ + KHR_DF_TRANSFER_PQ_OETF = 11U, + /** DCI P3 transfer function */ + KHR_DF_TRANSFER_DCIP3 = 12U, + /** Legacy PAL OETF */ + KHR_DF_TRANSFER_PAL_OETF = 13U, + /** Legacy PAL 625-line EOTF */ + KHR_DF_TRANSFER_PAL625_EOTF = 14U, + /** Legacy ST240 transfer function */ + KHR_DF_TRANSFER_ST240 = 15U, + /** ACEScc transfer function */ + KHR_DF_TRANSFER_ACESCC = 16U, + /** ACEScct transfer function */ + KHR_DF_TRANSFER_ACESCCT = 17U, + /** Adobe RGB (1998) transfer function */ + KHR_DF_TRANSFER_ADOBERGB = 18U, + KHR_DF_TRANSFER_MAX = 0xFFU +} khr_df_transfer_e; + +typedef enum _khr_df_flags_e { + KHR_DF_FLAG_ALPHA_STRAIGHT = 0U, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1U +} khr_df_flags_e; + +typedef enum _khr_df_sample_datatype_qualifiers_e { + KHR_DF_SAMPLE_DATATYPE_LINEAR = 1U << 4U, + KHR_DF_SAMPLE_DATATYPE_EXPONENT = 1U << 5U, + KHR_DF_SAMPLE_DATATYPE_SIGNED = 1U << 6U, + KHR_DF_SAMPLE_DATATYPE_FLOAT = 1U << 7U +} khr_df_sample_datatype_qualifiers_e; + +#endif diff --git a/KTXLoader/libktx/ktx.xcframework/xros-arm64/Headers/ktx.h b/KTXLoader/libktx/ktx.xcframework/xros-arm64/Headers/ktx.h new file mode 100644 index 00000000..fd321c30 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/xros-arm64/Headers/ktx.h @@ -0,0 +1,1835 @@ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + +#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1 +#define KTX_H_A55A6F00956F42F3A137C11929827FE1 + +/* + * Copyright 2010-2018 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + * + * See the accompanying LICENSE.md for licensing details for all files in + * the KTX library and KTX loader tests. + */ + +/** + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX API. + * + * @author Mark Callow, Edgewise Consulting and while at HI Corporation + * @author Based on original work by Georg Kolling, Imagination Technology + * + * @snippet{doc} version.h API version + */ + +#include +#include +#include + +#include + +/* + * Don't use khrplatform.h in order not to break apps existing + * before these definitions were needed. + */ +#if defined(KHRONOS_STATIC) + #define KTX_API +#elif defined(_WIN32) || defined(__CYGWIN__) + #if !defined(KTX_API) + #if __GNUC__ + #define KTX_API __attribute__ ((dllimport)) + #elif _MSC_VER + #define KTX_API __declspec(dllimport) + #else + #error "Your compiler's equivalent of dllimport is unknown" + #endif + #endif +#elif defined(__ANDROID__) + #define KTX_API __attribute__((visibility("default"))) +#else + #define KTX_API +#endif + +#if defined(_WIN32) && !defined(KHRONOS_STATIC) + #if !defined(KTX_APIENTRY) + #define KTX_APIENTRY __stdcall + #endif +#else + #define KTX_APIENTRY +#endif + +/* To avoid including define our own types. */ +typedef unsigned char ktx_uint8_t; +typedef bool ktx_bool_t; +#ifdef _MSC_VER +typedef unsigned __int16 ktx_uint16_t; +typedef signed __int16 ktx_int16_t; +typedef unsigned __int32 ktx_uint32_t; +typedef signed __int32 ktx_int32_t; +typedef size_t ktx_size_t; +typedef unsigned __int64 ktx_uint64_t; +typedef signed __int64 ktx_int64_t; +#else +#include +typedef uint16_t ktx_uint16_t; +typedef int16_t ktx_int16_t; +typedef uint32_t ktx_uint32_t; +typedef int32_t ktx_int32_t; +typedef size_t ktx_size_t; +typedef uint64_t ktx_uint64_t; +typedef int64_t ktx_int64_t; +#endif + +/* This will cause compilation to fail if size of uint32 != 4. */ +typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4]; + +/* + * This #if allows libktx to be compiled with strict c99. It avoids + * compiler warnings or even errors when a gl.h is already included. + * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if + * gl.h comes after. However nobody has complained about the unguarded typedefs + * since they were introduced so this is unlikely to be a problem in practice. + * Presumably everybody is using platform default compilers not c99 or else + * they are using C++. + */ +#if !defined(GL_NO_ERROR) + /* + * To avoid having to including gl.h ... + */ + typedef unsigned char GLboolean; + typedef unsigned int GLenum; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLuint; + typedef unsigned char GLubyte; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_ANIMDATA_KEY "KTXanimData" +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +#define KTX_ORIENTATION_KEY "KTXorientation" +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +#define KTX_SWIZZLE_KEY "KTXswizzle" +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_WRITER_KEY "KTXwriter" +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams" +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +#define KTX_ORIENTATION1_FMT "S=%c" +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +#define KTX_ORIENTATION2_FMT "S=%c,T=%c" +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c" +/** + * @~English + * @brief Required unpack alignment + */ +#define KTX_GL_UNPACK_ALIGNMENT 4 + +#define KTX_TRUE true +#define KTX_FALSE false + +/** + * @~English + * @brief Error codes returned by library functions. + */ +typedef enum ktx_error_code_e { + KTX_SUCCESS = 0, /*!< Operation was successful. */ + KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */ + KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */ + KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */ + KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */ + KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */ + KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */ + KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */ + KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */ + KTX_GL_ERROR, /*!< GL operations resulted in an error. */ + KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ + KTX_INVALID_VALUE, /*!< A parameter value was not valid */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ + KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ + KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ + KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ + KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */ + KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */ + KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */ + KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */ + KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */ + KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */ +} ktx_error_code_e; +/** + * @deprecated + * @~English + * @brief For backward compatibility + */ +#define KTX_error_code ktx_error_code_e + +#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } +#define KTX_ENDIAN_REF (0x04030201) +#define KTX_ENDIAN_REF_REV (0x01020304) +#define KTX_HEADER_SIZE (64) + +/** + * @~English + * @brief Result codes returned by library functions. + */ + typedef enum ktx_error_code_e ktxResult; + +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ +typedef struct ktxKVListEntry* ktxHashList; + +typedef struct ktxStream ktxStream; + +#define KTX_APIENTRYP KTX_APIENTRY * +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ +typedef struct ktxKVListEntry ktxHashListEntry; + +typedef enum ktxOrientationX { + KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r' +} ktxOrientationX; + +typedef enum ktxOrientationY { + KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd' +} ktxOrientationY; + +typedef enum ktxOrientationZ { + KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o' +} ktxOrientationZ; + +typedef enum class_id { + ktxTexture1_c = 1, + ktxTexture2_c = 2 +} class_id; + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +struct ktxOrientation { + ktxOrientationX x; /*!< Orientation in X */ + ktxOrientationY y; /*!< Orientation in Y */ + ktxOrientationZ z; /*!< Orientation in Z */ +}; + +#define KTXTEXTURECLASSDEFN \ + class_id classId; \ + struct ktxTexture_vtbl* vtbl; \ + struct ktxTexture_vvtbl* vvtbl; \ + struct ktxTexture_protected* _protected; \ + ktx_bool_t isArray; \ + ktx_bool_t isCubemap; \ + ktx_bool_t isCompressed; \ + ktx_bool_t generateMipmaps; \ + ktx_uint32_t baseWidth; \ + ktx_uint32_t baseHeight; \ + ktx_uint32_t baseDepth; \ + ktx_uint32_t numDimensions; \ + ktx_uint32_t numLevels; \ + ktx_uint32_t numLayers; \ + ktx_uint32_t numFaces; \ + struct ktxOrientation orientation; \ + ktxHashList kvDataHead; \ + ktx_uint32_t kvDataLen; \ + ktx_uint8_t* kvData; \ + ktx_size_t dataSize; \ + ktx_uint8_t* pData; + + +/** + * @class ktxTexture + * @~English + * @brief Base class representing a texture. + * + * ktxTextures should be created only by one of the provided + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture { + KTXTEXTURECLASSDEFN +} ktxTexture; +/** + * @typedef ktxTexture::classId + * @~English + * @brief Identify the class type. + * + * Since there are no public ktxTexture constructors, this can only have + * values of ktxTexture1_c or ktxTexture2_c. + */ +/** + * @typedef ktxTexture::vtbl + * @~English + * @brief Pointer to the class's vtble. + */ +/** + * @typedef ktxTexture::vvtbl + * @~English + * @brief Pointer to the class's vtble for Vulkan functions. + * + * A separate vtble is used so this header does not need to include vulkan.h. + */ +/** + * @typedef ktxTexture::_protected + * @~English + * @brief Opaque pointer to the class's protected variables. + */ +/** + * @typedef ktxTexture::isArray + * @~English + * + * KTX_TRUE if the texture is an array texture, i.e, + * a GL_TEXTURE_*_ARRAY target is to be used. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture is a cubemap or cubemap array. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture's format is a block compressed format. + */ +/** + * @typedef ktxTexture::generateMipmaps + * @~English + * + * KTX_TRUE if mipmaps should be generated for the texture by + * ktxTexture_GLUpload() or ktxTexture_VkUpload(). + */ +/**n + * @typedef ktxTexture::baseWidth + * @~English + * @brief Width of the texture's base level. + */ +/** + * @typedef ktxTexture::baseHeight + * @~English + * @brief Height of the texture's base level. + */ +/** + * @typedef ktxTexture::baseDepth + * @~English + * @brief Depth of the texture's base level. + */ +/** + * @typedef ktxTexture::numDimensions + * @~English + * @brief Number of dimensions in the texture: 1, 2 or 3. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of mip levels in the texture. + * + * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a + * full pyramid but always starts at the base level. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of array layers in the texture. + */ +/** + * @typedef ktxTexture::numFaces + * @~English + * @brief Number of faces: 6 for cube maps, 1 otherwise. + */ +/** + * @typedef ktxTexture::orientation + * @~English + * @brief Describes the logical orientation of the images in each dimension. + * + * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z. + */ +/** + * @typedef ktxTexture::kvDataHead + * @~English + * @brief Head of the hash list of metadata. + */ +/** + * @typedef ktxTexture::kvDataLen + * @~English + * @brief Length of the metadata, if it has been extracted in its raw form, + * otherwise 0. + */ +/** + * @typedef ktxTexture::kvData + * @~English + * @brief Pointer to the metadata, if it has been extracted in its raw form, + * otherwise NULL. + */ +/** + * @typedef ktxTexture::dataSize + * @~English + * @brief Byte length of the texture's uncompressed image data. + */ +/** + * @typedef ktxTexture::pData + * @~English + * @brief Pointer to the start of the image data. + */ + +/** + * @memberof ktxTexture + * @~English + * @brief Signature of function called by the ktxTexture_Iterate* + * functions to receive image data. + * + * The function parameters are used to pass values which change for each image. + * Obtain values which are uniform across all images from the @c ktxTexture + * object. + * + * @param [in] miplevel MIP level from 0 to the max level which is + * dependent on the texture size. + * @param [in] face usually 0; for cube maps, one of the 6 cube + * faces in the order +X, -X, +Y, -Y, +Z, -Z, + * 0 to 5. + * @param [in] width width of the image. + * @param [in] height height of the image or, for 1D textures + * textures, 1. + * @param [in] depth depth of the image or, for 1D & 2D + * textures, 1. + * @param [in] faceLodSize number of bytes of data pointed at by + * @p pixels. + * @param [in] pixels pointer to the image data. + * @param [in,out] userdata pointer for the application to pass data to and + * from the callback function. + */ + +typedef KTX_error_code + (* PFNKTXITERCB)(int miplevel, int face, + int width, int height, int depth, + ktx_uint64_t faceLodSize, + void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + ktx_size_t* pOffset); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This, + PFNKTXITERCB iterCb, + void* userdata); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This, + ktx_uint8_t* pBuffer, + ktx_size_t bufSize); +typedef ktx_bool_t + (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + const ktx_uint8_t* src, + ktx_size_t srcSize); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + FILE* src, ktx_size_t srcSize); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This, + const char* const dstname); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, + ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + struct ktxTexture_vtbl { + PFNKTEXDESTROY Destroy; + PFNKTEXGETIMAGEOFFSET GetImageOffset; + PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + PFNKTEXGETIMAGESIZE GetImageSize; + PFNKTEXITERATELEVELS IterateLevels; + PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + PFNKTEXLOADIMAGEDATA LoadImageData; + PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; +}; + +/**************************************************************** + * Macros to give some backward compatibility to the previous API + ****************************************************************/ + +/** + * @~English + * @brief Helper for calling the Destroy virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_Destroy + */ +#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This) + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \ + (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset) + +/** + * @~English + * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture. + * + * For a ktxTexture1 this will always return the value of This->dataSize. + * + * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed + */ +#define ktxTexture_GetDataSizeUncompressed(This) \ + (This)->vtbl->GetDataSizeUncompressed(This) + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +#define ktxTexture_GetImageSize(This, level) \ + (This)->vtbl->GetImageSize(This, level) + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +#define ktxTexture_IterateLevels(This, iterCb, userdata) \ + (This)->vtbl->IterateLevels(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \ + (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \ + (This)->vtbl->LoadImageData(This, pBuffer, bufSize) + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This) + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize) + +/** + * @~English + * @brief Helper for calling the SetImageFromStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream + */ +#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) + +/** + * @~English + * @brief Helper for calling the WriteToStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream + */ +#define ktxTexture_WriteToStdioStream(This, dstsstr) \ + (This)->vtbl->WriteToStdioStream(This, dstsstr) + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +#define ktxTexture_WriteToNamedFile(This, dstname) \ + (This)->vtbl->WriteToNamedFile(This, dstname) + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ + (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + + +/** + * @class ktxTexture1 + * @~English + * @brief Class representing a KTX version 1 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture1 { + KTXTEXTURECLASSDEFN + ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + struct ktxTexture1_private* _private; /*!< Private data. */ +} ktxTexture1; + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +typedef enum ktxSupercmpScheme { + KTX_SS_NONE = 0, /*!< No supercompression. */ + KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */ + KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */ + KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */ + KTX_SS_BEGIN_RANGE = KTX_SS_NONE, + KTX_SS_END_RANGE = KTX_SS_ZLIB, + KTX_SS_BEGIN_VENDOR_RANGE = 0x10000, + KTX_SS_END_VENDOR_RANGE = 0x1ffff, + KTX_SS_BEGIN_RESERVED = 0x20000, + KTX_SUPERCOMPRESSION_BASIS = KTX_SS_BASIS_LZ, + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_BASIS_LZ instead. */ + KTX_SUPERCOMPRESSION_ZSTD = KTX_SS_ZSTD + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_ZSTD instead. */ +} ktxSupercmpScheme; + +/** + * @class ktxTexture2 + * @~English + * @brief Class representing a KTX version 2 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture2 { + KTXTEXTURECLASSDEFN + ktx_uint32_t vkFormat; + ktx_uint32_t* pDfd; + ktxSupercmpScheme supercompressionScheme; + ktx_bool_t isVideo; + ktx_uint32_t duration; + ktx_uint32_t timescale; + ktx_uint32_t loopcount; + struct ktxTexture2_private* _private; /*!< Private data. */ +} ktxTexture2; + +#define ktxTexture(t) ((ktxTexture*)t) + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1_Create() and + * ktxTexture2_Create(). + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef struct +{ + ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an + array texture. Means OpenGL will use a + GL_TEXTURE_*_ARRAY target. */ + ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} ktxTextureCreateInfo; + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef enum { + KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */ + KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */ +} ktxTextureCreateStorageEnum; + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +enum ktxTextureCreateFlagBits { + KTX_TEXTURE_CREATE_NO_FLAGS = 0x00, + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01, + /*!< Load the images from the KTX source. */ + KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08 + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +}; +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +typedef ktx_uint32_t ktxTextureCreateFlags; + +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + ktxStream_write write; /*!< pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< destruct the stream. */ + + enum streamType type; + union { + FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + struct + { + void* address; /**< pointer to the data. */ + void* allocatorAddress; /**< pointer to a memory allocator. */ + ktx_size_t size; /**< size of the data. */ + } custom_ptr; /**< pointer to a struct for custom streams. */ + } data; /**< pointer to the stream data. */ + ktx_off_t readpos; /**< used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +}; + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ +KTX_API ktx_uint8_t* KTX_APIENTRY +ktxTexture_GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ +KTX_API ktx_size_t KTX_APIENTRY +ktxTexture_GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, + GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); +/* + * Create a new ktxTexture1. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture1_NeedsTranscoding(ktxTexture1* This); + +/* + * Write a ktxTexture object to a stdio stream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + +/* + * Write a ktxTexture object to a named file in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname); + +/* + * Write a ktxTexture object to a block of memory in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, + ktx_uint8_t** bytes, ktx_size_t* size); + +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + +/* + * Create a new ktxTexture2. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + +KTX_API void KTX_APIENTRY +ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, + ktx_uint32_t* componentByteLength); + +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetNumComponents(ktxTexture2* This); + +KTX_API khr_df_transfer_e KTX_APIENTRY +ktxTexture2_GetOETF_e(ktxTexture2* This); + +// For backward compatibility +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetOETF(ktxTexture2* This); + +KTX_API khr_df_model_e KTX_APIENTRY +ktxTexture2_GetColorModel_e(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_NeedsTranscoding(ktxTexture2* This); + +/** + * @~English + * @brief Flags specifiying UASTC encoding options. + */ +typedef enum ktx_pack_uastc_flag_bits_e { + KTX_PACK_UASTC_LEVEL_FASTEST = 0, + /*!< Fastest compression. 43.45dB. */ + KTX_PACK_UASTC_LEVEL_FASTER = 1, + /*!< Faster compression. 46.49dB. */ + KTX_PACK_UASTC_LEVEL_DEFAULT = 2, + /*!< Default compression. 47.47dB. */ + KTX_PACK_UASTC_LEVEL_SLOWER = 3, + /*!< Slower compression. 48.01dB. */ + KTX_PACK_UASTC_LEVEL_VERYSLOW = 4, + /*!< Very slow compression. 48.24dB. */ + KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW, + /*!< Maximum supported quality level. */ + KTX_PACK_UASTC_LEVEL_MASK = 0xF, + /*!< Mask to extract the level from the other bits. */ + KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8, + /*!< Optimize for lowest UASTC error. */ + KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16, + /*!< Optimize for lowest BC7 error. */ + KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64, + /*!< Optimize for faster transcoding to ETC1. */ + KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128, + /*!< Optimize for fastest transcoding to ETC1. */ + KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256 + /*!< Not documented in BasisU code. */ +} ktx_pack_uastc_flag_bits_e; +typedef ktx_uint32_t ktx_pack_uastc_flags; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +typedef enum ktx_pack_astc_quality_levels_e { + KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0, + /*!< Fastest compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10, + /*!< Fast compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60, + /*!< Medium compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98, + /*!< Slower compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100, + /*!< Very slow compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE, + /*!< Maximum supported quality level. */ +} ktx_pack_astc_quality_levels_e; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +typedef enum ktx_pack_astc_block_dimension_e { + // 2D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp + // 3D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6 + /*!< Maximum supported blocks. */ +} ktx_pack_astc_block_dimension_e; + +/** + * @~English + * @brief Options specifying ASTC encoder profile mode + * This and function is used later to derive the profile. + */ +typedef enum ktx_pack_astc_encoder_mode_e { + KTX_PACK_ASTC_ENCODER_MODE_DEFAULT, + KTX_PACK_ASTC_ENCODER_MODE_LDR, + KTX_PACK_ASTC_ENCODER_MODE_HDR, + KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR +} ktx_pack_astc_encoder_mode_e; + +extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture_CompressAstc. + * + * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension + * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to + * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended. + */ +typedef struct ktxAstcParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + ktx_uint32_t qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps + In this mode normals are compressed to X,Y components + Discarding Z component, reader will need to generate Z + component in shaders. + */ + + ktx_bool_t perceptual; + /*!< The codec should optimize for perceptual error, instead of direct + RMS error. This aims to improves perceived image quality, but + typically lowers the measured PSNR score. Perceptual methods are + currently only available for normal maps and RGB color data. + */ + + char inputSwizzle[4]; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} ktxAstcParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + +/** + * @memberof ktxTexture2 + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture2_CompressBasisEx(). + * + * If you only want default values, use ktxTexture2_CompressBasis(). Here, at a minimum you + * must initialize the structure as follows: + * @code + * ktxBasisParams params = {0}; + * params.structSize = sizeof(params); + * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e compressionLevel has to be explicitly set because 0 is a valid @e compressionLevel + * but is not the default used by the BasisU encoder when no value is set. Only the other + * settings that are to be non-default must be non-zero. + */ +typedef struct ktxBasisParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + ktx_bool_t uastc; + /*!< True to use UASTC base, false to use ETC1S base. */ + ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + ktx_uint32_t compressionLevel; + /*!< Encoding speed vs. quality tradeoff. Range is [0,5]. Higher values + are slower, but give higher quality. There is no default. Callers + must explicitly set this value. Callers can use + KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL as a default value. + Currently this is 2. + */ + ktx_uint32_t qualityLevel; + /*!< Compression quality. Range is [1,255]. Lower gives better + compression/lower quality/faster. Higher gives less compression + /higher quality/slower. This automatically determines values for + @c maxEndpoints, @c maxSelectors, + @c endpointRDOThreshold and @c selectorRDOThreshold + for the target quality level. Setting these parameters overrides + the values determined by @c qualityLevel which defaults to + 128 if neither it nor both of @c maxEndpoints and + @c maxSelectors have been set. + @note @e Both of @c maxEndpoints and @c maxSelectors + must be set for them to have any effect. + @note qualityLevel will only determine values for + @c endpointRDOThreshold and @c selectorRDOThreshold + when its value exceeds 128, otherwise their defaults will be used. + */ + ktx_uint32_t maxEndpoints; + /*!< Manually set the max number of color endpoint clusters. + Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors + must also be set, otherwise the value will be ignored. + */ + float endpointRDOThreshold; + /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is + higher quality but less quality per output bit (try [1.0,3.0]. + This will override the value chosen by @c qualityLevel. + */ + ktx_uint32_t maxSelectors; + /*!< Manually set the max number of color selector clusters. Range + is [1,16128]. Default is 0, unset. If this is set, maxEndpoints + must also be set, otherwise the value will be ignored. + */ + float selectorRDOThreshold; + /*!< Set selector RDO quality threshold. The default is 1.5. Lower is + higher quality but less quality per output bit (try [1.0,3.0]). + This will override the value chosen by @c qualityLevel. + */ + char inputSwizzle[4]; + /*!< A swizzle to apply before encoding. It must match the regular + expression /^[rgba01]{4}$/. If both this and preSwizzle + are specified ktxTexture_CompressBasisEx will raise + KTX_INVALID_OPERATION. + */ + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps (no + selector RDO, no endpoint RDO) and sets the texture's DFD appropriately. + Only valid for linear textures. + */ + ktx_bool_t separateRGToRGB_A; + /*!< @deprecated. This was and is a no-op. 2-component inputs have always been + automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode. + */ + ktx_bool_t preSwizzle; + /*!< If the texture has @c KTXswizzle metadata, apply it before + compressing. Swizzling, like @c rabb may yield drastically + different error metrics if done after supercompression. + */ + ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + ktx_bool_t noSelectorRDO; + /*!< Disable selector rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + + /* UASTC params */ + + ktx_pack_uastc_flags uastcFlags; + /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC + encoding. The most important value is the level given in the + least-significant 4 bits which selects a speed vs quality tradeoff + as shown in the following table: + + Level/Speed | Quality + :-----: | :-------: + KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB + KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB + KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB + KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB + KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB + */ + ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + float uastcRDOQualityScalar; + /*!< UASTC RDO quality scalar (lambda). Lower values yield higher + quality/larger LZ compressed files, higher values yield lower + quality/smaller LZ compressed files. A good range to try is [.2,4]. + Full range is [.001,50.0]. Default is 1.0. + */ + ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + float uastcRDOMaxSmoothBlockErrorScale; + /*!< UASTC RDO max smooth block error scale. Range is [1,300]. + Default is 10.0, 1.0 is disabled. Larger values suppress more + artifacts (and allocate more bits) on smooth blocks. + */ + float uastcRDOMaxSmoothBlockStdDev; + /*!< UASTC RDO max smooth block standard deviation. Range is + [.01,65536.0]. Default is 18.0. Larger values expand the range of + blocks considered smooth. + */ + ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + +} ktxBasisParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params); + +/** + * @~English + * @brief Enumerators for specifying the transcode target format. + * + * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate + * RGB images, a.k.a slices within the BasisU compressed data. For UASTC + * format they refer to the RGB and the alpha components of the UASTC data. If + * the original image had only 2 components, R will be in the opaque portion + * and G in the alpha portion. The R value will be replicated in the RGB + * components. In the case of BasisU the G value will be replicated in all 3 + * components of the alpha slice. If the original image had only 1 component + * it's value is replicated in all 3 components of the opaque portion and + * there is no alpha. + * + * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R, + * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565, + * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor + * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader + * will not produce correct results if any texture filtering is being used. + */ +typedef enum ktx_transcode_fmt_e { + // Compressed formats + + // ETC1-2 + KTX_TTF_ETC1_RGB = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_RGBA = 1, + /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + + // BC1-5, BC7 (desktop, some mobile devices) + KTX_TTF_BC1_RGB = 2, + /*!< Opaque only, no punchthrough alpha support yet. Returns RGB + or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS + flag is specified. */ + KTX_TTF_BC3_RGBA = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + KTX_TTF_BC4_R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_BC5_RG = 5, + /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should + have an alpha channel (if not G will be all 255's. For tangent + space normal maps. */ + KTX_TTF_BC7_RGBA = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + KTX_TTF_PVRTC1_4_RGB = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_PVRTC1_4_RGBA = 9, + /*!< Opaque+alpha. Most useful for simple opacity maps. If the + texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB + will be used instead. Lowest quality of any supported + texture format. */ + + // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day) + KTX_TTF_ASTC_4x4_RGBA = 10, + /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for + textures without an alpha channel. The transcoder uses + RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and + [0,255]) endpoint precisions. */ + + // ATC and FXT1 formats are not supported by KTX2 as there + // are no equivalent VkFormats. + + KTX_TTF_PVRTC2_4_RGB = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + KTX_TTF_PVRTC2_4_RGBA = 19, + /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB. + Premultiplied alpha is highly recommended, otherwise the + color channel can leak into the alpha channel on transparent + blocks. */ + + KTX_TTF_ETC2_EAC_R11 = 20, + /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_EAC_RG11 = 21, + /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The + texture should have an alpha channel (if not G will be all + 255's. For tangent space normal maps. */ + + // Uncompressed (raw pixel) formats + KTX_TTF_RGBA32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + KTX_TTF_RGB565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + KTX_TTF_BGR565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + KTX_TTF_RGBA4444 = 16, + /*!< 16bpp RGBA image stored in raster (not block) order in memory, + R at bit position 12, A at bit position 0. */ + + // Values for automatic selection of RGB or RGBA depending if alpha + // present. + KTX_TTF_ETC = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + KTX_TTF_BC1_OR_3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + KTX_TTF_NOSELECTION = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + KTX_TF_ETC1 = KTX_TTF_ETC1_RGB, + //!< @deprecated. Use #KTX_TTF_ETC1_RGB. + KTX_TF_ETC2 = KTX_TTF_ETC, + //!< @deprecated. Use #KTX_TTF_ETC. + KTX_TF_BC1 = KTX_TTF_BC1_RGB, + //!< @deprecated. Use #KTX_TTF_BC1_RGB. + KTX_TF_BC3 = KTX_TTF_BC3_RGBA, + //!< @deprecated. Use #KTX_TTF_BC3_RGBA. + KTX_TF_BC4 = KTX_TTF_BC4_R, + //!< @deprecated. Use #KTX_TTF_BC4_R. + KTX_TF_BC5 = KTX_TTF_BC5_RG, + //!< @deprecated. Use #KTX_TTF_BC5_RG. + KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA + KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB + //!< @deprecated. Use #KTX_TTF_PVRTC1_4_RGB. +} ktx_transcode_fmt_e; + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +typedef enum ktx_transcode_flag_bits_e { + KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2, + /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger + power of 2 (not implemented yet, but we're going to support it). + Ignored if the slice's dimensions are already a power of 2. + */ + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4, + /*!< When decoding to an opaque texture format, if the Basis data has + alpha, decode the alpha slice instead of the color slice to the + output texture format. Has no effect if there is no alpha data. + */ + KTX_TF_HIGH_QUALITY = 32, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} ktx_transcode_flag_bits_e; +typedef ktx_uint32_t ktx_transcode_flags; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, + ktx_transcode_flags transcodeFlags); + +/* + * Returns a string corresponding to a KTX error code. + */ +KTX_API const char* KTX_APIENTRY +ktxErrorString(KTX_error_code error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ +KTX_API const char* KTX_APIENTRY +ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ +KTX_API const char* KTX_APIENTRY +ktxTranscodeFormatString(ktx_transcode_fmt_e format); + +KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl); +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl); +KTX_API void KTX_APIENTRY +ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head); +KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_AddKVPair(ktxHashList* pHead, const char* key, + unsigned int valueLen, const void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindEntry(ktxHashList* pHead, const char* key, + ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindValue(ktxHashList* pHead, const char* key, + unsigned int* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ +KTX_API ktxHashListEntry* KTX_APIENTRY +ktxHashList_Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Serialize(ktxHashList* pHead, + unsigned int* kvdLen, unsigned char** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd); + +/* + * Get the key from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetKey(ktxHashListEntry* This, + unsigned int* pKeyLen, char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetValue(ktxHashListEntry* This, + unsigned int* pValueLen, void** ppValue); + +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX2 file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); + +#ifdef __cplusplus +} +#endif + +/*========================================================================* + * For backward compatibilty with the V3 & early versions of the V4 APIs. * + *========================================================================*/ + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_transcode_fmt_e ktx_transcode_fmt_e + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_decode_flags ktx_transcode_flag_bits + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktxTexture_GetSize ktxTexture_GetDatasize + +/** +@~English +@page libktx_history Revision History + +No longer updated. Kept to preserve ancient history. For more recent history see the repo log at +https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo. + +@section v8 Version 4.0 +Added: +@li Support for KTX Version 2. +@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files. +@li Function to print info about a KTX file. + +@section v7 Version 3.0.1 +Fixed: +@li GitHub issue #159: compile failure with recent Vulkan SDKs. +@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents. +@li Incorrect BC4 blocksize. +@li Missing mapping of PVRTC formats from GL to Vulkan. +@li Incorrect block width and height calculations for sizes that are not + a multiple of the block size. +@li Incorrect KTXorientation key in test images. + +@section v6 Version 3.0 +Added: +@li new ktxTexture object based API for reading KTX files without an OpenGL context. +@li Vulkan loader. @#include to use it. + +Changed: +@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h. + Applications using OpenGL must now include these files themselves. +@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures + when the OpenGL context does not support 1D textures. + KTX_UNSUPPORTED_TEXTURE_TYPE is now returned. + +@section v5 Version 2.0.2 +Added: +@li Support for cubemap arrays. + +Changed: +@li New build system + +Fixed: +@li GitHub issue #40: failure to byte-swap key-value lengths. +@li GitHub issue #33: returning incorrect target when loading cubemaps. +@li GitHub PR #42: loading of texture arrays. +@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined. +@li GitHub issue #39: stack-buffer-overflow in toktx +@li Don't use GL_EXTENSIONS on recent OpenGL versions. + +@section v4 Version 2.0.1 +Added: +@li CMake build files. Thanks to Pavel Rotjberg for the initial version. + +Changed: +@li ktxWriteKTXF to check the validity of the type & format combinations + passed to it. + +Fixed: +@li Public Bugzilla 999: 16-bit luminance texture cannot be written. +@li compile warnings from compilers stricter than MS Visual C++. Thanks to + Pavel Rotjberg. + +@section v3 Version 2.0 +Added: +@li support for decoding ETC2 and EAC formats in the absence of a hardware + decoder. +@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA, + etc. formats to the equivalent R, RG, etc. format with an + appropriate swizzle, when loading in OpenGL Core Profile contexts. +@li ktxErrorString function to return a string corresponding to an error code. +@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3. + The latter includes an EGL on WGL wrapper that makes porting apps between + OpenGL ES and OpenGL easier on Windows. +@li more texture formats to ktxLoadTexture[FN] and toktx tests. + +Changed: +@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at + run time and load textures, or not, according to those capabilities. + +Fixed: +@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX + format. +@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write + more than 1 byte of face-LOD padding. + +Although there is only a very minor API change, the addition of ktxErrorString, +the functional changes are large enough to justify bumping the major revision +number. + +@section v2 Version 1.0.1 +Implemented ktxLoadTextureM. +Fixed the following: +@li Public Bugzilla 571: crash when null passed for pIsMipmapped. +@li Public Bugzilla 572: memory leak when unpacking ETC textures. +@li Public Bugzilla 573: potential crash when unpacking ETC textures with unused padding pixels. +@li Public Bugzilla 576: various small fixes. + +Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes. + +@section v1 Version 1.0 +Initial release. + +*/ + +#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ diff --git a/KTXLoader/libktx/ktx.xcframework/xros-arm64/libktx.a b/KTXLoader/libktx/ktx.xcframework/xros-arm64/libktx.a new file mode 100644 index 00000000..f7193105 Binary files /dev/null and b/KTXLoader/libktx/ktx.xcframework/xros-arm64/libktx.a differ diff --git a/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/Headers/KHR/khr_df.h b/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/Headers/KHR/khr_df.h new file mode 100644 index 00000000..c0d03aa7 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/Headers/KHR/khr_df.h @@ -0,0 +1,630 @@ +/* The Khronos Data Format Specification (version 1.3) */ +/* +** Copyright 2015-2020 The Khronos Group Inc. +** SPDX-License-Identifier: Apache-2.0 +*/ + +/* This header defines a structure that can describe the layout of image + formats in memory. This means that the data format is transparent to + the application, and the expectation is that this should be used when + the layout is defined external to the API. Many Khronos APIs deliberately + keep the internal layout of images opaque, to allow proprietary layouts + and optimisations. This structure is not appropriate for describing + opaque layouts. */ + +/* We stick to standard C89 constructs for simplicity and portability. */ + +#ifndef _KHR_DATA_FORMAT_H_ +#define _KHR_DATA_FORMAT_H_ + +/** @file khr_df.h + + @brief Data Format enums and macros. +*/ + +/* Accessors */ +typedef enum _khr_word_e { + KHR_DF_WORD_VENDORID = 0U, + KHR_DF_WORD_DESCRIPTORTYPE = 0U, + KHR_DF_WORD_VERSIONNUMBER = 1U, + KHR_DF_WORD_DESCRIPTORBLOCKSIZE = 1U, + KHR_DF_WORD_MODEL = 2U, + KHR_DF_WORD_PRIMARIES = 2U, + KHR_DF_WORD_TRANSFER = 2U, + KHR_DF_WORD_FLAGS = 2U, + KHR_DF_WORD_TEXELBLOCKDIMENSION0 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION1 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION2 = 3U, + KHR_DF_WORD_TEXELBLOCKDIMENSION3 = 3U, + KHR_DF_WORD_BYTESPLANE0 = 4U, + KHR_DF_WORD_BYTESPLANE1 = 4U, + KHR_DF_WORD_BYTESPLANE2 = 4U, + KHR_DF_WORD_BYTESPLANE3 = 4U, + KHR_DF_WORD_BYTESPLANE4 = 5U, + KHR_DF_WORD_BYTESPLANE5 = 5U, + KHR_DF_WORD_BYTESPLANE6 = 5U, + KHR_DF_WORD_BYTESPLANE7 = 5U, + KHR_DF_WORD_SAMPLESTART = 6U, + KHR_DF_WORD_SAMPLEWORDS = 4U +} khr_df_word_e; + +typedef enum _khr_df_shift_e { + KHR_DF_SHIFT_VENDORID = 0U, + KHR_DF_SHIFT_DESCRIPTORTYPE = 17U, + KHR_DF_SHIFT_VERSIONNUMBER = 0U, + KHR_DF_SHIFT_DESCRIPTORBLOCKSIZE = 16U, + KHR_DF_SHIFT_MODEL = 0U, + KHR_DF_SHIFT_PRIMARIES = 8U, + KHR_DF_SHIFT_TRANSFER = 16U, + KHR_DF_SHIFT_FLAGS = 24U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION0 = 0U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION1 = 8U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION2 = 16U, + KHR_DF_SHIFT_TEXELBLOCKDIMENSION3 = 24U, + KHR_DF_SHIFT_BYTESPLANE0 = 0U, + KHR_DF_SHIFT_BYTESPLANE1 = 8U, + KHR_DF_SHIFT_BYTESPLANE2 = 16U, + KHR_DF_SHIFT_BYTESPLANE3 = 24U, + KHR_DF_SHIFT_BYTESPLANE4 = 0U, + KHR_DF_SHIFT_BYTESPLANE5 = 8U, + KHR_DF_SHIFT_BYTESPLANE6 = 16U, + KHR_DF_SHIFT_BYTESPLANE7 = 24U +} khr_df_shift_e; + +typedef enum _khr_df_mask_e { + KHR_DF_MASK_VENDORID = 0x1FFFFU, + KHR_DF_MASK_DESCRIPTORTYPE = 0x7FFFU, + KHR_DF_MASK_VERSIONNUMBER = 0xFFFFU, + KHR_DF_MASK_DESCRIPTORBLOCKSIZE = 0xFFFFU, + KHR_DF_MASK_MODEL = 0xFFU, + KHR_DF_MASK_PRIMARIES = 0xFFU, + KHR_DF_MASK_TRANSFER = 0xFFU, + KHR_DF_MASK_FLAGS = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION0 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION1 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION2 = 0xFFU, + KHR_DF_MASK_TEXELBLOCKDIMENSION3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE0 = 0xFFU, + KHR_DF_MASK_BYTESPLANE1 = 0xFFU, + KHR_DF_MASK_BYTESPLANE2 = 0xFFU, + KHR_DF_MASK_BYTESPLANE3 = 0xFFU, + KHR_DF_MASK_BYTESPLANE4 = 0xFFU, + KHR_DF_MASK_BYTESPLANE5 = 0xFFU, + KHR_DF_MASK_BYTESPLANE6 = 0xFFU, + KHR_DF_MASK_BYTESPLANE7 = 0xFFU +} khr_df_mask_e; + +/* Helper macro: + Extract field X from basic descriptor block BDB */ +#define KHR_DFDVAL(BDB, X) \ + (((BDB)[KHR_DF_WORD_ ## X] >> (KHR_DF_SHIFT_ ## X)) \ + & (KHR_DF_MASK_ ## X)) + +/* Helper macro: + Set field X of basic descriptor block BDB */ +#define KHR_DFDSETVAL(BDB, X, val) \ + ((BDB)[KHR_DF_WORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_ ## X] & \ + ~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \ + (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X))) + +/* Offsets relative to the start of a sample */ +typedef enum _khr_df_sampleword_e { + KHR_DF_SAMPLEWORD_BITOFFSET = 0U, + KHR_DF_SAMPLEWORD_BITLENGTH = 0U, + KHR_DF_SAMPLEWORD_CHANNELID = 0U, + KHR_DF_SAMPLEWORD_QUALIFIERS = 0U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION0 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION1 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION2 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION3 = 1U, + KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL = 1U, + KHR_DF_SAMPLEWORD_SAMPLELOWER = 2U, + KHR_DF_SAMPLEWORD_SAMPLEUPPER = 3U +} khr_df_sampleword_e; + +typedef enum _khr_df_sampleshift_e { + KHR_DF_SAMPLESHIFT_BITOFFSET = 0U, + KHR_DF_SAMPLESHIFT_BITLENGTH = 16U, + KHR_DF_SAMPLESHIFT_CHANNELID = 24U, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLESHIFT_QUALIFIERS = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION0 = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION1 = 8U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION2 = 16U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION3 = 24U, + KHR_DF_SAMPLESHIFT_SAMPLEPOSITION_ALL = 0U, + KHR_DF_SAMPLESHIFT_SAMPLELOWER = 0U, + KHR_DF_SAMPLESHIFT_SAMPLEUPPER = 0U +} khr_df_sampleshift_e; + +typedef enum _khr_df_samplemask_e { + KHR_DF_SAMPLEMASK_BITOFFSET = 0xFFFFU, + KHR_DF_SAMPLEMASK_BITLENGTH = 0xFF, + KHR_DF_SAMPLEMASK_CHANNELID = 0xF, + /* N.B. Qualifiers are defined as an offset into a byte */ + KHR_DF_SAMPLEMASK_QUALIFIERS = 0xF0, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION0 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION1 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION2 = 0xFF, + KHR_DF_SAMPLEMASK_SAMPLEPOSITION3 = 0xFF, + /* ISO C restricts enum values to range of int hence the + cast. We do it verbosely instead of using -1 to ensure + it is a 32-bit value even if int is 64 bits. */ + KHR_DF_SAMPLEMASK_SAMPLEPOSITION_ALL = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLELOWER = (int) 0xFFFFFFFFU, + KHR_DF_SAMPLEMASK_SAMPLEUPPER = (int) 0xFFFFFFFFU +} khr_df_samplemask_e; + +/* Helper macro: + Extract field X of sample S from basic descriptor block BDB */ +#define KHR_DFDSVAL(BDB, S, X) \ + (((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] >> (KHR_DF_SAMPLESHIFT_ ## X)) \ + & (KHR_DF_SAMPLEMASK_ ## X)) + +/* Helper macro: + Set field X of sample S of basic descriptor block BDB */ +#define KHR_DFDSETSVAL(BDB, S, X, val) \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] = \ + ((BDB)[KHR_DF_WORD_SAMPLESTART + \ + ((S) * KHR_DF_WORD_SAMPLEWORDS) + \ + KHR_DF_SAMPLEWORD_ ## X] & \ + ~((uint32_t)(KHR_DF_SAMPLEMASK_ ## X) << (KHR_DF_SAMPLESHIFT_ ## X))) | \ + (((val) & (uint32_t)(KHR_DF_SAMPLEMASK_ ## X)) << (KHR_DF_SAMPLESHIFT_ ## X))) + +/* Helper macro: + Number of samples in basic descriptor block BDB */ +#define KHR_DFDSAMPLECOUNT(BDB) \ + (((KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) >> 2) - \ + KHR_DF_WORD_SAMPLESTART) \ + / KHR_DF_WORD_SAMPLEWORDS) + +/* Helper macro: + Size in words of basic descriptor block for S samples */ +#define KHR_DFDSIZEWORDS(S) \ + (KHR_DF_WORD_SAMPLESTART + \ + (S) * KHR_DF_WORD_SAMPLEWORDS) + +/* Vendor ids */ +typedef enum _khr_df_vendorid_e { + /* Standard Khronos descriptor */ + KHR_DF_VENDORID_KHRONOS = 0U, + KHR_DF_VENDORID_MAX = 0x1FFFFU +} khr_df_vendorid_e; + +/* Descriptor types */ +typedef enum _khr_df_khr_descriptortype_e { + /* Default Khronos basic descriptor block */ + KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0U, + /* Extension descriptor block for additional planes */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_PLANES = 0x6001U, + /* Extension descriptor block for additional dimensions */ + KHR_DF_KHR_DESCRIPTORTYPE_ADDITIONAL_DIMENSIONS = 0x6002U, + /* Bit indicates modifying requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_WRITE_BIT = 0x2000U, + /* Bit indicates processing requires understanding this extension */ + KHR_DF_KHR_DESCRIPTORTYPE_NEEDED_FOR_DECODE_BIT = 0x4000U, + KHR_DF_KHR_DESCRIPTORTYPE_MAX = 0x7FFFU +} khr_df_khr_descriptortype_e; + +/* Descriptor block version */ +typedef enum _khr_df_versionnumber_e { + /* Standard Khronos descriptor */ + KHR_DF_VERSIONNUMBER_1_0 = 0U, /* Version 1.0 of the specification */ + KHR_DF_VERSIONNUMBER_1_1 = 0U, /* Version 1.1 did not bump the version number */ + KHR_DF_VERSIONNUMBER_1_2 = 1U, /* Version 1.2 increased the version number */ + KHR_DF_VERSIONNUMBER_1_3 = 2U, /* Version 1.3 increased the version number */ + KHR_DF_VERSIONNUMBER_LATEST = KHR_DF_VERSIONNUMBER_1_3, + KHR_DF_VERSIONNUMBER_MAX = 0xFFFFU +} khr_df_versionnumber_e; + +/** @~English + @brief Model in which the color coordinate space is defined. + There is no requirement that a color format use all the + channel types that are defined in the color model. */ +typedef enum _khr_df_model_e { + /** No interpretation of color channels defined */ + KHR_DF_MODEL_UNSPECIFIED = 0U, + /** Color primaries (red, green, blue) + alpha, depth and stencil */ + KHR_DF_MODEL_RGBSDA = 1U, + /** Color differences (Y', Cb, Cr) + alpha, depth and stencil */ + KHR_DF_MODEL_YUVSDA = 2U, + /** Color differences (Y', I, Q) + alpha, depth and stencil */ + KHR_DF_MODEL_YIQSDA = 3U, + /** Perceptual color (CIE L*a*b*) + alpha, depth and stencil */ + KHR_DF_MODEL_LABSDA = 4U, + /** Subtractive colors (cyan, magenta, yellow, black) + alpha */ + KHR_DF_MODEL_CMYKA = 5U, + /** Non-color coordinate data (X, Y, Z, W) */ + KHR_DF_MODEL_XYZW = 6U, + /** Hue, saturation, value, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSVA_ANG = 7U, + /** Hue, saturation, lightness, hue angle on color circle, plus alpha */ + KHR_DF_MODEL_HSLA_ANG = 8U, + /** Hue, saturation, value, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSVA_HEX = 9U, + /** Hue, saturation, lightness, hue on color hexagon, plus alpha */ + KHR_DF_MODEL_HSLA_HEX = 10U, + /** Lightweight approximate color difference (luma, orange, green) */ + KHR_DF_MODEL_YCGCOA = 11U, + /** ITU BT.2020 constant luminance YcCbcCrc */ + KHR_DF_MODEL_YCCBCCRC = 12U, + /** ITU BT.2100 constant intensity ICtCp */ + KHR_DF_MODEL_ICTCP = 13U, + /** CIE 1931 XYZ color coordinates (X, Y, Z) */ + KHR_DF_MODEL_CIEXYZ = 14U, + /** CIE 1931 xyY color coordinates (X, Y, Y) */ + KHR_DF_MODEL_CIEXYY = 15U, + + /* Compressed formats start at 128. */ + /* These compressed formats should generally have a single sample, + sited at the 0,0 position of the texel block. Where multiple + channels are used to distinguish formats, these should be cosited. */ + /* Direct3D (and S3) compressed formats */ + /* Note that premultiplied status is recorded separately */ + /** DXT1 "channels" are RGB (0), Alpha (1) + DXT1/BC1 with one channel is opaque + DXT1/BC1 with a cosited alpha sample is transparent */ + KHR_DF_MODEL_DXT1A = 128U, + KHR_DF_MODEL_BC1A = 128U, + /** DXT2/DXT3/BC2, with explicit 4-bit alpha */ + KHR_DF_MODEL_DXT2 = 129U, + KHR_DF_MODEL_DXT3 = 129U, + KHR_DF_MODEL_BC2 = 129U, + /** DXT4/DXT5/BC3, with interpolated alpha */ + KHR_DF_MODEL_DXT4 = 130U, + KHR_DF_MODEL_DXT5 = 130U, + KHR_DF_MODEL_BC3 = 130U, + /** BC4 - single channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC4 = 131U, + /** BC5 - two channel interpolated 8-bit data + (The UNORM/SNORM variation is recorded in the channel data) */ + KHR_DF_MODEL_BC5 = 132U, + /** BC6H - DX11 format for 16-bit float channels */ + KHR_DF_MODEL_BC6H = 133U, + /** BC7 - DX11 format */ + KHR_DF_MODEL_BC7 = 134U, + /* Gap left for future desktop expansion */ + + /* Mobile compressed formats follow */ + /** A format of ETC1 indicates that the format shall be decodable + by an ETC1-compliant decoder and not rely on ETC2 features */ + KHR_DF_MODEL_ETC1 = 160U, + /** A format of ETC2 is permitted to use ETC2 encodings on top of + the baseline ETC1 specification. + The ETC2 format has channels "red", "green", "RGB" and "alpha", + which should be cosited samples. + Punch-through alpha can be distinguished from full alpha by + the plane size in bytes required for the texel block */ + KHR_DF_MODEL_ETC2 = 161U, + /** Adaptive Scalable Texture Compression */ + /** ASTC HDR vs LDR is determined by the float flag in the channel */ + /** ASTC block size can be distinguished by texel block size */ + KHR_DF_MODEL_ASTC = 162U, + /** ETC1S is a simplified subset of ETC1 */ + KHR_DF_MODEL_ETC1S = 163U, + /** PowerVR Texture Compression v1 */ + KHR_DF_MODEL_PVRTC = 164U, + /** PowerVR Texture Compression v2 */ + KHR_DF_MODEL_PVRTC2 = 165U, + /** UASTC is a transcodable subset of ASTC + with additions to support the transcoding. */ + KHR_DF_MODEL_UASTC = 166U, + /* Proprietary formats (ATITC, etc.) should follow */ + KHR_DF_MODEL_MAX = 0xFFU +} khr_df_model_e; + +/* Definition of channel names for each color model */ +typedef enum _khr_df_model_channels_e { + /* Unspecified format with nominal channel numbering */ + KHR_DF_CHANNEL_UNSPECIFIED_0 = 0U, + KHR_DF_CHANNEL_UNSPECIFIED_1 = 1U, + KHR_DF_CHANNEL_UNSPECIFIED_2 = 2U, + KHR_DF_CHANNEL_UNSPECIFIED_3 = 3U, + KHR_DF_CHANNEL_UNSPECIFIED_4 = 4U, + KHR_DF_CHANNEL_UNSPECIFIED_5 = 5U, + KHR_DF_CHANNEL_UNSPECIFIED_6 = 6U, + KHR_DF_CHANNEL_UNSPECIFIED_7 = 7U, + KHR_DF_CHANNEL_UNSPECIFIED_8 = 8U, + KHR_DF_CHANNEL_UNSPECIFIED_9 = 9U, + KHR_DF_CHANNEL_UNSPECIFIED_10 = 10U, + KHR_DF_CHANNEL_UNSPECIFIED_11 = 11U, + KHR_DF_CHANNEL_UNSPECIFIED_12 = 12U, + KHR_DF_CHANNEL_UNSPECIFIED_13 = 13U, + KHR_DF_CHANNEL_UNSPECIFIED_14 = 14U, + KHR_DF_CHANNEL_UNSPECIFIED_15 = 15U, + /* MODEL_RGBSDA - red, green, blue, stencil, depth, alpha */ + KHR_DF_CHANNEL_RGBSDA_RED = 0U, + KHR_DF_CHANNEL_RGBSDA_R = 0U, + KHR_DF_CHANNEL_RGBSDA_GREEN = 1U, + KHR_DF_CHANNEL_RGBSDA_G = 1U, + KHR_DF_CHANNEL_RGBSDA_BLUE = 2U, + KHR_DF_CHANNEL_RGBSDA_B = 2U, + KHR_DF_CHANNEL_RGBSDA_STENCIL = 13U, + KHR_DF_CHANNEL_RGBSDA_S = 13U, + KHR_DF_CHANNEL_RGBSDA_DEPTH = 14U, + KHR_DF_CHANNEL_RGBSDA_D = 14U, + KHR_DF_CHANNEL_RGBSDA_ALPHA = 15U, + KHR_DF_CHANNEL_RGBSDA_A = 15U, + /* MODEL_YUVSDA - luma, Cb, Cr, stencil, depth, alpha */ + KHR_DF_CHANNEL_YUVSDA_Y = 0U, + KHR_DF_CHANNEL_YUVSDA_CB = 1U, + KHR_DF_CHANNEL_YUVSDA_U = 1U, + KHR_DF_CHANNEL_YUVSDA_CR = 2U, + KHR_DF_CHANNEL_YUVSDA_V = 2U, + KHR_DF_CHANNEL_YUVSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YUVSDA_S = 13U, + KHR_DF_CHANNEL_YUVSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YUVSDA_D = 14U, + KHR_DF_CHANNEL_YUVSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YUVSDA_A = 15U, + /* MODEL_YIQSDA - luma, in-phase, quadrature, stencil, depth, alpha */ + KHR_DF_CHANNEL_YIQSDA_Y = 0U, + KHR_DF_CHANNEL_YIQSDA_I = 1U, + KHR_DF_CHANNEL_YIQSDA_Q = 2U, + KHR_DF_CHANNEL_YIQSDA_STENCIL = 13U, + KHR_DF_CHANNEL_YIQSDA_S = 13U, + KHR_DF_CHANNEL_YIQSDA_DEPTH = 14U, + KHR_DF_CHANNEL_YIQSDA_D = 14U, + KHR_DF_CHANNEL_YIQSDA_ALPHA = 15U, + KHR_DF_CHANNEL_YIQSDA_A = 15U, + /* MODEL_LABSDA - CIELAB/L*a*b* luma, red-green, blue-yellow, stencil, depth, alpha */ + KHR_DF_CHANNEL_LABSDA_L = 0U, + KHR_DF_CHANNEL_LABSDA_A = 1U, + KHR_DF_CHANNEL_LABSDA_B = 2U, + KHR_DF_CHANNEL_LABSDA_STENCIL = 13U, + KHR_DF_CHANNEL_LABSDA_S = 13U, + KHR_DF_CHANNEL_LABSDA_DEPTH = 14U, + KHR_DF_CHANNEL_LABSDA_D = 14U, + KHR_DF_CHANNEL_LABSDA_ALPHA = 15U, + /* NOTE: KHR_DF_CHANNEL_LABSDA_A is not a synonym for alpha! */ + /* MODEL_CMYKA - cyan, magenta, yellow, key/blacK, alpha */ + KHR_DF_CHANNEL_CMYKSDA_CYAN = 0U, + KHR_DF_CHANNEL_CMYKSDA_C = 0U, + KHR_DF_CHANNEL_CMYKSDA_MAGENTA = 1U, + KHR_DF_CHANNEL_CMYKSDA_M = 1U, + KHR_DF_CHANNEL_CMYKSDA_YELLOW = 2U, + KHR_DF_CHANNEL_CMYKSDA_Y = 2U, + KHR_DF_CHANNEL_CMYKSDA_KEY = 3U, + KHR_DF_CHANNEL_CMYKSDA_BLACK = 3U, + KHR_DF_CHANNEL_CMYKSDA_K = 3U, + KHR_DF_CHANNEL_CMYKSDA_ALPHA = 15U, + KHR_DF_CHANNEL_CMYKSDA_A = 15U, + /* MODEL_XYZW - coordinates x, y, z, w */ + KHR_DF_CHANNEL_XYZW_X = 0U, + KHR_DF_CHANNEL_XYZW_Y = 1U, + KHR_DF_CHANNEL_XYZW_Z = 2U, + KHR_DF_CHANNEL_XYZW_W = 3U, + /* MODEL_HSVA_ANG - value (luma), saturation, hue, alpha, angular projection, conical space */ + KHR_DF_CHANNEL_HSVA_ANG_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_ANG_V = 0U, + KHR_DF_CHANNEL_HSVA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_ANG_S = 1U, + KHR_DF_CHANNEL_HSVA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSVA_ANG_H = 2U, + KHR_DF_CHANNEL_HSVA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_ANG_A = 15U, + /* MODEL_HSLA_ANG - lightness (luma), saturation, hue, alpha, angular projection, double conical space */ + KHR_DF_CHANNEL_HSLA_ANG_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_ANG_L = 0U, + KHR_DF_CHANNEL_HSLA_ANG_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_ANG_S = 1U, + KHR_DF_CHANNEL_HSLA_ANG_HUE = 2U, + KHR_DF_CHANNEL_HSLA_ANG_H = 2U, + KHR_DF_CHANNEL_HSLA_ANG_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_ANG_A = 15U, + /* MODEL_HSVA_HEX - value (luma), saturation, hue, alpha, hexagonal projection, conical space */ + KHR_DF_CHANNEL_HSVA_HEX_VALUE = 0U, + KHR_DF_CHANNEL_HSVA_HEX_V = 0U, + KHR_DF_CHANNEL_HSVA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSVA_HEX_S = 1U, + KHR_DF_CHANNEL_HSVA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSVA_HEX_H = 2U, + KHR_DF_CHANNEL_HSVA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSVA_HEX_A = 15U, + /* MODEL_HSLA_HEX - lightness (luma), saturation, hue, alpha, hexagonal projection, double conical space */ + KHR_DF_CHANNEL_HSLA_HEX_LIGHTNESS = 0U, + KHR_DF_CHANNEL_HSLA_HEX_L = 0U, + KHR_DF_CHANNEL_HSLA_HEX_SATURATION = 1U, + KHR_DF_CHANNEL_HSLA_HEX_S = 1U, + KHR_DF_CHANNEL_HSLA_HEX_HUE = 2U, + KHR_DF_CHANNEL_HSLA_HEX_H = 2U, + KHR_DF_CHANNEL_HSLA_HEX_ALPHA = 15U, + KHR_DF_CHANNEL_HSLA_HEX_A = 15U, + /* MODEL_YCGCOA - luma, green delta, orange delta, alpha */ + KHR_DF_CHANNEL_YCGCOA_Y = 0U, + KHR_DF_CHANNEL_YCGCOA_CG = 1U, + KHR_DF_CHANNEL_YCGCOA_CO = 2U, + KHR_DF_CHANNEL_YCGCOA_ALPHA = 15U, + KHR_DF_CHANNEL_YCGCOA_A = 15U, + /* MODEL_CIEXYZ - CIE 1931 X, Y, Z */ + KHR_DF_CHANNEL_CIEXYZ_X = 0U, + KHR_DF_CHANNEL_CIEXYZ_Y = 1U, + KHR_DF_CHANNEL_CIEXYZ_Z = 2U, + /* MODEL_CIEXYY - CIE 1931 x, y, Y */ + KHR_DF_CHANNEL_CIEXYY_X = 0U, + KHR_DF_CHANNEL_CIEXYY_YCHROMA = 1U, + KHR_DF_CHANNEL_CIEXYY_YLUMA = 2U, + + /* Compressed formats */ + /* MODEL_DXT1A/MODEL_BC1A */ + KHR_DF_CHANNEL_DXT1A_COLOR = 0U, + KHR_DF_CHANNEL_BC1A_COLOR = 0U, + KHR_DF_CHANNEL_DXT1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_DXT1A_ALPHA = 1U, + KHR_DF_CHANNEL_BC1A_ALPHAPRESENT = 1U, + KHR_DF_CHANNEL_BC1A_ALPHA = 1U, + /* MODEL_DXT2/3/MODEL_BC2 */ + KHR_DF_CHANNEL_DXT2_COLOR = 0U, + KHR_DF_CHANNEL_DXT3_COLOR = 0U, + KHR_DF_CHANNEL_BC2_COLOR = 0U, + KHR_DF_CHANNEL_DXT2_ALPHA = 15U, + KHR_DF_CHANNEL_DXT3_ALPHA = 15U, + KHR_DF_CHANNEL_BC2_ALPHA = 15U, + /* MODEL_DXT4/5/MODEL_BC3 */ + KHR_DF_CHANNEL_DXT4_COLOR = 0U, + KHR_DF_CHANNEL_DXT5_COLOR = 0U, + KHR_DF_CHANNEL_BC3_COLOR = 0U, + KHR_DF_CHANNEL_DXT4_ALPHA = 15U, + KHR_DF_CHANNEL_DXT5_ALPHA = 15U, + KHR_DF_CHANNEL_BC3_ALPHA = 15U, + /* MODEL_BC4 */ + KHR_DF_CHANNEL_BC4_DATA = 0U, + /* MODEL_BC5 */ + KHR_DF_CHANNEL_BC5_RED = 0U, + KHR_DF_CHANNEL_BC5_R = 0U, + KHR_DF_CHANNEL_BC5_GREEN = 1U, + KHR_DF_CHANNEL_BC5_G = 1U, + /* MODEL_BC6H */ + KHR_DF_CHANNEL_BC6H_COLOR = 0U, + KHR_DF_CHANNEL_BC6H_DATA = 0U, + /* MODEL_BC7 */ + KHR_DF_CHANNEL_BC7_DATA = 0U, + KHR_DF_CHANNEL_BC7_COLOR = 0U, + /* MODEL_ETC1 */ + KHR_DF_CHANNEL_ETC1_DATA = 0U, + KHR_DF_CHANNEL_ETC1_COLOR = 0U, + /* MODEL_ETC2 */ + KHR_DF_CHANNEL_ETC2_RED = 0U, + KHR_DF_CHANNEL_ETC2_R = 0U, + KHR_DF_CHANNEL_ETC2_GREEN = 1U, + KHR_DF_CHANNEL_ETC2_G = 1U, + KHR_DF_CHANNEL_ETC2_COLOR = 2U, + KHR_DF_CHANNEL_ETC2_ALPHA = 15U, + KHR_DF_CHANNEL_ETC2_A = 15U, + /* MODEL_ASTC */ + KHR_DF_CHANNEL_ASTC_DATA = 0U, + /* MODEL_ETC1S */ + KHR_DF_CHANNEL_ETC1S_RGB = 0U, + KHR_DF_CHANNEL_ETC1S_RRR = 3U, + KHR_DF_CHANNEL_ETC1S_GGG = 4U, + KHR_DF_CHANNEL_ETC1S_AAA = 15U, + /* MODEL_PVRTC */ + KHR_DF_CHANNEL_PVRTC_DATA = 0U, + KHR_DF_CHANNEL_PVRTC_COLOR = 0U, + /* MODEL_PVRTC2 */ + KHR_DF_CHANNEL_PVRTC2_DATA = 0U, + KHR_DF_CHANNEL_PVRTC2_COLOR = 0U, + /* MODEL UASTC */ + KHR_DF_CHANNEL_UASTC_DATA = 0U, + KHR_DF_CHANNEL_UASTC_RGB = 0U, + KHR_DF_CHANNEL_UASTC_RGBA = 3U, + KHR_DF_CHANNEL_UASTC_RRR = 4U, + KHR_DF_CHANNEL_UASTC_RRRG = 5U, + KHR_DF_CHANNEL_UASTC_RG = 6U, + + /* Common channel names shared by multiple formats */ + KHR_DF_CHANNEL_COMMON_LUMA = 0U, + KHR_DF_CHANNEL_COMMON_L = 0U, + KHR_DF_CHANNEL_COMMON_STENCIL = 13U, + KHR_DF_CHANNEL_COMMON_S = 13U, + KHR_DF_CHANNEL_COMMON_DEPTH = 14U, + KHR_DF_CHANNEL_COMMON_D = 14U, + KHR_DF_CHANNEL_COMMON_ALPHA = 15U, + KHR_DF_CHANNEL_COMMON_A = 15U +} khr_df_model_channels_e; + +/** @~English + @brief Definition of the primary colors in color coordinates. + This is implicitly responsible for defining the conversion + between RGB an YUV color spaces. + LAB and related absolute color models should use + KHR_DF_PRIMARIES_CIEXYZ. */ +typedef enum _khr_df_primaries_e { + /** No color primaries defined */ + KHR_DF_PRIMARIES_UNSPECIFIED = 0U, + /** Color primaries of ITU-R BT.709 and sRGB */ + KHR_DF_PRIMARIES_BT709 = 1U, + /** Synonym for KHR_DF_PRIMARIES_BT709 */ + KHR_DF_PRIMARIES_SRGB = 1U, + /** Color primaries of ITU-R BT.601 (625-line EBU variant) */ + KHR_DF_PRIMARIES_BT601_EBU = 2U, + /** Color primaries of ITU-R BT.601 (525-line SMPTE C variant) */ + KHR_DF_PRIMARIES_BT601_SMPTE = 3U, + /** Color primaries of ITU-R BT.2020 */ + KHR_DF_PRIMARIES_BT2020 = 4U, + /** CIE theoretical color coordinate space */ + KHR_DF_PRIMARIES_CIEXYZ = 5U, + /** Academy Color Encoding System primaries */ + KHR_DF_PRIMARIES_ACES = 6U, + /** Color primaries of ACEScc */ + KHR_DF_PRIMARIES_ACESCC = 7U, + /** Legacy NTSC 1953 primaries */ + KHR_DF_PRIMARIES_NTSC1953 = 8U, + /** Legacy PAL 525-line primaries */ + KHR_DF_PRIMARIES_PAL525 = 9U, + /** Color primaries of Display P3 */ + KHR_DF_PRIMARIES_DISPLAYP3 = 10U, + /** Color primaries of Adobe RGB (1998) */ + KHR_DF_PRIMARIES_ADOBERGB = 11U, + KHR_DF_PRIMARIES_MAX = 0xFFU +} khr_df_primaries_e; + +/** @~English + @brief Definition of the optical to digital transfer function + ("gamma correction"). Most transfer functions are not a pure + power function and also include a linear element. + LAB and related absolute color representations should use + KHR_DF_TRANSFER_UNSPECIFIED. */ +typedef enum _khr_df_transfer_e { + /** No transfer function defined */ + KHR_DF_TRANSFER_UNSPECIFIED = 0U, + /** Linear transfer function (value proportional to intensity) */ + KHR_DF_TRANSFER_LINEAR = 1U, + /** Perceptually-linear transfer function of sRGH (~2.4) */ + KHR_DF_TRANSFER_SRGB = 2U, + /** Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45) */ + KHR_DF_TRANSFER_ITU = 3U, + /** SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) */ + KHR_DF_TRANSFER_SMTPE170M = 3U, + /** Perceptually-linear gamma function of original NTSC (simple 2.2 gamma) */ + KHR_DF_TRANSFER_NTSC = 4U, + /** Sony S-log used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG = 5U, + /** Sony S-log 2 used by Sony video cameras */ + KHR_DF_TRANSFER_SLOG2 = 6U, + /** ITU BT.1886 EOTF */ + KHR_DF_TRANSFER_BT1886 = 7U, + /** ITU BT.2100 HLG OETF */ + KHR_DF_TRANSFER_HLG_OETF = 8U, + /** ITU BT.2100 HLG EOTF */ + KHR_DF_TRANSFER_HLG_EOTF = 9U, + /** ITU BT.2100 PQ EOTF */ + KHR_DF_TRANSFER_PQ_EOTF = 10U, + /** ITU BT.2100 PQ OETF */ + KHR_DF_TRANSFER_PQ_OETF = 11U, + /** DCI P3 transfer function */ + KHR_DF_TRANSFER_DCIP3 = 12U, + /** Legacy PAL OETF */ + KHR_DF_TRANSFER_PAL_OETF = 13U, + /** Legacy PAL 625-line EOTF */ + KHR_DF_TRANSFER_PAL625_EOTF = 14U, + /** Legacy ST240 transfer function */ + KHR_DF_TRANSFER_ST240 = 15U, + /** ACEScc transfer function */ + KHR_DF_TRANSFER_ACESCC = 16U, + /** ACEScct transfer function */ + KHR_DF_TRANSFER_ACESCCT = 17U, + /** Adobe RGB (1998) transfer function */ + KHR_DF_TRANSFER_ADOBERGB = 18U, + KHR_DF_TRANSFER_MAX = 0xFFU +} khr_df_transfer_e; + +typedef enum _khr_df_flags_e { + KHR_DF_FLAG_ALPHA_STRAIGHT = 0U, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1U +} khr_df_flags_e; + +typedef enum _khr_df_sample_datatype_qualifiers_e { + KHR_DF_SAMPLE_DATATYPE_LINEAR = 1U << 4U, + KHR_DF_SAMPLE_DATATYPE_EXPONENT = 1U << 5U, + KHR_DF_SAMPLE_DATATYPE_SIGNED = 1U << 6U, + KHR_DF_SAMPLE_DATATYPE_FLOAT = 1U << 7U +} khr_df_sample_datatype_qualifiers_e; + +#endif diff --git a/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/Headers/ktx.h b/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/Headers/ktx.h new file mode 100644 index 00000000..fd321c30 --- /dev/null +++ b/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/Headers/ktx.h @@ -0,0 +1,1835 @@ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + +#ifndef KTX_H_A55A6F00956F42F3A137C11929827FE1 +#define KTX_H_A55A6F00956F42F3A137C11929827FE1 + +/* + * Copyright 2010-2018 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + * + * See the accompanying LICENSE.md for licensing details for all files in + * the KTX library and KTX loader tests. + */ + +/** + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX API. + * + * @author Mark Callow, Edgewise Consulting and while at HI Corporation + * @author Based on original work by Georg Kolling, Imagination Technology + * + * @snippet{doc} version.h API version + */ + +#include +#include +#include + +#include + +/* + * Don't use khrplatform.h in order not to break apps existing + * before these definitions were needed. + */ +#if defined(KHRONOS_STATIC) + #define KTX_API +#elif defined(_WIN32) || defined(__CYGWIN__) + #if !defined(KTX_API) + #if __GNUC__ + #define KTX_API __attribute__ ((dllimport)) + #elif _MSC_VER + #define KTX_API __declspec(dllimport) + #else + #error "Your compiler's equivalent of dllimport is unknown" + #endif + #endif +#elif defined(__ANDROID__) + #define KTX_API __attribute__((visibility("default"))) +#else + #define KTX_API +#endif + +#if defined(_WIN32) && !defined(KHRONOS_STATIC) + #if !defined(KTX_APIENTRY) + #define KTX_APIENTRY __stdcall + #endif +#else + #define KTX_APIENTRY +#endif + +/* To avoid including define our own types. */ +typedef unsigned char ktx_uint8_t; +typedef bool ktx_bool_t; +#ifdef _MSC_VER +typedef unsigned __int16 ktx_uint16_t; +typedef signed __int16 ktx_int16_t; +typedef unsigned __int32 ktx_uint32_t; +typedef signed __int32 ktx_int32_t; +typedef size_t ktx_size_t; +typedef unsigned __int64 ktx_uint64_t; +typedef signed __int64 ktx_int64_t; +#else +#include +typedef uint16_t ktx_uint16_t; +typedef int16_t ktx_int16_t; +typedef uint32_t ktx_uint32_t; +typedef int32_t ktx_int32_t; +typedef size_t ktx_size_t; +typedef uint64_t ktx_uint64_t; +typedef int64_t ktx_int64_t; +#endif + +/* This will cause compilation to fail if size of uint32 != 4. */ +typedef unsigned char ktx_uint32_t_SIZE_ASSERT[sizeof(ktx_uint32_t) == 4]; + +/* + * This #if allows libktx to be compiled with strict c99. It avoids + * compiler warnings or even errors when a gl.h is already included. + * "Redefinition of (type) is a c11 feature". Obviously this doesn't help if + * gl.h comes after. However nobody has complained about the unguarded typedefs + * since they were introduced so this is unlikely to be a problem in practice. + * Presumably everybody is using platform default compilers not c99 or else + * they are using C++. + */ +#if !defined(GL_NO_ERROR) + /* + * To avoid having to including gl.h ... + */ + typedef unsigned char GLboolean; + typedef unsigned int GLenum; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLuint; + typedef unsigned char GLubyte; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_ANIMDATA_KEY "KTXanimData" +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +#define KTX_ORIENTATION_KEY "KTXorientation" +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +#define KTX_SWIZZLE_KEY "KTXswizzle" +/** + * @~English + * @brief Key string for standard writer metadata. + */ +#define KTX_WRITER_KEY "KTXwriter" +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +#define KTX_WRITER_SCPARAMS_KEY "KTXwriterScParams" +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +#define KTX_ORIENTATION1_FMT "S=%c" +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +#define KTX_ORIENTATION2_FMT "S=%c,T=%c" +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +#define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c" +/** + * @~English + * @brief Required unpack alignment + */ +#define KTX_GL_UNPACK_ALIGNMENT 4 + +#define KTX_TRUE true +#define KTX_FALSE false + +/** + * @~English + * @brief Error codes returned by library functions. + */ +typedef enum ktx_error_code_e { + KTX_SUCCESS = 0, /*!< Operation was successful. */ + KTX_FILE_DATA_ERROR, /*!< The data in the file is inconsistent with the spec. */ + KTX_FILE_ISPIPE, /*!< The file is a pipe or named pipe. */ + KTX_FILE_OPEN_FAILED, /*!< The target file could not be opened. */ + KTX_FILE_OVERFLOW, /*!< The operation would exceed the max file size. */ + KTX_FILE_READ_ERROR, /*!< An error occurred while reading from the file. */ + KTX_FILE_SEEK_ERROR, /*!< An error occurred while seeking in the file. */ + KTX_FILE_UNEXPECTED_EOF, /*!< File does not have enough data to satisfy request. */ + KTX_FILE_WRITE_ERROR, /*!< An error occurred while writing to the file. */ + KTX_GL_ERROR, /*!< GL operations resulted in an error. */ + KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ + KTX_INVALID_VALUE, /*!< A parameter value was not valid */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ + KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ + KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ + KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ + KTX_UNSUPPORTED_TEXTURE_TYPE, /*!< The KTX file specifies an unsupported texture type. */ + KTX_UNSUPPORTED_FEATURE, /*!< Feature not included in in-use library or not yet implemented. */ + KTX_LIBRARY_NOT_LINKED, /*!< Library dependency (OpenGL or Vulkan) not linked into application. */ + KTX_DECOMPRESS_LENGTH_ERROR, /*!< Decompressed byte count does not match expected byte size */ + KTX_DECOMPRESS_CHECKSUM_ERROR, /*!< Checksum mismatch when decompressing */ + KTX_ERROR_MAX_ENUM = KTX_DECOMPRESS_CHECKSUM_ERROR /*!< For safety checks. */ +} ktx_error_code_e; +/** + * @deprecated + * @~English + * @brief For backward compatibility + */ +#define KTX_error_code ktx_error_code_e + +#define KTX_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } +#define KTX_ENDIAN_REF (0x04030201) +#define KTX_ENDIAN_REF_REV (0x01020304) +#define KTX_HEADER_SIZE (64) + +/** + * @~English + * @brief Result codes returned by library functions. + */ + typedef enum ktx_error_code_e ktxResult; + +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ +typedef struct ktxKVListEntry* ktxHashList; + +typedef struct ktxStream ktxStream; + +#define KTX_APIENTRYP KTX_APIENTRY * +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ +typedef struct ktxKVListEntry ktxHashListEntry; + +typedef enum ktxOrientationX { + KTX_ORIENT_X_LEFT = 'l', KTX_ORIENT_X_RIGHT = 'r' +} ktxOrientationX; + +typedef enum ktxOrientationY { + KTX_ORIENT_Y_UP = 'u', KTX_ORIENT_Y_DOWN = 'd' +} ktxOrientationY; + +typedef enum ktxOrientationZ { + KTX_ORIENT_Z_IN = 'i', KTX_ORIENT_Z_OUT = 'o' +} ktxOrientationZ; + +typedef enum class_id { + ktxTexture1_c = 1, + ktxTexture2_c = 2 +} class_id; + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +struct ktxOrientation { + ktxOrientationX x; /*!< Orientation in X */ + ktxOrientationY y; /*!< Orientation in Y */ + ktxOrientationZ z; /*!< Orientation in Z */ +}; + +#define KTXTEXTURECLASSDEFN \ + class_id classId; \ + struct ktxTexture_vtbl* vtbl; \ + struct ktxTexture_vvtbl* vvtbl; \ + struct ktxTexture_protected* _protected; \ + ktx_bool_t isArray; \ + ktx_bool_t isCubemap; \ + ktx_bool_t isCompressed; \ + ktx_bool_t generateMipmaps; \ + ktx_uint32_t baseWidth; \ + ktx_uint32_t baseHeight; \ + ktx_uint32_t baseDepth; \ + ktx_uint32_t numDimensions; \ + ktx_uint32_t numLevels; \ + ktx_uint32_t numLayers; \ + ktx_uint32_t numFaces; \ + struct ktxOrientation orientation; \ + ktxHashList kvDataHead; \ + ktx_uint32_t kvDataLen; \ + ktx_uint8_t* kvData; \ + ktx_size_t dataSize; \ + ktx_uint8_t* pData; + + +/** + * @class ktxTexture + * @~English + * @brief Base class representing a texture. + * + * ktxTextures should be created only by one of the provided + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture { + KTXTEXTURECLASSDEFN +} ktxTexture; +/** + * @typedef ktxTexture::classId + * @~English + * @brief Identify the class type. + * + * Since there are no public ktxTexture constructors, this can only have + * values of ktxTexture1_c or ktxTexture2_c. + */ +/** + * @typedef ktxTexture::vtbl + * @~English + * @brief Pointer to the class's vtble. + */ +/** + * @typedef ktxTexture::vvtbl + * @~English + * @brief Pointer to the class's vtble for Vulkan functions. + * + * A separate vtble is used so this header does not need to include vulkan.h. + */ +/** + * @typedef ktxTexture::_protected + * @~English + * @brief Opaque pointer to the class's protected variables. + */ +/** + * @typedef ktxTexture::isArray + * @~English + * + * KTX_TRUE if the texture is an array texture, i.e, + * a GL_TEXTURE_*_ARRAY target is to be used. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture is a cubemap or cubemap array. + */ +/** + * @typedef ktxTexture::isCubemap + * @~English + * + * KTX_TRUE if the texture's format is a block compressed format. + */ +/** + * @typedef ktxTexture::generateMipmaps + * @~English + * + * KTX_TRUE if mipmaps should be generated for the texture by + * ktxTexture_GLUpload() or ktxTexture_VkUpload(). + */ +/**n + * @typedef ktxTexture::baseWidth + * @~English + * @brief Width of the texture's base level. + */ +/** + * @typedef ktxTexture::baseHeight + * @~English + * @brief Height of the texture's base level. + */ +/** + * @typedef ktxTexture::baseDepth + * @~English + * @brief Depth of the texture's base level. + */ +/** + * @typedef ktxTexture::numDimensions + * @~English + * @brief Number of dimensions in the texture: 1, 2 or 3. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of mip levels in the texture. + * + * Must be 1, if @c generateMipmaps is KTX_TRUE. Can be less than a + * full pyramid but always starts at the base level. + */ +/** + * @typedef ktxTexture::numLevels + * @~English + * @brief Number of array layers in the texture. + */ +/** + * @typedef ktxTexture::numFaces + * @~English + * @brief Number of faces: 6 for cube maps, 1 otherwise. + */ +/** + * @typedef ktxTexture::orientation + * @~English + * @brief Describes the logical orientation of the images in each dimension. + * + * ktxOrientationX for X, ktxOrientationY for Y and ktxOrientationZ for Z. + */ +/** + * @typedef ktxTexture::kvDataHead + * @~English + * @brief Head of the hash list of metadata. + */ +/** + * @typedef ktxTexture::kvDataLen + * @~English + * @brief Length of the metadata, if it has been extracted in its raw form, + * otherwise 0. + */ +/** + * @typedef ktxTexture::kvData + * @~English + * @brief Pointer to the metadata, if it has been extracted in its raw form, + * otherwise NULL. + */ +/** + * @typedef ktxTexture::dataSize + * @~English + * @brief Byte length of the texture's uncompressed image data. + */ +/** + * @typedef ktxTexture::pData + * @~English + * @brief Pointer to the start of the image data. + */ + +/** + * @memberof ktxTexture + * @~English + * @brief Signature of function called by the ktxTexture_Iterate* + * functions to receive image data. + * + * The function parameters are used to pass values which change for each image. + * Obtain values which are uniform across all images from the @c ktxTexture + * object. + * + * @param [in] miplevel MIP level from 0 to the max level which is + * dependent on the texture size. + * @param [in] face usually 0; for cube maps, one of the 6 cube + * faces in the order +X, -X, +Y, -Y, +Z, -Z, + * 0 to 5. + * @param [in] width width of the image. + * @param [in] height height of the image or, for 1D textures + * textures, 1. + * @param [in] depth depth of the image or, for 1D & 2D + * textures, 1. + * @param [in] faceLodSize number of bytes of data pointed at by + * @p pixels. + * @param [in] pixels pointer to the image data. + * @param [in,out] userdata pointer for the application to pass data to and + * from the callback function. + */ + +typedef KTX_error_code + (* PFNKTXITERCB)(int miplevel, int face, + int width, int height, int depth, + ktx_uint64_t faceLodSize, + void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +typedef void (KTX_APIENTRY* PFNKTEXDESTROY)(ktxTexture* This); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXGETIMAGEOFFSET)(ktxTexture* This, ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + ktx_size_t* pOffset); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETDATASIZEUNCOMPRESSED)(ktxTexture* This); +typedef ktx_size_t + (KTX_APIENTRY* PFNKTEXGETIMAGESIZE)(ktxTexture* This, ktx_uint32_t level); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELEVELS)(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXITERATELOADLEVELFACES)(ktxTexture* This, + PFNKTXITERCB iterCb, + void* userdata); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXLOADIMAGEDATA)(ktxTexture* This, + ktx_uint8_t* pBuffer, + ktx_size_t bufSize); +typedef ktx_bool_t + (KTX_APIENTRY* PFNKTEXNEEDSTRANSCODING)(ktxTexture* This); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMMEMORY)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + const ktx_uint8_t* src, + ktx_size_t srcSize); + +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXSETIMAGEFROMSTDIOSTREAM)(ktxTexture* This, + ktx_uint32_t level, + ktx_uint32_t layer, + ktx_uint32_t faceSlice, + FILE* src, ktx_size_t srcSize); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTDIOSTREAM)(ktxTexture* This, FILE* dstsstr); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETONAMEDFILE)(ktxTexture* This, + const char* const dstname); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, + ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + struct ktxTexture_vtbl { + PFNKTEXDESTROY Destroy; + PFNKTEXGETIMAGEOFFSET GetImageOffset; + PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + PFNKTEXGETIMAGESIZE GetImageSize; + PFNKTEXITERATELEVELS IterateLevels; + PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + PFNKTEXLOADIMAGEDATA LoadImageData; + PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; +}; + +/**************************************************************** + * Macros to give some backward compatibility to the previous API + ****************************************************************/ + +/** + * @~English + * @brief Helper for calling the Destroy virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_Destroy + */ +#define ktxTexture_Destroy(This) (This)->vtbl->Destroy(This) + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +#define ktxTexture_GetImageOffset(This, level, layer, faceSlice, pOffset) \ + (This)->vtbl->GetImageOffset(This, level, layer, faceSlice, pOffset) + +/** + * @~English + * @brief Helper for calling the GetDataSizeUncompressed virtual method of a ktxTexture. + * + * For a ktxTexture1 this will always return the value of This->dataSize. + * + * @copydetails ktxTexture2.ktxTexture2_GetDataSizeUncompressed + */ +#define ktxTexture_GetDataSizeUncompressed(This) \ + (This)->vtbl->GetDataSizeUncompressed(This) + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +#define ktxTexture_GetImageSize(This, level) \ + (This)->vtbl->GetImageSize(This, level) + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +#define ktxTexture_IterateLevels(This, iterCb, userdata) \ + (This)->vtbl->IterateLevels(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + #define ktxTexture_IterateLoadLevelFaces(This, iterCb, userdata) \ + (This)->vtbl->IterateLoadLevelFaces(This, iterCb, userdata) + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +#define ktxTexture_LoadImageData(This, pBuffer, bufSize) \ + (This)->vtbl->LoadImageData(This, pBuffer, bufSize) + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +#define ktxTexture_NeedsTranscoding(This) (This)->vtbl->NeedsTranscoding(This) + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +#define ktxTexture_SetImageFromMemory(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromMemory(This, level, layer, faceSlice, src, srcSize) + +/** + * @~English + * @brief Helper for calling the SetImageFromStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromStdioStream + */ +#define ktxTexture_SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) \ + (This)->vtbl->SetImageFromStdioStream(This, level, layer, faceSlice, \ + src, srcSize) + +/** + * @~English + * @brief Helper for calling the WriteToStdioStream virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStdioStream + */ +#define ktxTexture_WriteToStdioStream(This, dstsstr) \ + (This)->vtbl->WriteToStdioStream(This, dstsstr) + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +#define ktxTexture_WriteToNamedFile(This, dstname) \ + (This)->vtbl->WriteToNamedFile(This, dstname) + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ + (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + + +/** + * @class ktxTexture1 + * @~English + * @brief Class representing a KTX version 1 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture1 { + KTXTEXTURECLASSDEFN + ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + struct ktxTexture1_private* _private; /*!< Private data. */ +} ktxTexture1; + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +typedef enum ktxSupercmpScheme { + KTX_SS_NONE = 0, /*!< No supercompression. */ + KTX_SS_BASIS_LZ = 1, /*!< Basis LZ supercompression. */ + KTX_SS_ZSTD = 2, /*!< ZStd supercompression. */ + KTX_SS_ZLIB = 3, /*!< ZLIB supercompression. */ + KTX_SS_BEGIN_RANGE = KTX_SS_NONE, + KTX_SS_END_RANGE = KTX_SS_ZLIB, + KTX_SS_BEGIN_VENDOR_RANGE = 0x10000, + KTX_SS_END_VENDOR_RANGE = 0x1ffff, + KTX_SS_BEGIN_RESERVED = 0x20000, + KTX_SUPERCOMPRESSION_BASIS = KTX_SS_BASIS_LZ, + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_BASIS_LZ instead. */ + KTX_SUPERCOMPRESSION_ZSTD = KTX_SS_ZSTD + /*!< @deprecated Will be removed before v4 release. Use KTX_SS_ZSTD instead. */ +} ktxSupercmpScheme; + +/** + * @class ktxTexture2 + * @~English + * @brief Class representing a KTX version 2 format texture. + * + * ktxTextures should be created only by one of the ktxTexture_Create* + * functions and these fields should be considered read-only. + */ +typedef struct ktxTexture2 { + KTXTEXTURECLASSDEFN + ktx_uint32_t vkFormat; + ktx_uint32_t* pDfd; + ktxSupercmpScheme supercompressionScheme; + ktx_bool_t isVideo; + ktx_uint32_t duration; + ktx_uint32_t timescale; + ktx_uint32_t loopcount; + struct ktxTexture2_private* _private; /*!< Private data. */ +} ktxTexture2; + +#define ktxTexture(t) ((ktxTexture*)t) + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1_Create() and + * ktxTexture2_Create(). + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef struct +{ + ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + ktx_bool_t isArray; /*!< Set to KTX_TRUE if the texture is to be an + array texture. Means OpenGL will use a + GL_TEXTURE_*_ARRAY target. */ + ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} ktxTextureCreateInfo; + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +typedef enum { + KTX_TEXTURE_CREATE_NO_STORAGE = 0, /*!< Don't allocate any image storage. */ + KTX_TEXTURE_CREATE_ALLOC_STORAGE = 1 /*!< Allocate image storage. */ +} ktxTextureCreateStorageEnum; + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +enum ktxTextureCreateFlagBits { + KTX_TEXTURE_CREATE_NO_FLAGS = 0x00, + KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT = 0x01, + /*!< Load the images from the KTX source. */ + KTX_TEXTURE_CREATE_RAW_KVDATA_BIT = 0x02, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + KTX_TEXTURE_CREATE_SKIP_KVDATA_BIT = 0x04, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT = 0x08 + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +}; +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +typedef ktx_uint32_t ktxTextureCreateFlags; + +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + ktxStream_write write; /*!< pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< destruct the stream. */ + + enum streamType type; + union { + FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + struct + { + void* address; /**< pointer to the data. */ + void* allocatorAddress; /**< pointer to a memory allocator. */ + ktx_size_t size; /**< size of the data. */ + } custom_ptr; /**< pointer to a struct for custom streams. */ + } data; /**< pointer to the stream data. */ + ktx_off_t readpos; /**< used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +}; + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ +KTX_API ktx_uint8_t* KTX_APIENTRY +ktxTexture_GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture_GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ +KTX_API ktx_size_t KTX_APIENTRY +ktxTexture_GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, + GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, + void* userdata); +/* + * Create a new ktxTexture1. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture1_NeedsTranscoding(ktxTexture1* This); + +/* + * Write a ktxTexture object to a stdio stream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + +/* + * Write a ktxTexture object to a named file in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToNamedFile(ktxTexture1* This, const char* const dstname); + +/* + * Write a ktxTexture object to a block of memory in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, + ktx_uint8_t** bytes, ktx_size_t* size); + +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + +/* + * Create a new ktxTexture2. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_Create(ktxTextureCreateInfo* createInfo, + ktxTextureCreateStorageEnum storageAllocation, + ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStdioStream(FILE* stdioStream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromNamedFile(const char* const filename, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + +KTX_API void KTX_APIENTRY +ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, + ktx_uint32_t* componentByteLength); + +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetNumComponents(ktxTexture2* This); + +KTX_API khr_df_transfer_e KTX_APIENTRY +ktxTexture2_GetOETF_e(ktxTexture2* This); + +// For backward compatibility +KTX_API ktx_uint32_t KTX_APIENTRY +ktxTexture2_GetOETF(ktxTexture2* This); + +KTX_API khr_df_model_e KTX_APIENTRY +ktxTexture2_GetColorModel_e(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This); + +KTX_API ktx_bool_t KTX_APIENTRY +ktxTexture2_NeedsTranscoding(ktxTexture2* This); + +/** + * @~English + * @brief Flags specifiying UASTC encoding options. + */ +typedef enum ktx_pack_uastc_flag_bits_e { + KTX_PACK_UASTC_LEVEL_FASTEST = 0, + /*!< Fastest compression. 43.45dB. */ + KTX_PACK_UASTC_LEVEL_FASTER = 1, + /*!< Faster compression. 46.49dB. */ + KTX_PACK_UASTC_LEVEL_DEFAULT = 2, + /*!< Default compression. 47.47dB. */ + KTX_PACK_UASTC_LEVEL_SLOWER = 3, + /*!< Slower compression. 48.01dB. */ + KTX_PACK_UASTC_LEVEL_VERYSLOW = 4, + /*!< Very slow compression. 48.24dB. */ + KTX_PACK_UASTC_MAX_LEVEL = KTX_PACK_UASTC_LEVEL_VERYSLOW, + /*!< Maximum supported quality level. */ + KTX_PACK_UASTC_LEVEL_MASK = 0xF, + /*!< Mask to extract the level from the other bits. */ + KTX_PACK_UASTC_FAVOR_UASTC_ERROR = 8, + /*!< Optimize for lowest UASTC error. */ + KTX_PACK_UASTC_FAVOR_BC7_ERROR = 16, + /*!< Optimize for lowest BC7 error. */ + KTX_PACK_UASTC_ETC1_FASTER_HINTS = 64, + /*!< Optimize for faster transcoding to ETC1. */ + KTX_PACK_UASTC_ETC1_FASTEST_HINTS = 128, + /*!< Optimize for fastest transcoding to ETC1. */ + KTX_PACK_UASTC__ETC1_DISABLE_FLIP_AND_INDIVIDUAL = 256 + /*!< Not documented in BasisU code. */ +} ktx_pack_uastc_flag_bits_e; +typedef ktx_uint32_t ktx_pack_uastc_flags; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +typedef enum ktx_pack_astc_quality_levels_e { + KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST = 0, + /*!< Fastest compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_FAST = 10, + /*!< Fast compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM = 60, + /*!< Medium compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH = 98, + /*!< Slower compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE = 100, + /*!< Very slow compression. */ + KTX_PACK_ASTC_QUALITY_LEVEL_MAX = KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE, + /*!< Maximum supported quality level. */ +} ktx_pack_astc_quality_levels_e; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +typedef enum ktx_pack_astc_block_dimension_e { + // 2D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4, //: 8.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4, //: 6.40 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5, //: 5.12 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5, //: 4.27 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x5, //: 3.20 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x6, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x5, //: 2.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x6, //: 2.13 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_8x8, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x8, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_10x10, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x10, //: 1.07 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_12x12, //: 0.89 bpp + // 3D formats + KTX_PACK_ASTC_BLOCK_DIMENSION_3x3x3, //: 4.74 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x3x3, //: 3.56 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x3, //: 2.67 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_4x4x4, //: 2.00 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x4x4, //: 1.60 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x4, //: 1.28 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_5x5x5, //: 1.02 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x5x5, //: 0.85 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x5, //: 0.71 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6, //: 0.59 bpp + KTX_PACK_ASTC_BLOCK_DIMENSION_MAX = KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6 + /*!< Maximum supported blocks. */ +} ktx_pack_astc_block_dimension_e; + +/** + * @~English + * @brief Options specifying ASTC encoder profile mode + * This and function is used later to derive the profile. + */ +typedef enum ktx_pack_astc_encoder_mode_e { + KTX_PACK_ASTC_ENCODER_MODE_DEFAULT, + KTX_PACK_ASTC_ENCODER_MODE_LDR, + KTX_PACK_ASTC_ENCODER_MODE_HDR, + KTX_PACK_ASTC_ENCODER_MODE_MAX = KTX_PACK_ASTC_ENCODER_MODE_HDR +} ktx_pack_astc_encoder_mode_e; + +extern KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture_CompressAstc. + * + * Passing a struct initialized to 0 (e.g. " = {0};") will use blockDimension + * 4x4, mode LDR and qualityLevel FASTEST. Setting qualityLevel to + * KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM is recommended. + */ +typedef struct ktxAstcParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + ktx_uint32_t qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps + In this mode normals are compressed to X,Y components + Discarding Z component, reader will need to generate Z + component in shaders. + */ + + ktx_bool_t perceptual; + /*!< The codec should optimize for perceptual error, instead of direct + RMS error. This aims to improves perceived image quality, but + typically lowers the measured PSNR score. Perceptual methods are + currently only available for normal maps and RGB color data. + */ + + char inputSwizzle[4]; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} ktxAstcParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params); + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + +/** + * @memberof ktxTexture2 + * @~English + * @brief Structure for passing extended parameters to + * ktxTexture2_CompressBasisEx(). + * + * If you only want default values, use ktxTexture2_CompressBasis(). Here, at a minimum you + * must initialize the structure as follows: + * @code + * ktxBasisParams params = {0}; + * params.structSize = sizeof(params); + * params.compressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e compressionLevel has to be explicitly set because 0 is a valid @e compressionLevel + * but is not the default used by the BasisU encoder when no value is set. Only the other + * settings that are to be non-default must be non-zero. + */ +typedef struct ktxBasisParams { + ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + ktx_bool_t uastc; + /*!< True to use UASTC base, false to use ETC1S base. */ + ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + ktx_uint32_t compressionLevel; + /*!< Encoding speed vs. quality tradeoff. Range is [0,5]. Higher values + are slower, but give higher quality. There is no default. Callers + must explicitly set this value. Callers can use + KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL as a default value. + Currently this is 2. + */ + ktx_uint32_t qualityLevel; + /*!< Compression quality. Range is [1,255]. Lower gives better + compression/lower quality/faster. Higher gives less compression + /higher quality/slower. This automatically determines values for + @c maxEndpoints, @c maxSelectors, + @c endpointRDOThreshold and @c selectorRDOThreshold + for the target quality level. Setting these parameters overrides + the values determined by @c qualityLevel which defaults to + 128 if neither it nor both of @c maxEndpoints and + @c maxSelectors have been set. + @note @e Both of @c maxEndpoints and @c maxSelectors + must be set for them to have any effect. + @note qualityLevel will only determine values for + @c endpointRDOThreshold and @c selectorRDOThreshold + when its value exceeds 128, otherwise their defaults will be used. + */ + ktx_uint32_t maxEndpoints; + /*!< Manually set the max number of color endpoint clusters. + Range is [1,16128]. Default is 0, unset. If this is set, maxSelectors + must also be set, otherwise the value will be ignored. + */ + float endpointRDOThreshold; + /*!< Set endpoint RDO quality threshold. The default is 1.25. Lower is + higher quality but less quality per output bit (try [1.0,3.0]. + This will override the value chosen by @c qualityLevel. + */ + ktx_uint32_t maxSelectors; + /*!< Manually set the max number of color selector clusters. Range + is [1,16128]. Default is 0, unset. If this is set, maxEndpoints + must also be set, otherwise the value will be ignored. + */ + float selectorRDOThreshold; + /*!< Set selector RDO quality threshold. The default is 1.5. Lower is + higher quality but less quality per output bit (try [1.0,3.0]). + This will override the value chosen by @c qualityLevel. + */ + char inputSwizzle[4]; + /*!< A swizzle to apply before encoding. It must match the regular + expression /^[rgba01]{4}$/. If both this and preSwizzle + are specified ktxTexture_CompressBasisEx will raise + KTX_INVALID_OPERATION. + */ + ktx_bool_t normalMap; + /*!< Tunes codec parameters for better quality on normal maps (no + selector RDO, no endpoint RDO) and sets the texture's DFD appropriately. + Only valid for linear textures. + */ + ktx_bool_t separateRGToRGB_A; + /*!< @deprecated. This was and is a no-op. 2-component inputs have always been + automatically separated using an "rrrg" inputSwizzle. @sa inputSwizzle and normalMode. + */ + ktx_bool_t preSwizzle; + /*!< If the texture has @c KTXswizzle metadata, apply it before + compressing. Swizzling, like @c rabb may yield drastically + different error metrics if done after supercompression. + */ + ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + ktx_bool_t noSelectorRDO; + /*!< Disable selector rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + + /* UASTC params */ + + ktx_pack_uastc_flags uastcFlags; + /*!< A set of ::ktx_pack_uastc_flag_bits_e controlling UASTC + encoding. The most important value is the level given in the + least-significant 4 bits which selects a speed vs quality tradeoff + as shown in the following table: + + Level/Speed | Quality + :-----: | :-------: + KTX_PACK_UASTC_LEVEL_FASTEST | 43.45dB + KTX_PACK_UASTC_LEVEL_FASTER | 46.49dB + KTX_PACK_UASTC_LEVEL_DEFAULT | 47.47dB + KTX_PACK_UASTC_LEVEL_SLOWER | 48.01dB + KTX_PACK_UASTC_LEVEL_VERYSLOW | 48.24dB + */ + ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + float uastcRDOQualityScalar; + /*!< UASTC RDO quality scalar (lambda). Lower values yield higher + quality/larger LZ compressed files, higher values yield lower + quality/smaller LZ compressed files. A good range to try is [.2,4]. + Full range is [.001,50.0]. Default is 1.0. + */ + ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + float uastcRDOMaxSmoothBlockErrorScale; + /*!< UASTC RDO max smooth block error scale. Range is [1,300]. + Default is 10.0, 1.0 is disabled. Larger values suppress more + artifacts (and allocate more bits) on smooth blocks. + */ + float uastcRDOMaxSmoothBlockStdDev; + /*!< UASTC RDO max smooth block standard deviation. Range is + [.01,65536.0]. Default is 18.0. Larger values expand the range of + blocks considered smooth. + */ + ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + +} ktxBasisParams; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params); + +/** + * @~English + * @brief Enumerators for specifying the transcode target format. + * + * For BasisU/ETC1S format, @e Opaque and @e alpha here refer to 2 separate + * RGB images, a.k.a slices within the BasisU compressed data. For UASTC + * format they refer to the RGB and the alpha components of the UASTC data. If + * the original image had only 2 components, R will be in the opaque portion + * and G in the alpha portion. The R value will be replicated in the RGB + * components. In the case of BasisU the G value will be replicated in all 3 + * components of the alpha slice. If the original image had only 1 component + * it's value is replicated in all 3 components of the opaque portion and + * there is no alpha. + * + * @note You should not transcode sRGB encoded data to @c KTX_TTF_BC4_R, + * @c KTX_TTF_BC5_RG, @c KTX_TTF_ETC2_EAC_R{,G}11, @c KTX_TTF_RGB565, + * @c KTX_TTF_BGR565 or @c KTX_TTF_RGBA4444 formats as neither OpenGL nor + * Vulkan support sRGB variants of these. Doing sRGB decoding in the shader + * will not produce correct results if any texture filtering is being used. + */ +typedef enum ktx_transcode_fmt_e { + // Compressed formats + + // ETC1-2 + KTX_TTF_ETC1_RGB = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_RGBA = 1, + /*!< Opaque+alpha. EAC_A8 block followed by an ETC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + + // BC1-5, BC7 (desktop, some mobile devices) + KTX_TTF_BC1_RGB = 2, + /*!< Opaque only, no punchthrough alpha support yet. Returns RGB + or alpha data, if KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS + flag is specified. */ + KTX_TTF_BC3_RGBA = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + KTX_TTF_BC4_R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_BC5_RG = 5, + /*!< Two BC4 blocks, R=opaque.g and G=alpha.g The texture should + have an alpha channel (if not G will be all 255's. For tangent + space normal maps. */ + KTX_TTF_BC7_RGBA = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + KTX_TTF_PVRTC1_4_RGB = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_PVRTC1_4_RGBA = 9, + /*!< Opaque+alpha. Most useful for simple opacity maps. If the + texture doesn't have an alpha channel KTX_TTF_PVRTC1_4_RGB + will be used instead. Lowest quality of any supported + texture format. */ + + // ASTC (mobile, Intel devices, hopefully all desktop GPU's one day) + KTX_TTF_ASTC_4x4_RGBA = 10, + /*!< Opaque+alpha, ASTC 4x4. The alpha channel will be opaque for + textures without an alpha channel. The transcoder uses + RGB/RGBA/L/LA modes, void extent, and up to two ([0,47] and + [0,255]) endpoint precisions. */ + + // ATC and FXT1 formats are not supported by KTX2 as there + // are no equivalent VkFormats. + + KTX_TTF_PVRTC2_4_RGB = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + KTX_TTF_PVRTC2_4_RGBA = 19, + /*!< Opaque+alpha. Slower to transcode than cTFPVRTC2_4_RGB. + Premultiplied alpha is highly recommended, otherwise the + color channel can leak into the alpha channel on transparent + blocks. */ + + KTX_TTF_ETC2_EAC_R11 = 20, + /*!< R only (ETC2 EAC R11 unsigned). R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + KTX_TTF_ETC2_EAC_RG11 = 21, + /*!< RG only (ETC2 EAC RG11 unsigned), R=opaque.g, G=alpha.g. The + texture should have an alpha channel (if not G will be all + 255's. For tangent space normal maps. */ + + // Uncompressed (raw pixel) formats + KTX_TTF_RGBA32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + KTX_TTF_RGB565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + KTX_TTF_BGR565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + KTX_TTF_RGBA4444 = 16, + /*!< 16bpp RGBA image stored in raster (not block) order in memory, + R at bit position 12, A at bit position 0. */ + + // Values for automatic selection of RGB or RGBA depending if alpha + // present. + KTX_TTF_ETC = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + KTX_TTF_BC1_OR_3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + KTX_TTF_NOSELECTION = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + KTX_TF_ETC1 = KTX_TTF_ETC1_RGB, + //!< @deprecated. Use #KTX_TTF_ETC1_RGB. + KTX_TF_ETC2 = KTX_TTF_ETC, + //!< @deprecated. Use #KTX_TTF_ETC. + KTX_TF_BC1 = KTX_TTF_BC1_RGB, + //!< @deprecated. Use #KTX_TTF_BC1_RGB. + KTX_TF_BC3 = KTX_TTF_BC3_RGBA, + //!< @deprecated. Use #KTX_TTF_BC3_RGBA. + KTX_TF_BC4 = KTX_TTF_BC4_R, + //!< @deprecated. Use #KTX_TTF_BC4_R. + KTX_TF_BC5 = KTX_TTF_BC5_RG, + //!< @deprecated. Use #KTX_TTF_BC5_RG. + KTX_TTF_BC7_M6_RGB = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TTF_BC7_M5_RGBA = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA. + KTX_TF_BC7_M6_OPAQUE_ONLY = KTX_TTF_BC7_RGBA, + //!< @deprecated. Use #KTX_TTF_BC7_RGBA + KTX_TF_PVRTC1_4_OPAQUE_ONLY = KTX_TTF_PVRTC1_4_RGB + //!< @deprecated. Use #KTX_TTF_PVRTC1_4_RGB. +} ktx_transcode_fmt_e; + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +typedef enum ktx_transcode_flag_bits_e { + KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 = 2, + /*!< PVRTC1: decode non-pow2 ETC1S texture level to the next larger + power of 2 (not implemented yet, but we're going to support it). + Ignored if the slice's dimensions are already a power of 2. + */ + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS = 4, + /*!< When decoding to an opaque texture format, if the Basis data has + alpha, decode the alpha slice instead of the color slice to the + output texture format. Has no effect if there is no alpha data. + */ + KTX_TF_HIGH_QUALITY = 32, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} ktx_transcode_flag_bits_e; +typedef ktx_uint32_t ktx_transcode_flags; + +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, + ktx_transcode_flags transcodeFlags); + +/* + * Returns a string corresponding to a KTX error code. + */ +KTX_API const char* KTX_APIENTRY +ktxErrorString(KTX_error_code error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ +KTX_API const char* KTX_APIENTRY +ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ +KTX_API const char* KTX_APIENTRY +ktxTranscodeFormatString(ktx_transcode_fmt_e format); + +KTX_API KTX_error_code KTX_APIENTRY ktxHashList_Create(ktxHashList** ppHl); +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_CreateCopy(ktxHashList** ppHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Construct(ktxHashList* pHl); +KTX_API void KTX_APIENTRY +ktxHashList_ConstructCopy(ktxHashList* pHl, ktxHashList orig); +KTX_API void KTX_APIENTRY ktxHashList_Destroy(ktxHashList* head); +KTX_API void KTX_APIENTRY ktxHashList_Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_AddKVPair(ktxHashList* pHead, const char* key, + unsigned int valueLen, const void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_DeleteKVPair(ktxHashList* pHead, const char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindEntry(ktxHashList* pHead, const char* key, + ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_FindValue(ktxHashList* pHead, const char* key, + unsigned int* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ +KTX_API ktxHashListEntry* KTX_APIENTRY +ktxHashList_Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Serialize(ktxHashList* pHead, + unsigned int* kvdLen, unsigned char** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashList_Deserialize(ktxHashList* pHead, unsigned int kvdLen, void* kvd); + +/* + * Get the key from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetKey(ktxHashListEntry* This, + unsigned int* pKeyLen, char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxHashListEntry_GetValue(ktxHashListEntry* This, + unsigned int* pValueLen, void** ppValue); + +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintInfoForMemory(const ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX2 file. * + *===========================================================*/ + +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForMemory(const ktx_uint8_t* bytes, ktx_size_t size); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForNamedFile(const char* const filename); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoTextForStream(ktxStream* stream); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForNamedFile(const char* const filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +KTX_API KTX_error_code KTX_APIENTRY ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); + +#ifdef __cplusplus +} +#endif + +/*========================================================================* + * For backward compatibilty with the V3 & early versions of the V4 APIs. * + *========================================================================*/ + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_transcode_fmt_e ktx_transcode_fmt_e + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktx_texture_decode_flags ktx_transcode_flag_bits + +/** + * @deprecated Will be dropped before V4 release. + */ +#define ktxTexture_GetSize ktxTexture_GetDatasize + +/** +@~English +@page libktx_history Revision History + +No longer updated. Kept to preserve ancient history. For more recent history see the repo log at +https://github.com/KhronosGroup/KTX-Software. See also the Release Notes in the repo. + +@section v8 Version 4.0 +Added: +@li Support for KTX Version 2. +@li Support for encoding and transcoding Basis Universal images in KTX Version 2 files. +@li Function to print info about a KTX file. + +@section v7 Version 3.0.1 +Fixed: +@li GitHub issue #159: compile failure with recent Vulkan SDKs. +@li Incorrect mapping of GL DXT3 and DXT5 formats to Vulkan equivalents. +@li Incorrect BC4 blocksize. +@li Missing mapping of PVRTC formats from GL to Vulkan. +@li Incorrect block width and height calculations for sizes that are not + a multiple of the block size. +@li Incorrect KTXorientation key in test images. + +@section v6 Version 3.0 +Added: +@li new ktxTexture object based API for reading KTX files without an OpenGL context. +@li Vulkan loader. @#include to use it. + +Changed: +@li ktx.h to not depend on KHR/khrplatform.h and GL{,ES*}/gl{corearb,}.h. + Applications using OpenGL must now include these files themselves. +@li ktxLoadTexture[FMN], removing the hack of loading 1D textures as 2D textures + when the OpenGL context does not support 1D textures. + KTX_UNSUPPORTED_TEXTURE_TYPE is now returned. + +@section v5 Version 2.0.2 +Added: +@li Support for cubemap arrays. + +Changed: +@li New build system + +Fixed: +@li GitHub issue #40: failure to byte-swap key-value lengths. +@li GitHub issue #33: returning incorrect target when loading cubemaps. +@li GitHub PR #42: loading of texture arrays. +@li GitHub PR #41: compilation error when KTX_OPENGL_ES2=1 defined. +@li GitHub issue #39: stack-buffer-overflow in toktx +@li Don't use GL_EXTENSIONS on recent OpenGL versions. + +@section v4 Version 2.0.1 +Added: +@li CMake build files. Thanks to Pavel Rotjberg for the initial version. + +Changed: +@li ktxWriteKTXF to check the validity of the type & format combinations + passed to it. + +Fixed: +@li Public Bugzilla 999: 16-bit luminance texture cannot be written. +@li compile warnings from compilers stricter than MS Visual C++. Thanks to + Pavel Rotjberg. + +@section v3 Version 2.0 +Added: +@li support for decoding ETC2 and EAC formats in the absence of a hardware + decoder. +@li support for converting textures with legacy LUMINANCE, LUMINANCE_ALPHA, + etc. formats to the equivalent R, RG, etc. format with an + appropriate swizzle, when loading in OpenGL Core Profile contexts. +@li ktxErrorString function to return a string corresponding to an error code. +@li tests for ktxLoadTexture[FN] that run under OpenGL ES 3.0 and OpenGL 3.3. + The latter includes an EGL on WGL wrapper that makes porting apps between + OpenGL ES and OpenGL easier on Windows. +@li more texture formats to ktxLoadTexture[FN] and toktx tests. + +Changed: +@li ktxLoadTexture[FMN] to discover the capabilities of the GL context at + run time and load textures, or not, according to those capabilities. + +Fixed: +@li failure of ktxWriteKTXF to pad image rows to 4 bytes as required by the KTX + format. +@li ktxWriteKTXF exiting with KTX_FILE_WRITE_ERROR when attempting to write + more than 1 byte of face-LOD padding. + +Although there is only a very minor API change, the addition of ktxErrorString, +the functional changes are large enough to justify bumping the major revision +number. + +@section v2 Version 1.0.1 +Implemented ktxLoadTextureM. +Fixed the following: +@li Public Bugzilla 571: crash when null passed for pIsMipmapped. +@li Public Bugzilla 572: memory leak when unpacking ETC textures. +@li Public Bugzilla 573: potential crash when unpacking ETC textures with unused padding pixels. +@li Public Bugzilla 576: various small fixes. + +Thanks to Krystian Bigaj for the ktxLoadTextureM implementation and these fixes. + +@section v1 Version 1.0 +Initial release. + +*/ + +#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ diff --git a/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/libktx.a b/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/libktx.a new file mode 100644 index 00000000..268ce652 Binary files /dev/null and b/KTXLoader/libktx/ktx.xcframework/xros-arm64_x86_64-simulator/libktx.a differ diff --git a/KTXLoaderTests/KTXLoaderTests.swift b/KTXLoaderTests/KTXLoaderTests.swift new file mode 100644 index 00000000..dc333a1f --- /dev/null +++ b/KTXLoaderTests/KTXLoaderTests.swift @@ -0,0 +1,42 @@ +// +// KTXLoaderTests.swift +// KTXLoaderTests +// +// Created by Jesse Armand on 30/11/23. +// Copyright © 2023 DarkHorse. All rights reserved. +// + +import XCTest +@testable import KTXLoader + +class KTXLoaderTests: XCTestCase { + + func testLoadTextureData() throws { + guard let device = MTLCreateSystemDefaultDevice() else { + XCTFail("Fail to create metal system default device") + return + } + let resourceName = "Cube_BaseColor" + + guard let url = Bundle(for: KTXLoaderTests.self).url(forResource: resourceName, withExtension: "ktx2", subdirectory: "art.scnassets/Cube/") else { + XCTFail("\(resourceName).ktx2 is not available to load") + return + } + + let data = try Data(contentsOf: url) + + let loader = try KTXLoader(data: data, device: device) + let metalTexture = loader.loadTexture(using: device) + Swift.debugPrint("MLTTexture size (width: \(metalTexture.width), height: \(metalTexture.height))") + Swift.debugPrint("MLTTexture pixel format: \(metalTexture.pixelFormat)") + Swift.debugPrint("MLTTexture compression type \(metalTexture.compressionType)") + Swift.debugPrint("MLTTexture texture type \(metalTexture.textureType)") + + XCTAssertEqual(metalTexture.pixelFormat, MTLPixelFormat.astc_4x4_srgb) + XCTAssertEqual(metalTexture.compressionType, MTLTextureCompressionType.lossless) + XCTAssertEqual(metalTexture.textureType, MTLTextureType.type2D) + XCTAssertEqual(metalTexture.width, 256) + XCTAssertEqual(metalTexture.height, 256) + } + +} diff --git a/Sample/Common/art.scnassets/Cube/Cube.bin b/Sample/Common/art.scnassets/Cube/Cube.bin new file mode 100644 index 00000000..7dae4b0b Binary files /dev/null and b/Sample/Common/art.scnassets/Cube/Cube.bin differ diff --git a/Sample/Common/art.scnassets/Cube/Cube.gltf b/Sample/Common/art.scnassets/Cube/Cube.gltf new file mode 100644 index 00000000..72686660 --- /dev/null +++ b/Sample/Common/art.scnassets/Cube/Cube.gltf @@ -0,0 +1,209 @@ +{ + "accessors": [ + { + "bufferView": 0, + "byteOffset": 0, + "componentType": 5123, + "count": 36, + "max": [ + 35 + ], + "min": [ + 0 + ], + "type": "SCALAR" + }, + { + "bufferView": 1, + "byteOffset": 0, + "componentType": 5126, + "count": 36, + "max": [ + 1, + 1, + 1.000001 + ], + "min": [ + -1, + -1, + -1 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 0, + "componentType": 5126, + "count": 36, + "max": [ + 1, + 1, + 1 + ], + "min": [ + -1, + -1, + -1 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "byteOffset": 0, + "componentType": 5126, + "count": 36, + "max": [ + 1, + 0, + 0, + 1 + ], + "min": [ + 0, + 0, + -1, + -1 + ], + "type": "VEC4" + }, + { + "bufferView": 4, + "byteOffset": 0, + "componentType": 5126, + "count": 36, + "max": [ + 1, + 1 + ], + "min": [ + -1, + -1 + ], + "type": "VEC2" + } + ], + "asset": { + "generator": "VKTS glTF 2.0 exporter", + "version": "2.0" + }, + "bufferViews": [ + { + "buffer": 0, + "byteLength": 72, + "byteOffset": 0, + "target": 34963 + }, + { + "buffer": 0, + "byteLength": 432, + "byteOffset": 72, + "target": 34962 + }, + { + "buffer": 0, + "byteLength": 432, + "byteOffset": 504, + "target": 34962 + }, + { + "buffer": 0, + "byteLength": 576, + "byteOffset": 936, + "target": 34962 + }, + { + "buffer": 0, + "byteLength": 288, + "byteOffset": 1512, + "target": 34962 + } + ], + "buffers": [ + { + "byteLength": 1800, + "uri": "Cube.bin" + } + ], + "images": [ + { + "uri": "Cube_BaseColor.ktx2", + "mimeType": "image/ktx2" + }, + { + "uri": "Cube_MetallicRoughness.ktx2", + "mimeType": "image/ktx2" + } + ], + "materials": [ + { + "name": "Cube", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 0 + }, + "metallicRoughnessTexture": { + "index": 1 + } + } + } + ], + "meshes": [ + { + "name": "Cube", + "primitives": [ + { + "attributes": { + "NORMAL": 2, + "POSITION": 1, + "TANGENT": 3, + "TEXCOORD_0": 4 + }, + "indices": 0, + "material": 0, + "mode": 4 + } + ] + } + ], + "nodes": [ + { + "mesh": 0, + "name": "Cube" + } + ], + "samplers": [ + {} + ], + "scene": 0, + "scenes": [ + { + "nodes": [ + 0 + ] + } + ], + "textures": [ + { + "sampler": 0, + "extensions": { + "KHR_texture_basisu": { + "source": 0 + } + } + }, + { + "sampler": 0, + "extensions": { + "KHR_texture_basisu": { + "source": 1 + } + } + } + ], + "extensionsUsed": [ + "KHR_texture_basisu" + ], + "extensionsRequired": [ + "KHR_texture_basisu" + ] +} \ No newline at end of file diff --git a/Sample/Common/art.scnassets/Cube/Cube_BaseColor.ktx2 b/Sample/Common/art.scnassets/Cube/Cube_BaseColor.ktx2 new file mode 100644 index 00000000..ac67f7d1 Binary files /dev/null and b/Sample/Common/art.scnassets/Cube/Cube_BaseColor.ktx2 differ diff --git a/Sample/Common/art.scnassets/Cube/Cube_MetallicRoughness.ktx2 b/Sample/Common/art.scnassets/Cube/Cube_MetallicRoughness.ktx2 new file mode 100644 index 00000000..62010d92 Binary files /dev/null and b/Sample/Common/art.scnassets/Cube/Cube_MetallicRoughness.ktx2 differ diff --git a/Sample/iOS/GameViewController.swift b/Sample/iOS/GameViewController.swift index c75bfe15..7fbd214f 100644 --- a/Sample/iOS/GameViewController.swift +++ b/Sample/iOS/GameViewController.swift @@ -23,7 +23,8 @@ class GameViewController: UIViewController { var scene: SCNScene do { - let sceneSource = try GLTFSceneSource(named: "art.scnassets/GlassVase/Wayfair-GlassVase-BCHH2364.glb") + // let sceneSource = try GLTFSceneSource(named: "art.scnassets/OfficeCorridor/glTF/Office_Corridor_compressed.gltf") + let sceneSource = try GLTFSceneSource(named: "art.scnassets/Cube/Cube.gltf") scene = try sceneSource.scene() } catch { print("\(error.localizedDescription)") @@ -41,7 +42,7 @@ class GameViewController: UIViewController { self.gameView!.showsStatistics = true // configure the view - self.gameView!.backgroundColor = UIColor.gray + self.gameView!.backgroundColor = UIColor.lightGray self.gameView!.delegate = self } @@ -51,9 +52,9 @@ class GameViewController: UIViewController { self.gameView!.scene = scene self.scene = scene - //to give nice reflections :) - scene.lightingEnvironment.contents = "art.scnassets/shinyRoom.jpg" - scene.lightingEnvironment.intensity = 2; + // to give nice reflections :) + // scene.lightingEnvironment.contents = "art.scnassets/shinyRoom.jpg" + // scene.lightingEnvironment.intensity = 2; } override var shouldAutorotate: Bool { diff --git a/Sample/iOS/KTX-Bridging-Header.h b/Sample/iOS/KTX-Bridging-Header.h new file mode 100644 index 00000000..987188d9 --- /dev/null +++ b/Sample/iOS/KTX-Bridging-Header.h @@ -0,0 +1,9 @@ +// +// KTX-Bridging-Header.h +// GLTFSceneKit +// +// Created by Jesse Armand on 29/11/23. +// Copyright © 2023 DarkHorse. All rights reserved. +// + +#import "KTXLoader.h" diff --git a/Sources/GLTFSceneKit/GLTFUnarchiver.swift b/Sources/GLTFSceneKit/GLTFUnarchiver.swift index f1ea60dc..9f3fba55 100644 --- a/Sources/GLTFSceneKit/GLTFUnarchiver.swift +++ b/Sources/GLTFSceneKit/GLTFUnarchiver.swift @@ -10,6 +10,7 @@ import SceneKit import SpriteKit import QuartzCore import CoreGraphics +import KTXLoader let glbMagic = 0x46546C67 // "glTF" let chunkTypeJSON = 0x4E4F534A // "JSON" @@ -873,7 +874,7 @@ public class GLTFUnarchiver { property.wrapT = wrapT } - private func loadTexture(index: Int) throws -> SCNMaterialProperty { + private func loadTexture(index: Int) throws -> Any? { guard index < self.textures.count else { throw GLTFUnarchiveError.DataInconsistent("loadTexture: out of index: \(index) < \(self.textures.count)") } @@ -887,17 +888,84 @@ public class GLTFUnarchiver { } let glTexture = textures[index] + func loadTextureToMetalTexture(index: GLTFGlTFid) throws -> MTLTexture { + guard index < self.images.count else { + throw GLTFUnarchiveError.DataInconsistent("loadTexture: out of index: \(index) < \(self.images.count)") + } + + guard let images = self.json.images else { + throw GLTFUnarchiveError.DataInconsistent("loadTexture: images is not defined") + } + let glImage = images[index] + + func loadKTXTextureData(_ data: Data) throws -> MTLTexture { + guard let device = MTLCreateSystemDefaultDevice() else { + throw GLTFUnarchiveError.NotSupported("loadTexture: loading texture as a metal texture requires a metal device") + } + + let loader = try KTXLoader(data: data, device: device) + let metalTexture = loader.loadTexture(using: device) + return metalTexture + } + + if let uri = glImage.uri { + if let base64Str = self.getBase64Str(from: uri) { + guard let data = Data(base64Encoded: base64Str) else { + throw GLTFUnarchiveError.DataInconsistent("loadTexture: cannot convert the base64 string to Data") + } + if let mimeType = glImage.mimeType, mimeType == "image/ktx2" { + return try loadKTXTextureData(data) + } else { + throw GLTFUnarchiveError.NotSupported("loadTexture: Image \(glImage.mimeType ?? "mime type") is not supported") + } + + } else { + let url = URL(fileURLWithPath: uri, relativeTo: self.directoryPath) + let data = try Data(contentsOf: url) + if let mimeType = glImage.mimeType, mimeType == "image/ktx2" { + return try loadKTXTextureData(data) + } else { + throw GLTFUnarchiveError.NotSupported("loadTexture: Image \(glImage.mimeType ?? "mime type") is not supported") + } + } + + } else if let bufferViewIndex = glImage.bufferView { + do { + let data = try loadBufferView(index: bufferViewIndex) + if let mimeType = glImage.mimeType, mimeType == GLTFMediaTypeKTX2 { + return try loadKTXTextureData(data) + } else { + throw GLTFUnarchiveError.NotSupported("loadTexture: Image \(glImage.mimeType ?? "mime type") is not supported") + } + } catch { + throw error + } + } else { + throw GLTFUnarchiveError.DataInconsistent("loadTexture: Image data source is not defined") + } + } + + if let khrTextureBasisU = glTexture.extensions?.extensions["KHR_texture_basisu"] as? [String: Codable], + let sourceIndex = khrTextureBasisU["source"] as? GLTFGlTFid { + let metalTexture = try loadTextureToMetalTexture(index: sourceIndex) + glTexture.didLoad(by: metalTexture, unarchiver: self) + return metalTexture + } + guard let sourceIndex = glTexture.source else { - throw GLTFUnarchiveError.NotSupported("loadTexture: texture without source is not supported") + let metalTexture = try loadTextureToMetalTexture(index: 0) + glTexture.didLoad(by: metalTexture, unarchiver: self) + return metalTexture } - let image = try self.loadImage(index: sourceIndex) + let image = try self.loadImage(index: sourceIndex) let texture = SCNMaterialProperty(contents: image) + // enable Texture filtering sample so we get less aliasing when they are farther away texture.mipFilter = .linear - + // TODO: retain glTexture.name somewhere - + if let sampler = glTexture.sampler { try self.setSampler(index: sampler, to: texture) } else { @@ -905,31 +973,39 @@ public class GLTFUnarchiver { texture.wrapS = .repeat texture.wrapT = .repeat } - + self.textures[index] = texture - + glTexture.didLoad(by: texture, unarchiver: self) return texture } func setTexture(index: Int, to property: SCNMaterialProperty) throws { let texture = try self.loadTexture(index: index) - guard let contents = texture.contents else { - throw GLTFUnarchiveError.DataInconsistent("setTexture: contents of texture \(index) is nil") - } - - property.contents = contents - property.minificationFilter = texture.minificationFilter - property.magnificationFilter = texture.magnificationFilter - property.mipFilter = texture.mipFilter - property.wrapS = texture.wrapS - property.wrapT = texture.wrapT - property.intensity = texture.intensity - property.maxAnisotropy = texture.maxAnisotropy - property.contentsTransform = texture.contentsTransform - property.mappingChannel = texture.mappingChannel - if #available(OSX 10.13, *) { - property.textureComponents = texture.textureComponents + if let materialProperty = texture as? SCNMaterialProperty { + guard let contents = materialProperty.contents else { + throw GLTFUnarchiveError.DataInconsistent("setTexture: contents of texture \(index) is nil") + } + + property.contents = contents + property.minificationFilter = materialProperty.minificationFilter + property.magnificationFilter = materialProperty.magnificationFilter + property.mipFilter = materialProperty.mipFilter + property.wrapS = materialProperty.wrapS + property.wrapT = materialProperty.wrapT + property.intensity = materialProperty.intensity + property.maxAnisotropy = materialProperty.maxAnisotropy + property.contentsTransform = materialProperty.contentsTransform + property.mappingChannel = materialProperty.mappingChannel + if #available(OSX 10.13, *) { + property.textureComponents = materialProperty.textureComponents + } + } else if let metalTexture = texture as? MTLTexture { + property.contents = metalTexture + + if let glTexture = self.json.textures?[index], let sampler = glTexture.sampler { + try setSampler(index: sampler, to: property) + } } } @@ -984,7 +1060,7 @@ public class GLTFUnarchiver { if let baseTexture = pbr.baseColorTexture { try self.setTexture(index: baseTexture.index, to: material.diffuse) material.diffuse.mappingChannel = baseTexture.texCoord - + //let baseColorFactor = createVector4(pbr.baseColorFactor) //material.setValue(NSValue(scnVector4: baseColorFactor), forKeyPath: "baseColorFactor") material.setValue(pbr.baseColorFactor[0], forKey: "baseColorFactorR") @@ -1044,15 +1120,19 @@ public class GLTFUnarchiver { material.isDoubleSided = glMaterial.doubleSided - material.shaderModifiers = [ - .surface: try! String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierSurface", ofType: "shader")!), encoding: String.Encoding.utf8) - ] + if let surfaceModifier = try? String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierSurface", ofType: "shader")!), encoding: String.Encoding.utf8) { + material.shaderModifiers = [ + .surface: surfaceModifier + ] + } #if SEEMS_TO_HAVE_DOUBLESIDED_BUG - if material.isDoubleSided { + if material.isDoubleSided { + if let surfaceModifier = try? String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierSurface_doubleSidedWorkaround", ofType: "shader")!), encoding: String.Encoding.utf8) { material.shaderModifiers = [ - .surface: try! String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierSurface_doubleSidedWorkaround", ofType: "shader")!), encoding: String.Encoding.utf8) + .surface: surfaceModifier ] } + } #endif switch glMaterial.alphaMode { @@ -1061,9 +1141,13 @@ public class GLTFUnarchiver { case "BLEND": material.blendMode = .alpha material.writesToDepthBuffer = false - material.shaderModifiers![.surface] = try! String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierSurface_alphaModeBlend", ofType: "shader")!), encoding: String.Encoding.utf8) + if let surfaceModifier = try? String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierSurface_alphaModeBlend", ofType: "shader")!), encoding: String.Encoding.utf8) { + material.shaderModifiers?[.surface] = surfaceModifier + } case "MASK": - material.shaderModifiers![.fragment] = try! String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierFragment_alphaCutoff", ofType: "shader")!), encoding: String.Encoding.utf8) + if let fragmentModifier = try? String(contentsOf: URL(fileURLWithPath: bundle.path(forResource: "GLTFShaderModifierSurface_alphaModeBlend", ofType: "shader")!), encoding: String.Encoding.utf8) { + material.shaderModifiers?[.fragment] = fragmentModifier + } default: throw GLTFUnarchiveError.NotSupported("loadMaterial: alphaMode \(glMaterial.alphaMode) is not supported") } diff --git a/Sources/GLTFSceneKit/schema/extensions/VRM/GLTFVRM_VRM.swift b/Sources/GLTFSceneKit/schema/extensions/VRM/GLTFVRM_VRM.swift index 1014221c..f7fe0b43 100644 --- a/Sources/GLTFSceneKit/schema/extensions/VRM/GLTFVRM_VRM.swift +++ b/Sources/GLTFSceneKit/schema/extensions/VRM/GLTFVRM_VRM.swift @@ -218,7 +218,27 @@ struct GLTFVRM_GLTFVRMExtension: GLTFCodable { nodes.forEach { node in node.renderingOrder = material.renderQueue - guard let orgMaterial = node.geometry?.material(named: material.name) else { return } + guard let orgGeometry = node.geometry else { return } + guard let orgMaterial = orgGeometry.material(named: material.name) else { return } + + // Remove gltf color data + if orgGeometry.sources(for: .color) != nil { + let sources = orgGeometry.sources.filter { + $0.semantic != .color + } + let geometry = SCNGeometry(sources: sources, elements: orgGeometry.elements) + geometry.edgeCreasesElement = orgGeometry.edgeCreasesElement + geometry.edgeCreasesSource = orgGeometry.edgeCreasesSource + geometry.levelsOfDetail = orgGeometry.levelsOfDetail + geometry.materials = orgGeometry.materials + geometry.name = orgGeometry.name + geometry.program = orgGeometry.program + geometry.shaderModifiers = orgGeometry.shaderModifiers + geometry.subdivisionLevel = orgGeometry.subdivisionLevel + geometry.tessellator = orgGeometry.tessellator + geometry.wantsAdaptiveSubdivision = orgGeometry.wantsAdaptiveSubdivision + node.geometry = geometry + } let isAlphaCutoff: Bool let blendModeFloat = material.floatProperties["_BlendMode"]