From 23bca0e23e6b97bed2b5d1b0ca95498a4d139436 Mon Sep 17 00:00:00 2001 From: Rune Date: Wed, 22 Jul 2026 00:32:44 +0200 Subject: [PATCH] add bindings --- .gitignore | 4 + .gitmodules | 3 + BeefProj.toml | 14 + BeefSpace.toml | 8 + KTX-Software | 1 + Setup/BeefProj.toml | 9 + Setup/BeefSpace.toml | 8 + Setup/all.h | 5 + Setup/src/Program.bf | 297 ++++++ src/KHR_df.bf | 691 ++++++++++++++ src/KTX.bf | 2072 ++++++++++++++++++++++++++++++++++++++++++ src/KTXVulkan.bf | 281 ++++++ src/Library.bf | 61 ++ 13 files changed, 3454 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 BeefProj.toml create mode 100644 BeefSpace.toml create mode 160000 KTX-Software create mode 100644 Setup/BeefProj.toml create mode 100644 Setup/BeefSpace.toml create mode 100644 Setup/all.h create mode 100644 Setup/src/Program.bf create mode 100644 src/KHR_df.bf create mode 100644 src/KTX.bf create mode 100644 src/KTXVulkan.bf create mode 100644 src/Library.bf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4342935 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +BeefSpace_User.toml +BeefSpace_Lock.toml +build +recovery diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..606958c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "KTX-Software"] + path = KTX-Software + url = https://github.com/KhronosGroup/KTX-Software.git diff --git a/BeefProj.toml b/BeefProj.toml new file mode 100644 index 0000000..5f28f82 --- /dev/null +++ b/BeefProj.toml @@ -0,0 +1,14 @@ +FileVersion = 1 + +[Project] +Name = "KTX" +TargetType = "BeefLib" +StartupObject = "KTX.Program" + +[Dependencies] +corlib = "*" +"CxxBuildTool.git" = {Git = "https://git.unicon-gmbh.de/Rune/CxxBuildTool.git"} + +[[ProjectFolder.Items]] +Type = "IgnoreSource" +Name = "KTXVulkan.bf" diff --git a/BeefSpace.toml b/BeefSpace.toml new file mode 100644 index 0000000..67e9dd5 --- /dev/null +++ b/BeefSpace.toml @@ -0,0 +1,8 @@ +FileVersion = 1 + +[Workspace] +StartupProject = "KTX" + +[Projects] +KTX = {Path = "."} +"CxxBuildTool.git" = {Git = "https://git.unicon-gmbh.de/Rune/CxxBuildTool.git"} diff --git a/KTX-Software b/KTX-Software new file mode 160000 index 0000000..b9bcfeb --- /dev/null +++ b/KTX-Software @@ -0,0 +1 @@ +Subproject commit b9bcfeb1df982f38b11d460cdd9878aa748ebafb diff --git a/Setup/BeefProj.toml b/Setup/BeefProj.toml new file mode 100644 index 0000000..924013d --- /dev/null +++ b/Setup/BeefProj.toml @@ -0,0 +1,9 @@ +FileVersion = 1 + +[Project] +Name = "KTX.Setup" +StartupObject = "KTX.Setup.Program" + +[Dependencies] +corlib = "*" +"Cpp2Beef.git" = {Git = "https://git.unicon-gmbh.de/Rune/Cpp2Beef.git"} diff --git a/Setup/BeefSpace.toml b/Setup/BeefSpace.toml new file mode 100644 index 0000000..3371965 --- /dev/null +++ b/Setup/BeefSpace.toml @@ -0,0 +1,8 @@ +FileVersion = 1 + +[Workspace] +StartupProject = "KTX.Setup" + +[Projects] +"KTX.Setup" = {Path = "."} +"Cpp2Beef.git" = {Git = "https://git.unicon-gmbh.de/Rune/Cpp2Beef.git"} diff --git a/Setup/all.h b/Setup/all.h new file mode 100644 index 0000000..a547f46 --- /dev/null +++ b/Setup/all.h @@ -0,0 +1,5 @@ +#define VK_NO_PROTOTYPES +#include "vulkan/vulkan_core.h" +#include +#include + diff --git a/Setup/src/Program.bf b/Setup/src/Program.bf new file mode 100644 index 0000000..f645c70 --- /dev/null +++ b/Setup/src/Program.bf @@ -0,0 +1,297 @@ +using System; +using System.IO; +using System.Collections; +using System.Diagnostics; + +using Cpp2Beef; +using LibClang; + +namespace KTX.Setup; + +class ExampleGenerator : Cpp2BeefGenerator, this(Span args) +{ + protected override Span Args => args; + protected override Flags Flags => .None; + + StreamWriter ktxWriter = new .()..Create("../src/KTX.bf")..Write(""" + // This file was generated by Cpp2Beef + + using System; + using System.Interop; + + namespace KTX; + + + """) ~ delete _; + StreamWriter ktxVulkanWriter = new .()..Create("../src/KTXVulkan.bf")..Write(""" + // This file was generated by Cpp2Beef + + using System; + using System.Interop; + + namespace KTX; + + + """) ~ delete _; + StreamWriter khrDfWriter = new .()..Create("../src/KHR_df.bf")..Write(""" + // This file was generated by Cpp2Beef + + using System; + using System.Interop; + + namespace KTX; + + + """) ~ delete _; + + protected override StreamWriter GetWriterForHeader(StringView header) + { + if (header.EndsWith("ktx.h")) + return ktxWriter; + if (header.EndsWith("ktxvulkan.h")) + return ktxVulkanWriter; + if (header.EndsWith("khr_df.h")) + return khrDfWriter; + return null; + } + + Dictionary vtblPfns = new .(24) ~ DeleteDictionaryAndKeys!(_); + + protected override void HandleCursor(CXCursor cursor) + { + switch (cursor.kind) + { + case .TypedefDecl: + let spelling = GetCursorSpelling!(cursor); + if (spelling == "ktxHashList" || spelling == "ktxHashListEntry" || spelling == "ktxStream") + return; + case .MacroDefinition: + let spelling = GetCursorSpelling!(cursor); + if (spelling == "KTXTEXTURECLASSDEFN" || spelling == "KTX_APIENTRYP" || spelling == "KTX_API" || + spelling == "KTX_APIENTRY" || spelling == "KTX_error_code") + return; + + if (Clang.Cursor_IsMacroFunctionLike(cursor) == 0 || !spelling.StartsWith("ktx")) break; + BeginCursor(cursor); + AccessSpecifier(cursor); + str.Append("static "); + let nameInBindings = spelling[(spelling.IndexOf('_')+1)...]; + Runtime.Assert(vtblPfns.TryGetAlt(nameInBindings, ?, let pfnType)); + Type(Clang.GetResultType(pfnType)); + str.Append(' '); + str.Append(nameInBindings); + Flush(); + let tokens = ScopeTokenize!(cursor, unit); + WriteTokens(tokens[1...], Clang.GetRangeEnd(Clang.Cursor_GetSpellingNameRange(cursor, 0, 0)), .Identifier); + String buffer = scope .(256)..Append(str); + uint32 argI = 0; + insert: for (int i = 0; i < buffer.Length; i++) + { + switch (buffer[i]) + { + case '(', ',': + str.Clear(); + Type(Clang.GetArgType(pfnType, argI++)); + str.Append(' '); + int idx = i+1 + (_ == ',' ? 1 : 0); + buffer.Insert(idx, str); + case ')': + buffer.Insert(i+1, " =>"); + break insert; + } + } + buffer.Replace("->", "."); + str.Set(buffer); + str.Append(';'); + return; + case .StructDecl: + if (Clang.Cursor_IsAnonymous(cursor) != 0) + return; + if (Clang.GetCursorLexicalParent(cursor).kind == .StructDecl) + return; + let spelling = GetCursorSpelling!(cursor); + if (spelling == "ktxKVListEntry" || (spelling == "ktxStream" && Clang.EqualCursors(cursor, Clang.GetTypeDeclaration(Clang.GetCursorType(cursor))) != 0)) + return; + BeginCursor(cursor); + Record(cursor); + return; + case .FieldDecl: + if (GetCursorSpelling!(Clang.GetCursorSemanticParent(cursor)) == "ktxTexture_vtbl") + vtblPfns.Add(new .(GetCursorSpelling!(cursor)), + Clang.GetPointeeType(Clang.GetTypedefDeclUnderlyingType(Clang.GetTypeDeclaration(Clang.GetCursorType(cursor)))) + ); + default: + } + base.HandleCursor(cursor); + if (fileInfo.prevEnd == default) + fileInfo.prevEnd = GetCursorAnchor(cursor); + } + + append String blockBuffer; + protected override Block GetCursorBlock(CXCursor cursor) + { + if (cursor.kind == .FunctionDecl || cursor.kind == .MacroDefinition) do + { + let spelling = GetCursorSpelling!(cursor); + if (!spelling.StartsWith("ktx")) break; + int index = spelling.IndexOf('_'); + if (index < 0) break; + blockBuffer.Set(spelling[.. define our own types. */ +public typealias ktx_uint8_t = c_uchar; +public typealias ktx_bool_t = bool; + +public typealias ktx_uint16_t = c_ushort; +public typealias ktx_int16_t = c_short; +public typealias ktx_uint32_t = c_uint; +public typealias ktx_int32_t = c_int; +public typealias ktx_size_t = c_size; +public typealias ktx_uint64_t = c_ulonglong; +public typealias ktx_int64_t = c_longlong; + + + + + + + + + + + +/* This will cause compilation to fail if size of uint32 != 4. */ +public typealias ktx_uint32_t_SIZE_ASSERT = c_uchar[1]; + +/* + * 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++. + */ + + /* + * To avoid having to including gl.h ... + */ + public typealias GLboolean = c_uchar; + public typealias GLenum = c_uint; + public typealias GLint = c_int; + public typealias GLsizei = c_int; + public typealias GLuint = c_uint; + public typealias GLubyte = c_uchar; + + + + + + +static +{ +/** + * @~English + * @brief Key string for standard writer metadata. + */ +public const let KTX_ANIMDATA_KEY = "KTXanimData"; +/** + * @~English + * @brief Key string for standard orientation metadata. + */ +public const let KTX_ORIENTATION_KEY = "KTXorientation"; +/** + * @~English + * @brief Key string for standard swizzle metadata. + */ +public const let KTX_SWIZZLE_KEY = "KTXswizzle"; +/** + * @~English + * @brief Key string for standard map range metadata. + */ +public const let KTX_MAP_RANGE_KEY = "KTXmapRange"; +/** + * @~English + * @brief Key string for standard writer metadata. + */ +public const let KTX_WRITER_KEY = "KTXwriter"; +/** + * @~English + * @brief Key string for standard writer supercompression parameter metadata. + */ +public const let KTX_WRITER_SCPARAMS_KEY = "KTXwriterScParams"; +/** + * @~English + * @brief Standard KTX 1 format for 1D orientation value. + */ +public const let KTX_ORIENTATION1_FMT = "S=%c"; +/** + * @~English + * @brief Standard KTX 1 format for 2D orientation value. + */ +public const let KTX_ORIENTATION2_FMT = "S=%c,T=%c"; +/** + * @~English + * @brief Standard KTX 1 format for 3D orientation value. + */ +public const let KTX_ORIENTATION3_FMT = "S=%c,T=%c,R=%c"; +/** + * @~English + * @brief Required unpack alignment + */ +public const let KTX_GL_UNPACK_ALIGNMENT = 4; +public const let KTX_FACESLICE_WHOLE_LEVEL = uint32.MaxValue; + +public const let KTX_TRUE = true; +public const let KTX_FALSE = false; +} + + + +/** + * @~English + * @brief Error codes returned by library functions. + */ +[AllowDuplicates] public enum ktx_error_code_e : c_int { + 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. */ +} +/** + * @~English + * @deprecated Use #ktx_error_code_e. + * @brief For backward compatibility + */ + + +static +{ +public const let KTX_IDENTIFIER_REF = uint8[?]( 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A ); +public const let KTX_ENDIAN_REF = (0x04030201); +public const let KTX_ENDIAN_REF_REV = (0x01020304); +public const let KTX_HEADER_SIZE = (64); + } + + + +/** + * @~English + * @brief Result codes returned by library functions. + */ + public typealias ktxResult = ktx_error_code_e; + +static +{ +/** + * @class ktxHashList + * @~English + * @brief Opaque handle to a ktxHashList. + */ + + + + + +} + + +/** + * @class ktxHashListEntry + * @~English + * @brief Opaque handle to an entry in a @ref ktxHashList. + */ + + +[AllowDuplicates] public enum ktxOrientationX : c_int { + KtxOrientXLeft = 'l', KtxOrientXRight = 'r', +} + +[AllowDuplicates] public enum ktxOrientationY : c_int { + KtxOrientYUp = 'u', KtxOrientYDown = 'd', +} + +[AllowDuplicates] public enum ktxOrientationZ : c_int { + KtxOrientZIn = 'i', KtxOrientZOut = 'o', +} + +[AllowDuplicates] public enum class_id : c_int { + Ktxtexture1C = 1, + Ktxtexture2C = 2, +} + +/** + * @~English + * @brief Struct describing the logical orientation of an image. + */ +[CRepr] public struct ktxOrientation { + public ktxOrientationX x; /*!< Orientation in X */ + public ktxOrientationY y; /*!< Orientation in Y */ + public ktxOrientationZ z; /*!< Orientation in Z */ +} + + + + + + + + + + + + + + + + + + + + + + + + + +/** + * @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. + */ +[CRepr] public struct ktxTexture { + public class_id classId; public ktxTexture_vtbl* vtbl; public ktxTexture_vvtbl* vvtbl; public ktxTexture_protected* _protected; public ktx_bool_t isArray; public ktx_bool_t isCubemap; public ktx_bool_t isCompressed; public ktx_bool_t generateMipmaps; public ktx_uint32_t baseWidth; public ktx_uint32_t baseHeight; public ktx_uint32_t baseDepth; public ktx_uint32_t numDimensions; public ktx_uint32_t numLevels; public ktx_uint32_t numLayers; public ktx_uint32_t numFaces; public ktxOrientation orientation; public ktxHashList kvDataHead; public ktx_uint32_t kvDataLen; public ktx_uint8_t* kvData; public ktx_size_t dataSize; public ktx_uint8_t* pData; +} +/** + * @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::isCompressed + * @~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(). + */ +/** + * @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. + */ + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTXITERCB(c_int miplevel, c_int face, c_int width, c_int height, c_int depth, ktx_uint64_t faceLodSize, void* pixels, void* userdata); + +/* Don't use KTX_APIENTRYP to avoid a Doxygen bug. */ +[CallingConvention(KTX_APIENTRYP)] public function void PFNKTEXDESTROY(ktxTexture*); + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXGETIMAGEOFFSET(ktxTexture*, ktx_uint32_t, ktx_uint32_t, ktx_uint32_t, ktx_size_t*); + + + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_size_t PFNKTEXGETDATASIZEUNCOMPRESSED(ktxTexture*); + + [CallingConvention(KTX_APIENTRYP)] public function ktx_size_t PFNKTEXGETIMAGESIZE(ktxTexture*, ktx_uint32_t); + + [CallingConvention(KTX_APIENTRYP)] public function ktx_size_t PFNKTEXGETLEVELSIZE(ktxTexture*, ktx_uint32_t); + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXITERATELEVELS(ktxTexture*, PFNKTXITERCB, void*); + + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXITERATELOADLEVELFACES(ktxTexture*, PFNKTXITERCB, void*); + + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXLOADIMAGEDATA(ktxTexture*, ktx_uint8_t*, ktx_size_t); + + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_bool_t PFNKTEXNEEDSTRANSCODING(ktxTexture*); + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_bool_t PFNKTEXISTRANSCODABLE(ktxTexture*); + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_bool_t PFNKTEXISHDR(ktxTexture*); + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXSETIMAGEFROMMEMORY(ktxTexture*, ktx_uint32_t, ktx_uint32_t, ktx_uint32_t, ktx_uint8_t*, ktx_size_t); + + + + + + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXSETIMAGEFROMSTDIOSTREAM(ktxTexture*, ktx_uint32_t, ktx_uint32_t, ktx_uint32_t, FILE*, ktx_size_t); + + + + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXWRITETOSTDIOSTREAM(ktxTexture*, FILE*); + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXWRITETONAMEDFILE(ktxTexture*, c_char*); + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXWRITETOMEMORY(ktxTexture*, ktx_uint8_t**, ktx_size_t*); + + + [CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e PFNKTEXWRITETOSTREAM(ktxTexture*, ktxStream*); + + +/** + * @memberof ktxTexture + * @~English + * @brief Table of virtual ktxTexture methods. + */ + [CRepr] public struct ktxTexture_vtbl { + public PFNKTEXDESTROY Destroy; + public PFNKTEXGETIMAGEOFFSET GetImageOffset; + public PFNKTEXGETDATASIZEUNCOMPRESSED GetDataSizeUncompressed; + public PFNKTEXGETIMAGESIZE GetImageSize; + public PFNKTEXGETLEVELSIZE GetLevelSize; + public PFNKTEXITERATELEVELS IterateLevels; + public PFNKTEXITERATELOADLEVELFACES IterateLoadLevelFaces; + public PFNKTEXNEEDSTRANSCODING NeedsTranscoding; + public PFNKTEXISTRANSCODABLE IsTranscodable; + public PFNKTEXISHDR IsHDR; + public PFNKTEXLOADIMAGEDATA LoadImageData; + public PFNKTEXSETIMAGEFROMMEMORY SetImageFromMemory; + public PFNKTEXSETIMAGEFROMSTDIOSTREAM SetImageFromStdioStream; + public PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; + public PFNKTEXWRITETONAMEDFILE WriteToNamedFile; + public PFNKTEXWRITETOMEMORY WriteToMemory; + public PFNKTEXWRITETOSTREAM WriteToStream; +} + +extension ktxTexture +{ +/**************************************************************** + * 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 + */ +public static void Destroy(ktxTexture* This) => (This).vtbl.Destroy(This); + +/** + * @~English + * @brief Helper for calling the GetImageOffset virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageOffset + */ +public static ktx_error_code_e GetImageOffset(ktxTexture* This, ktx_uint32_t level, ktx_uint32_t layer, ktx_uint32_t faceSlice, ktx_size_t* 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 + */ +public static ktx_size_t GetDataSizeUncompressed(ktxTexture* This) => + (This).vtbl.GetDataSizeUncompressed(This); + + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +public static ktx_size_t GetImageSize(ktxTexture* This, ktx_uint32_t level) => + (This).vtbl.GetImageSize(This, level); + + +/** + * @~English + * @brief Helper for calling the GetImageSize virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_GetImageSize + */ +public static ktx_size_t GetLevelSize(ktxTexture* This, ktx_uint32_t level) => + (This).vtbl.GetLevelSize(This, level); + + +/** + * @~English + * @brief Helper for calling the IterateLevels virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLevels + */ +public static ktx_error_code_e IterateLevels(ktxTexture* This, PFNKTXITERCB iterCb, void* userdata) => + (This).vtbl.IterateLevels(This, iterCb, userdata); + + +/** + * @~English + * @brief Helper for calling the IterateLoadLevelFaces virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IterateLoadLevelFaces + */ + public static ktx_error_code_e IterateLoadLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, void* userdata) => + (This).vtbl.IterateLoadLevelFaces(This, iterCb, userdata); + + +/** + * @~English + * @brief Helper for calling the LoadImageData virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_LoadImageData + */ +public static ktx_error_code_e LoadImageData(ktxTexture* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize) => + (This).vtbl.LoadImageData(This, pBuffer, bufSize); + + +/** + * @~English + * @brief Helper for calling the NeedsTranscoding virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_NeedsTranscoding + */ +public static ktx_bool_t NeedsTranscoding(ktxTexture* This) => (This).vtbl.NeedsTranscoding(This); + +/** + * @~English + * @brief Helper for calling the IsTranscodable virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IsTranscodable + */ +public static ktx_bool_t IsTranscodable(ktxTexture* This) => (This).vtbl.IsTranscodable(This); + +/** + * @~English + * @brief Helper for calling the IsHDR virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_IsHDR + */ +public static ktx_bool_t IsHDR(ktxTexture* This) => (This).vtbl.IsHDR(This); + +/** + * @~English + * @brief Helper for calling the SetImageFromMemory virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_SetImageFromMemory + */ +public static ktx_error_code_e SetImageFromMemory(ktxTexture* This, ktx_uint32_t level, ktx_uint32_t layer, ktx_uint32_t faceSlice, ktx_uint8_t* + src, ktx_size_t 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 + */ +public static ktx_error_code_e SetImageFromStdioStream(ktxTexture* This, ktx_uint32_t level, ktx_uint32_t layer, ktx_uint32_t faceSlice, FILE* + src, ktx_size_t 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 + */ +public static ktx_error_code_e WriteToStdioStream(ktxTexture* This, FILE* dstsstr) => + (This).vtbl.WriteToStdioStream(This, dstsstr); + + +/** + * @~English + * @brief Helper for calling the WriteToNamedfile virtual method of a + * ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToNamedFile + */ +public static ktx_error_code_e WriteToNamedFile(ktxTexture* This, c_char* dstname) => + (This).vtbl.WriteToNamedFile(This, dstname); + + +/** + * @~English + * @brief Helper for calling the WriteToMemory virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToMemory + */ +public static ktx_error_code_e WriteToMemory(ktxTexture* This, ktx_uint8_t** ppDstBytes, ktx_size_t* pSize) => + (This).vtbl.WriteToMemory(This, ppDstBytes, pSize); + + +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2.ktxTexture2_WriteToStream + */ +public static ktx_error_code_e WriteToStream(ktxTexture* This, ktxStream* 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. + */ +[CRepr] public struct ktxTexture1 { + public class_id classId; public ktxTexture_vtbl* vtbl; public ktxTexture_vvtbl* vvtbl; public ktxTexture_protected* _protected; public ktx_bool_t isArray; public ktx_bool_t isCubemap; public ktx_bool_t isCompressed; public ktx_bool_t generateMipmaps; public ktx_uint32_t baseWidth; public ktx_uint32_t baseHeight; public ktx_uint32_t baseDepth; public ktx_uint32_t numDimensions; public ktx_uint32_t numLevels; public ktx_uint32_t numLayers; public ktx_uint32_t numFaces; public ktxOrientation orientation; public ktxHashList kvDataHead; public ktx_uint32_t kvDataLen; public ktx_uint8_t* kvData; public ktx_size_t dataSize; public ktx_uint8_t* pData; + public ktx_uint32_t glFormat; /*!< Format of the texture data, e.g., GL_RGB. */ + public ktx_uint32_t glInternalformat; /*!< Internal format of the texture data, + e.g., GL_RGB8. */ + public ktx_uint32_t glBaseInternalformat; /*!< Base format of the texture data, + e.g., GL_RGB. */ + public ktx_uint32_t glType; /*!< Type of the texture data, e.g, GL_UNSIGNED_BYTE.*/ + public ktxTexture1_private* _private; /*!< Private data. */ +} + +/*===========================================================* +* KTX format version 2 * +*===========================================================*/ + +/** + * @~English + * @brief Enumerators identifying the supercompression scheme. + */ +[AllowDuplicates] public enum ktxSupercmpScheme : c_int { + None = 0, /*!< No supercompression. */ + BasisLz = 1, /*!< Basis LZ supercompression. */ + Zstd = 2, /*!< ZStd supercompression. */ + Zlib = 3, /*!< ZLIB supercompression. */ + UastcHdr6x6Intermediate = 4, /*!< UASTC HDR 6x6 Intermediate supercompression. */ + BeginRange = None, + EndRange = UastcHdr6x6Intermediate, + BeginVendorRange = 0x10000, + EndVendorRange = 0x1ffff, + BeginReserved = 0x20000, +} + +/** + * @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. + */ +[CRepr] public struct ktxTexture2 { + public class_id classId; public ktxTexture_vtbl* vtbl; public ktxTexture_vvtbl* vvtbl; public ktxTexture_protected* _protected; public ktx_bool_t isArray; public ktx_bool_t isCubemap; public ktx_bool_t isCompressed; public ktx_bool_t generateMipmaps; public ktx_uint32_t baseWidth; public ktx_uint32_t baseHeight; public ktx_uint32_t baseDepth; public ktx_uint32_t numDimensions; public ktx_uint32_t numLevels; public ktx_uint32_t numLayers; public ktx_uint32_t numFaces; public ktxOrientation orientation; public ktxHashList kvDataHead; public ktx_uint32_t kvDataLen; public ktx_uint8_t* kvData; public ktx_size_t dataSize; public ktx_uint8_t* pData; + public ktx_uint32_t vkFormat; + public ktx_uint32_t* pDfd; + public ktxSupercmpScheme supercompressionScheme; + public ktx_bool_t isVideo; + public ktx_uint32_t duration; + public ktx_uint32_t timescale; + public ktx_uint32_t loopcount; + public ktxTexture2_private* _private; /*!< Private data. */ +} + +/* + * If Doxygen sees this macro it gets confused and fails to spot + * references to ktxTexture_*() functions in the running text. It + * also complains it can't find the reference when @ref is used + * with a fully qualified method name to make an intra-class + * reference in the @c ktxTexture class. + * See https://github.com/doxygen/doxygen/issues/10311. + * + * Not documenting the macro is the lesser of two evils. + */ + + /** + * @brief Helper for casting ktxTexture1 and ktxTexture2 to ktxTexture. + * + * Use with caution. + */ + + + +/** + * @memberof ktxTexture + * @~English + * @brief Structure for passing texture information to ktxTexture1\_Create() and + * ktxTexture2\_Create(). + * + * @sa @ref ktxTexture1::ktxTexture1\_Create() "ktxTexture1_Create()" + * @sa @ref ktxTexture2::ktxTexture2\_Create() "ktxTexture2_Create()" + */ +[CRepr] public struct ktxTextureCreateInfo +{ + public ktx_uint32_t glInternalformat; /*!< Internal format for the texture, e.g., + GL_RGB8. Ignored when creating a + ktxTexture2. */ + public ktx_uint32_t vkFormat; /*!< VkFormat for texture. Ignored when creating a + ktxTexture1. */ + public ktx_uint32_t* pDfd; /*!< Pointer to DFD. Used only when creating a + ktxTexture2 and only if vkFormat is + VK_FORMAT_UNDEFINED. */ + public ktx_uint32_t baseWidth; /*!< Width of the base level of the texture. */ + public ktx_uint32_t baseHeight; /*!< Height of the base level of the texture. */ + public ktx_uint32_t baseDepth; /*!< Depth of the base level of the texture. */ + public ktx_uint32_t numDimensions; /*!< Number of dimensions in the texture, 1, 2 + or 3. */ + public ktx_uint32_t numLevels; /*!< Number of mip levels in the texture. Should be + 1 if @c generateMipmaps is KTX_TRUE; */ + public ktx_uint32_t numLayers; /*!< Number of array layers in the texture. */ + public ktx_uint32_t numFaces; /*!< Number of faces: 6 for cube maps, 1 otherwise. */ + public 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. */ + public ktx_bool_t generateMipmaps; /*!< Set to KTX_TRUE if mipmaps should be + generated for the texture when loading + into a 3D API. */ +} + +/** + * @memberof ktxTexture + * @~English + * @brief Enum for requesting, or not, allocation of storage for images. + * + * @sa ktxTexture1_Create() and ktxTexture2_Create(). + */ +[AllowDuplicates] public enum ktxTextureCreateStorageEnum : c_int { + NoStorage = 0, /*!< Don't allocate any image storage. */ + AllocStorage = 1, /*!< Allocate image storage. */ +} + +/** + * @memberof ktxTexture + * @~English + * @brief Flags for requesting services during creation. + * + * @sa ktxTexture_CreateFrom* + */ +[AllowDuplicates] public enum ktxTextureCreateFlagBits : c_int { + NoFlags = 0x00U, + LoadImageData = 0x01U, + /*!< Load the images from the KTX source. */ + RawKvdata = 0x02U, + /*!< Load the raw key-value data instead of + creating a @c ktxHashList from it. */ + SkipKvdata = 0x04U, + /*!< Skip any key-value data. This overrides + the RAW_KVDATA_BIT. */ + CheckGltfBasisu = 0x08U, + /*!< Load texture compatible with the rules + of KHR_texture_basisu glTF extension */ +} +/** + * @memberof ktxTexture + * @~English + * @brief Type for TextureCreateFlags parameters. + * + * @sa ktxTexture_CreateFrom*() + */ +public typealias ktxTextureCreateFlags = ktx_uint32_t; + +/*===========================================================* +* 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. + */ + + public typealias ktx_off_t = c_ulonglong; + + + +[CRepr] public struct ktxMem; + + +[AllowDuplicates] public enum streamType : c_int { Estreamtypefile = 1, Estreamtypememory = 2, Estreamtypecustom = 3, } + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +[CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e ktxStream_read(ktxStream* str, void* dst, ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +[CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e ktxStream_skip(ktxStream* str, ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream writing function + */ +[CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e ktxStream_write(ktxStream* str, void* src, ktx_size_t size, ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +[CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e ktxStream_getpos(ktxStream* str, ktx_off_t* offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +[CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e ktxStream_setpos(ktxStream* str, ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +[CallingConvention(KTX_APIENTRYP)] public function ktx_error_code_e ktxStream_getsize(ktxStream* str, ktx_size_t* size); + +/** + * @~English + * @brief Destruct a stream + */ +[CallingConvention(KTX_APIENTRYP)] public function void ktxStream_destruct(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +[CRepr] public struct ktxStream +{ + public ktxStream_read read; /*!< pointer to function for reading bytes. */ + public ktxStream_skip skip; /*!< pointer to function for skipping bytes. */ + public ktxStream_write write; /*!< pointer to function for writing bytes. */ + public ktxStream_getpos getpos; /*!< pointer to function for getting current position in stream. */ + public ktxStream_setpos setpos; /*!< pointer to function for setting current position in stream. */ + public ktxStream_getsize getsize; /*!< pointer to function for querying size. */ + public ktxStream_destruct destruct; /*!< destruct the stream. */ + + public streamType type; + + /**< a stdio FILE pointer for a ktxFileStream. */ + /**< a pointer to a ktxMem struct for a ktxMemStream. */ + + + /**< pointer to the data. */ + /**< pointer to a memory allocator. */ + /**< size of the data. */ + /**< pointer to a struct for custom streams. */ + public [CRepr, Union] public struct { + public FILE* file; /**< a stdio FILE pointer for a ktxFileStream. */ + public ktxMem* mem; /**< a pointer to a ktxMem struct for a ktxMemStream. */ + + + /**< pointer to the data. */ + /**< pointer to a memory allocator. */ + /**< size of the data. */ + public [CRepr] public struct + { + public void* address; /**< pointer to the data. */ + public void* allocatorAddress; /**< pointer to a memory allocator. */ + public ktx_size_t size; + } custom_ptr; + } data; /**< size of the data. */ + /**< pointer to a struct for custom streams. */ + /**< pointer to the stream data. */ + public ktx_off_t readpos; /**< used by FileStream for stdin. */ + public ktx_bool_t closeOnDestruct; /**< Close FILE* or dispose of memory on destruct. */ +} + +/* + * See the implementation files for the full documentation of the following + * functions. + */ + +/** + * @~English + * @brief typedef of function pointer returned by GLGetProcAddress functions. + */ +[CallingConvention(KTX_APIENTRYP)] public function void PFNVOIDFUNCTION(); +/** + * @~English + * @brief typedef of pointer to function for retrieving OpenGL function pointers. + */ +[CallingConvention(KTX_APIENTRYP)] public function PFNVOIDFUNCTION PFNGLGETPROCADDRESS(c_char*); +static +{ +/* + * Load pointers for the OpenGL functions needed by ktxTexture_GLUpload. + */ + +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxLoadOpenGL(PFNGLGETPROCADDRESS pfnGLGetProcAddress); +} + +extension ktxTexture +{ +/* + * These four create a ktxTexture1 or ktxTexture2 according to the data + * header, and return a pointer to the base ktxTexture class. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_CreateFromStdioStream")] public static extern ktx_error_code_e CreateFromStdioStream(FILE* stdioStream, ktxTextureCreateFlags createFlags, ktxTexture** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_CreateFromNamedFile")] public static extern ktx_error_code_e CreateFromNamedFile(c_char* filename, ktxTextureCreateFlags createFlags, ktxTexture** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_CreateFromMemory")] public static extern ktx_error_code_e CreateFromMemory(ktx_uint8_t* bytes, ktx_size_t size, ktxTextureCreateFlags createFlags, ktxTexture** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_CreateFromStream")] public static extern ktx_error_code_e CreateFromStream(ktxStream* stream, ktxTextureCreateFlags createFlags, ktxTexture** newTex); + +/* + * Returns a pointer to the image data of a ktxTexture object. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_GetData")] public static extern ktx_uint8_t* GetData(ktxTexture* This); + +/* + * Returns the pitch of a row of an image at the specified level. + * Similar to the rowPitch in a VkSubResourceLayout. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_GetRowPitch")] public static extern ktx_uint32_t GetRowPitch(ktxTexture* This, ktx_uint32_t level); + + /* + * Return the element size of the texture's images. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_GetElementSize")] public static extern ktx_uint32_t GetElementSize(ktxTexture* This); + +/* + * Returns the size of all the image data of a ktxTexture object in bytes. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_GetDataSize")] public static extern ktx_size_t GetDataSize(ktxTexture* This); + +/* Uploads a texture to OpenGL {,ES}. */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_GLUpload")] public static extern ktx_error_code_e GLUpload(ktxTexture* This, GLuint* pTexture, GLenum* pTarget, GLenum* pGlerror); + +/* + * Iterate over the levels or faces in a ktxTexture object. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_IterateLevelFaces")] public static extern ktx_error_code_e IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, void* userdata); +} + +extension ktxTexture1 +{ +/* + * Create a new ktxTexture1. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_Create")] public static extern ktx_error_code_e Create(ktxTextureCreateInfo* createInfo, ktxTextureCreateStorageEnum storageAllocation, ktxTexture1** newTex); + +/* + * These four create a ktxTexture1 provided the data is in KTX format. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_CreateFromStdioStream")] public static extern ktx_error_code_e CreateFromStdioStream(FILE* stdioStream, ktxTextureCreateFlags createFlags, ktxTexture1** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_CreateFromNamedFile")] public static extern ktx_error_code_e CreateFromNamedFile(c_char* filename, ktxTextureCreateFlags createFlags, ktxTexture1** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_CreateFromMemory")] public static extern ktx_error_code_e CreateFromMemory(ktx_uint8_t* bytes, ktx_size_t size, ktxTextureCreateFlags createFlags, ktxTexture1** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_CreateFromStream")] public static extern ktx_error_code_e CreateFromStream(ktxStream* stream, ktxTextureCreateFlags createFlags, ktxTexture1** newTex); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_Destroy")] public static extern void Destroy(ktxTexture1* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_IsHDR")] public static extern ktx_bool_t IsHDR(ktxTexture1* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_NeedsTranscoding")] public static extern ktx_bool_t NeedsTranscoding(ktxTexture1* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_IsTranscodable")] public static extern ktx_bool_t IsTranscodable(ktxTexture1* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_LoadImageData")] public static extern ktx_error_code_e LoadImageData(ktxTexture1* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize); + +/* + * These four write a ktxTexture1 object to a KTX v1 file. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteToStdioStream")] public static extern ktx_error_code_e WriteToStdioStream(ktxTexture1* This, FILE* dstsstr); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteToNamedFile")] public static extern ktx_error_code_e WriteToNamedFile(ktxTexture1* This, c_char* dstname); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteToMemory")] public static extern ktx_error_code_e WriteToMemory(ktxTexture1* This, ktx_uint8_t** bytes, ktx_size_t* size); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteToStream")] public static extern ktx_error_code_e WriteToStream(ktxTexture1* This, ktxStream* dststr); + +/* + * These four write a ktxTexture1 object to a KTX v2 file. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteKTX2ToStdioStream")] public static extern ktx_error_code_e WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteKTX2ToNamedFile")] public static extern ktx_error_code_e WriteKTX2ToNamedFile(ktxTexture1* This, c_char* dstname); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteKTX2ToMemory")] public static extern ktx_error_code_e WriteKTX2ToMemory(ktxTexture1* This, ktx_uint8_t** bytes, ktx_size_t* size); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_WriteKTX2ToStream")] public static extern ktx_error_code_e WriteKTX2ToStream(ktxTexture1* This, ktxStream* dststr); +} + +extension ktxTexture2 +{ +/* + * Create a new ktxTexture2. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_Create")] public static extern ktx_error_code_e Create(ktxTextureCreateInfo* createInfo, ktxTextureCreateStorageEnum storageAllocation, ktxTexture2** newTex); + +/* + * Create a new ktxTexture2 as a copy of an existing texture. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CreateCopy")] public static extern ktx_error_code_e CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); + + /* + * These four create a ktxTexture2 provided the data is in KTX2 format. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CreateFromStdioStream")] public static extern ktx_error_code_e CreateFromStdioStream(FILE* stdioStream, ktxTextureCreateFlags createFlags, ktxTexture2** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CreateFromNamedFile")] public static extern ktx_error_code_e CreateFromNamedFile(c_char* filename, ktxTextureCreateFlags createFlags, ktxTexture2** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CreateFromMemory")] public static extern ktx_error_code_e CreateFromMemory(ktx_uint8_t* bytes, ktx_size_t size, ktxTextureCreateFlags createFlags, ktxTexture2** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CreateFromStream")] public static extern ktx_error_code_e CreateFromStream(ktxStream* stream, ktxTextureCreateFlags createFlags, ktxTexture2** newTex); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_Destroy")] public static extern void Destroy(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CompressBasis")] public static extern ktx_error_code_e CompressBasis(ktxTexture2* This, ktx_uint32_t quality); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_DeflateZstd")] public static extern ktx_error_code_e DeflateZstd(ktxTexture2* This, ktx_uint32_t level); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_DeflateZLIB")] public static extern ktx_error_code_e DeflateZLIB(ktxTexture2* This, ktx_uint32_t level); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetComponentInfo")] public static extern void GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents, ktx_uint32_t* componentByteLength); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetImageOffset")] public static extern ktx_error_code_e GetImageOffset(ktxTexture2* This, ktx_uint32_t level, ktx_uint32_t layer, ktx_uint32_t faceSlice, ktx_size_t* pOffset); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetNumComponents")] public static extern ktx_uint32_t GetNumComponents(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetTransferFunction_e")] public static extern khr_df_transfer_e GetTransferFunction_e(ktxTexture2* This); +/* For backward compatibility. */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetOETF_e")] public static extern khr_df_transfer_e GetOETF_e(ktxTexture2* This); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetOETF")] public static extern ktx_uint32_t GetOETF(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetColorModel_e")] public static extern khr_df_model_e GetColorModel_e(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetPremultipliedAlpha")] public static extern ktx_bool_t GetPremultipliedAlpha(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetPrimaries_e")] public static extern khr_df_primaries_e GetPrimaries_e(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_IsHDR")] public static extern ktx_bool_t IsHDR(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_NeedsTranscoding")] public static extern ktx_bool_t NeedsTranscoding(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_IsTranscodable")] public static extern ktx_bool_t IsTranscodable(ktxTexture2* This); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_SetTransferFunction")] public static extern ktx_error_code_e SetTransferFunction(ktxTexture2* This, khr_df_transfer_e tf); +/* For backward compatibility. */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_SetOETF")] public static extern ktx_error_code_e SetOETF(ktxTexture2* This, khr_df_transfer_e oetf); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_SetPrimaries")] public static extern ktx_error_code_e SetPrimaries(ktxTexture2* This, khr_df_primaries_e primaries); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_LoadImageData")] public static extern ktx_error_code_e LoadImageData(ktxTexture2* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize); +/* + * For rare testing scenarios. Use ktxTexture2_LoadImageData. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_LoadDeflatedImageData")] public static extern ktx_error_code_e LoadDeflatedImageData(ktxTexture2* This, ktx_uint8_t* pBuffer, ktx_size_t bufSize); + +/* + * These four write a ktxTexture2 object to a KTX v2 file. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_WriteToStdioStream")] public static extern ktx_error_code_e WriteToStdioStream(ktxTexture2* This, FILE* dstsstr); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_WriteToNamedFile")] public static extern ktx_error_code_e WriteToNamedFile(ktxTexture2* This, c_char* dstname); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_WriteToMemory")] public static extern ktx_error_code_e WriteToMemory(ktxTexture2* This, ktx_uint8_t** bytes, ktx_size_t* size); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_WriteToStream")] public static extern ktx_error_code_e WriteToStream(ktxTexture2* This, ktxStream* dststr); +} + +/** + * @~English + * @brief Flags specifying UASTC encoding options. + */ +[AllowDuplicates] public enum ktx_pack_uastc_flag_bits_e : c_int { + LevelFastest = 0U, + /*!< Fastest compression. 43.45dB. */ + LevelFaster = 1U, + /*!< Faster compression. 46.49dB. */ + LevelDefault = 2U, + /*!< Default compression. 47.47dB. */ + LevelSlower = 3U, + /*!< Slower compression. 48.01dB. */ + LevelVeryslow = 4U, + /*!< Very slow compression. 48.24dB. */ + MaxLevel = LevelVeryslow, + /*!< Maximum supported quality level. */ + LevelMask = 0xF, + /*!< Mask to extract the level from the other bits. */ + FavorUastcError = 8U, + /*!< Optimize for lowest UASTC error. */ + FavorBc7Error = 16U, + /*!< Optimize for lowest BC7 error. */ + Etc1FasterHints = 64U, + /*!< Optimize for faster transcoding to ETC1. */ + Etc1FastestHints = 128U, + /*!< Optimize for fastest transcoding to ETC1. */ + Etc1DisableFlipAndIndividual = 256U, + /*!< Not documented in BasisU code. */ +} +public typealias ktx_pack_uastc_flags = ktx_uint32_t; + +/** + * @~English + * @brief Options specifiying ASTC encoding quality levels. + */ +[AllowDuplicates] public enum ktx_pack_astc_quality_levels_e : c_int { + Fastest = 0U, + /*!< Fastest compression. */ + Fast = 10U, + /*!< Fast compression. */ + Medium = 60U, + /*!< Medium compression. */ + Thorough = 98U, + /*!< Slower compression. */ + Exhaustive = 100U, + /*!< Very slow compression. */ + Max = Exhaustive, + /*!< Maximum supported quality level. */ +} +public typealias ktx_pack_astc_quality_levels = ktx_uint32_t; + +/** + * @~English + * @brief Options specifiying ASTC encoding block dimensions + */ +[AllowDuplicates] public enum ktx_pack_astc_block_dimension_e : c_int { + // 2D formats + _4x4, //: 8.00 bpp + _5x4, //: 6.40 bpp + _5x5, //: 5.12 bpp + _6x5, //: 4.27 bpp + _6x6, //: 3.56 bpp + _8x5, //: 3.20 bpp + _8x6, //: 2.67 bpp + _10x5, //: 2.56 bpp + _10x6, //: 2.13 bpp + _8x8, //: 2.00 bpp + _10x8, //: 1.60 bpp + _10x10, //: 1.28 bpp + _12x10, //: 1.07 bpp + _12x12, //: 0.89 bpp + // 3D formats + _3x3x3, //: 4.74 bpp + _4x3x3, //: 3.56 bpp + _4x4x3, //: 2.67 bpp + _4x4x4, //: 2.00 bpp + _5x4x4, //: 1.60 bpp + _5x5x4, //: 1.28 bpp + _5x5x5, //: 1.02 bpp + _6x5x5, //: 0.85 bpp + _6x6x5, //: 0.71 bpp + _6x6x6, //: 0.59 bpp + Max = _6x6x6, + /*!< Maximum supported blocks. */ +} + +/** + * @~English + * @brief Options specifying ASTC encoder mode. + */ +[AllowDuplicates] public enum ktx_pack_astc_encoder_mode_e : c_int { + Default, + /*!< Selects LDR mode if component size is <= 8-bit, HDR otherwise. */ + Ldr, + /*!< Always encode in low dynamic range mode. */ + Hdr, + /*!< Always encode in high dynamic range mode. */ + Max = Hdr, + /*!< Indicates the maximum permissible value. */ +} + +static +{ +[CLink] public static extern 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. + */ +[CRepr] public struct ktxAstcParams { + public ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + + public ktx_bool_t verbose; + /*!< If true, prints Astc encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + + public ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. + */ + + /* astcenc params */ + public ktx_uint32_t blockDimension; + /*!< Combinations of block dimensions that astcenc supports + i.e. 6x6, 8x8, 6x5 etc + */ + + public ktx_uint32_t mode; + /*!< Can be {ldr/hdr} from astcenc + */ + + public ktx_pack_astc_quality_levels qualityLevel; + /*!< astcenc supports -fastest, -fast, -medium, -thorough, -exhaustive + */ + + public 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. + */ + + public 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. + */ + + public c_char[4] inputSwizzle; + /*!< A swizzle to provide as input to astcenc. It must match the regular + expression /^[rgba01]{4}$/. + */ +} + + +extension ktxTexture2 +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CompressAstcEx")] public static extern ktx_error_code_e CompressAstcEx(ktxTexture2* This, ktxAstcParams* @params); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CompressAstc")] public static extern ktx_error_code_e CompressAstc(ktxTexture2* This, ktx_uint32_t quality); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_DecodeAstc")] public static extern ktx_error_code_e DecodeAstc(ktxTexture2* This); +} + +/** + * @~English + * @brief Options specifiying basis codec. + */ +[AllowDuplicates] public enum ktx_basis_codec_e : c_int { + None = 0U, + /*!< NONE. */ + Etc1s = 1U, + /*!< BasisLZ. */ + UastcLdr4x4 = 2U, + /*!< UASTC. */ + UastcHdr4x4 = 3U, + /*!< UASTC_HDR_4x4. */ + UastcHdr6x6Intermediate = 4U, + /*!< UASTC_HDR_6x6i. */ +} +public typealias ktx_basis_codec = ktx_uint32_t; + +/** + * @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.etc1sCompressionLevel = KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL; + * @endcode + * + * @e etc1sCompressionLevel has to be explicitly set because 0 is a valid + * @e etc1sCompressionLevel 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. + */ +[CRepr] public struct ktxBasisParams { + public ktx_uint32_t structSize; + /*!< Size of this struct. Used so library can tell which version + of struct is being passed. + */ + public ktx_basis_codec codec; + /*!< Flag to indicate which codec to use. 0 - NONE, 1 - ETC1S, 2 - UASTC_LDR, 3 - UASTC_HDR4x4, 4 - UASTC_HDR6x6i. */ + public ktx_bool_t verbose; + /*!< If true, prints Basis Universal encoder operation details to + @c stdout. Not recommended for GUI apps. + */ + public ktx_bool_t noSSE; + /*!< True to forbid use of the SSE instruction set. Ignored if CPU + does not support SSE. */ + public ktx_uint32_t threadCount; + /*!< Number of threads used for compression. Default is 1. */ + + /* ETC1S params */ + + public ktx_uint32_t etc1sCompressionLevel; + /*!< ETC1S compression effort level. Range is [0,6]. Higher values are much + slower, but give slightly higher quality. Higher levels are intended + for video. This parameter controls numerous internal encoding speed vs. + compression efficiency/performance tradeoffs. Note this is NOT the same + as the ETC1S quality level, and most users shouldn't change this. + 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 + */ + public 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. + */ + public 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. + */ + public 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. + */ + public 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. + */ + public 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. + */ + public c_char[4] inputSwizzle; + /*!< 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. Usable with both ETC1S and UASTC. + */ + public 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. + */ + public 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. + */ + public 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. Usable + for both ETC1S and UASTC. + */ + public ktx_bool_t noEndpointRDO; + /*!< Disable endpoint rate distortion optimizations. Slightly faster, + less noisy output, but lower quality per output bit. Default is + KTX_FALSE. + */ + public 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 */ + + public 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 + */ + public ktx_bool_t uastcRDO; + /*!< Enable Rate Distortion Optimization (RDO) post-processing. + */ + public 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. + */ + public ktx_uint32_t uastcRDODictSize; + /*!< UASTC RDO dictionary size in bytes. Default is 4096. Lower + values=faster, but give less compression. Range is [64,65536]. + */ + public 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. + */ + public 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. + */ + public ktx_bool_t uastcRDODontFavorSimplerModes; + /*!< Do not favor simpler UASTC modes in RDO mode. + */ + public ktx_bool_t uastcRDONoMultithreading; + /*!< Disable RDO multithreading (slightly higher compression, + deterministic). + */ + public ktx_uint32_t uastcHDRQuality; + /*!< UASTC HDR 4x4: Sets the UASTC HDR 4x4 compressor's level. + Valid range is [0,4] - higher=slower but higher quality. Default=1. + Level 0=fastest/lowest quality, 3=highest practical setting, 4=exhaustive + */ + public ktx_bool_t uastcHDRUberMode; + /*!< UASTC HDR 4x4: Allow the UASTC HDR 4x4 encoder to try varying the CEM 11 + selectors more for slightly higher quality (slower). This may negatively impact BC6H quality, however. + */ + public ktx_bool_t uastcHDRUltraQuant; + /*!< UASTC HDR 4x4: Try to find better quantized CEM 7/11 endpoint values (slower) + */ + public ktx_bool_t uastcHDRFavorAstc; + /*!< UASTC HDR 4x4: By default the UASTC HDR 4x4 encoder tries to strike a balance + or even slightly favor BC6H quality. If this option is specified, ASTC HDR 4x4 quality is favored instead. + */ + public float uastcHDRLambda; + /*!< UASTC HDR 6x6i specific option: Enables rate distortion optimization (RDO). + The higher this value, the lower the quality, but the smaller the file size. Try 100-20000, or higher values + on some images. + */ + public ktx_uint32_t uastcHDRLevel; + /*!< UASTC HDR 6x6i specific option: Controls the 6x6 HDR intermediate mode encoder + performance vs. max quality tradeoff. X may range from [0,12]. Default level is 2. + */ + +} + + +extension ktxTexture2 +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_CompressBasisEx")] public static extern ktx_error_code_e 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. + */ +[AllowDuplicates] public enum ktx_transcode_fmt_e : c_int { + // Compressed formats + + // ETC1-2 + TtfEtc1Rgb = 0, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + TtfEtc2Rgba = 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) + TtfBc1Rgb = 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. */ + TtfBc3Rgba = 3, + /*!< Opaque+alpha. BC4 block with alpha followed by a BC1 block. The + alpha channel will be opaque for textures without an alpha + channel. */ + TtfBc4R = 4, + /*!< One BC4 block. R = opaque.g or alpha.g, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + TtfBc5Rg = 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. */ + TtfBc7Rgba = 6, + /*!< RGB or RGBA mode 5 for ETC1S, modes 1, 2, 3, 4, 5, 6, 7 for + UASTC. */ + + // PVRTC1 4bpp (mobile, PowerVR devices) + TtfPvrtc14Rgb = 8, + /*!< Opaque only. Returns RGB or alpha data, if + KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS flag is + specified. */ + TtfPvrtc14Rgba = 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) + TtfAstc4x4Rgba = 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. + + TtfPvrtc24Rgb = 18, + /*!< Opaque-only. Almost BC1 quality, much faster to transcode + and supports arbitrary texture dimensions (unlike + PVRTC1 RGB). */ + TtfPvrtc24Rgba = 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. */ + + TtfEtc2EacR11 = 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. */ + TtfEtc2EacRg11 = 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 + TtfRgba32 = 13, + /*!< 32bpp RGBA image stored in raster (not block) order in + memory, R is first byte, A is last byte. */ + TtfRgb565 = 14, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 11. */ + TtfBgr565 = 15, + /*!< 16bpp RGB image stored in raster (not block) order in memory, + R at bit position 0. */ + TtfRgba4444 = 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. + TtfEtc = 22, + /*!< Automatically selects @c KTX_TTF_ETC1_RGB or + @c KTX_TTF_ETC2_RGBA according to presence of alpha. */ + TtfBc1Or3 = 23, + /*!< Automatically selects @c KTX_TTF_BC1_RGB or + @c KTX_TTF_BC3_RGBA according to presence of alpha. */ + + /* 48bpp RGB half (16-bits/component, 3 components) */ + TtfRgbaHalf = 25, + + TtfAstcHdr4x4Rgba = 29, // HDR, RGBA (currently UASTC HDR 4x4 encoders are only RGB), unsigned + TtfAstcHdr6x6Rgba = 30, // HDR, RGBA (currently UASTC HDR 4x4 encoders are only RGB), unsigned + TtfBc6hu = 31, // HDR, RGB only, unsigned + + TtfNoselection = 0x7fffffff, + + // Old enums for compatibility with code compiled against previous + // versions of libktx. + TfEtc1 = TtfEtc1Rgb, + //!< @deprecated Use #KTX_TTF_ETC1_RGB. + TfEtc2 = TtfEtc, + //!< @deprecated Use #KTX_TTF_ETC. + TfBc1 = TtfBc1Rgb, + //!< @deprecated Use #KTX_TTF_BC1_RGB. + TfBc3 = TtfBc3Rgba, + //!< @deprecated Use #KTX_TTF_BC3_RGBA. + TfBc4 = TtfBc4R, + //!< @deprecated Use #KTX_TTF_BC4_R. + TfBc5 = TtfBc5Rg, + //!< @deprecated Use #KTX_TTF_BC5_RG. + TtfBc7M6Rgb = TtfBc7Rgba, + //!< @deprecated Use #KTX_TTF_BC7_RGBA. + TtfBc7M5Rgba = TtfBc7Rgba, + //!< @deprecated Use #KTX_TTF_BC7_RGBA. + TfBc7M6OpaqueOnly = TtfBc7Rgba, + //!< @deprecated Use #KTX_TTF_BC7_RGBA + TfPvrtc14OpaqueOnly = TtfPvrtc14Rgb, + //!< @deprecated Use #KTX_TTF_PVRTC1_4_RGB. +} + +/** + * @~English + * @brief Flags guiding transcoding of Basis Universal compressed textures. + */ +[AllowDuplicates] public enum ktx_transcode_flag_bits_e : c_int { + TfPvrtcDecodeToNextPow2 = 2U, + /*!< 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. + */ + TfTranscodeAlphaDataToOpaqueFormats = 4U, + /*!< 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. + */ + TfHighQuality = 32U, + /*!< Request higher quality transcode of UASTC to BC1, BC3, ETC2_EAC_R11 and + ETC2_EAC_RG11. The flag is unused by other UASTC transcoders. + */ +} +public typealias ktx_transcode_flags = ktx_uint32_t; + + +extension ktxTexture2 +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_TranscodeBasis")] public static extern ktx_error_code_e TranscodeBasis(ktxTexture2* This, ktx_transcode_fmt_e fmt, ktx_transcode_flags transcodeFlags); +} + +static +{ +/* + * Returns a string corresponding to a KTX error code. + */ + +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern c_char* ktxErrorString(ktx_error_code_e error); + +/* + * Returns a string corresponding to a supercompression scheme. + */ + +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern c_char* ktxSupercompressionSchemeString(ktxSupercmpScheme scheme); + +/* + * Returns a string corresponding to a transcode target format. + */ + +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern c_char* ktxTranscodeFormatString(ktx_transcode_fmt_e format); +} + +extension ktxHashList +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Create")] public static extern ktx_error_code_e Create(ktxHashList** ppHl); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_CreateCopy")] public static extern ktx_error_code_e CreateCopy(ktxHashList** ppHl, ktxHashList orig); +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Construct")] public static extern void Construct(ktxHashList* pHl); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_ConstructCopy")] public static extern void ConstructCopy(ktxHashList* pHl, ktxHashList orig); +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Destroy")] public static extern void Destroy(ktxHashList* head); +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Destruct")] public static extern void Destruct(ktxHashList* head); + +/* + * Adds a key-value pair to a hash list. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_AddKVPair")] public static extern ktx_error_code_e AddKVPair(ktxHashList* pHead, c_char* key, c_uint valueLen, void* value); + +/* + * Deletes a ktxHashListEntry from a ktxHashList. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_DeleteEntry")] public static extern ktx_error_code_e DeleteEntry(ktxHashList* pHead, ktxHashListEntry* pEntry); + +/* + * Finds the entry for a key in a ktxHashList and deletes it. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_DeleteKVPair")] public static extern ktx_error_code_e DeleteKVPair(ktxHashList* pHead, c_char* key); + +/* + * Looks up a key and returns the ktxHashListEntry. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_FindEntry")] public static extern ktx_error_code_e FindEntry(ktxHashList* pHead, c_char* key, ktxHashListEntry** ppEntry); + +/* + * Looks up a key and returns the value. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_FindValue")] public static extern ktx_error_code_e FindValue(ktxHashList* pHead, c_char* key, c_uint* pValueLen, void** pValue); + +/* + * Return the next entry in a ktxHashList. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Next")] public static extern ktxHashListEntry* Next(ktxHashListEntry* entry); + +/* + * Sorts a ktxHashList into order of the key codepoints. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Sort")] public static extern ktx_error_code_e Sort(ktxHashList* pHead); + +/* + * Serializes a ktxHashList to a block of memory suitable for + * writing to a KTX file. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Serialize")] public static extern ktx_error_code_e Serialize(ktxHashList* pHead, c_uint* kvdLen, c_uchar** kvd); + +/* + * Creates a hash table from the serialized data read from a + * a KTX file. + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashList_Deserialize")] public static extern ktx_error_code_e Deserialize(ktxHashList* pHead, c_uint kvdLen, void* kvd); +} + +extension ktxHashListEntry +{ +/* + * Get the key from a ktxHashListEntry + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashListEntry_GetKey")] public static extern ktx_error_code_e GetKey(ktxHashListEntry* This, c_uint* pKeyLen, c_char** ppKey); + +/* + * Get the value from a ktxHashListEntry + */ + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxHashListEntry_GetValue")] public static extern ktx_error_code_e GetValue(ktxHashListEntry* This, c_uint* pValueLen, void** ppValue); +} + +static +{ +/*===========================================================* + * Utilities for printing info about a KTX file. * + *===========================================================*/ + +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintInfoForStdioStream(FILE* stdioStream); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintInfoForNamedFile(c_char* filename); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintInfoForMemory(ktx_uint8_t* bytes, ktx_size_t size); + +/*===========================================================* + * Utilities for printing info about a KTX v1 file. * + *===========================================================*/ + + [CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX1InfoTextForStream(ktxStream* stream); + +/*===========================================================* + * Utilities for printing info about a KTX v2 file. * + *===========================================================*/ + +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoTextForMemory(ktx_uint8_t* bytes, ktx_size_t size); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoTextForNamedFile(c_char* filename); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoTextForStdioStream(FILE* stdioStream); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoTextForStream(ktxStream* stream); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoJSONForMemory(ktx_uint8_t* bytes, ktx_size_t size, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoJSONForNamedFile(c_char* filename, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoJSONForStdioStream(FILE* stdioStream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +[CallingConvention(KTX_APIENTRYP)] [CLink] public static extern ktx_error_code_e ktxPrintKTX2InfoJSONForStream(ktxStream* stream, ktx_uint32_t base_indent, ktx_uint32_t indent_width, bool minified); +} + +/** +@~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. + +*/ + +/* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ \ No newline at end of file diff --git a/src/KTXVulkan.bf b/src/KTXVulkan.bf new file mode 100644 index 0000000..b7e650a --- /dev/null +++ b/src/KTXVulkan.bf @@ -0,0 +1,281 @@ +// This file was generated by Cpp2Beef + +using System; +using System.Interop; + +namespace KTX; + +static +{ +/* -*- tab-width: 4; -*- */ +/* vi: set sw=2 ts=4 expandtab: */ + + + +} + + + +/* + * Copyright 2017-2020 The Khronos Group, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @internal + * @file + * @~English + * + * @brief Declares the public functions and structures of the + * KTX Vulkan texture loading API. + * + * A separate header file is used to avoid extra dependencies for those not + * using Vulkan. The nature of the Vulkan API, rampant structures and enums, + * means that vulkan.h must be included @e before including this file. The + * alternative is duplicating unattractively large parts of it. + * + * @author Mark Callow, github.com/MarkCallow + */ + + + + +/* Avoid Vulkan include file */ + + + + + + + + + + + + + + + + + + + + + + +/** + * @struct ktxVulkanFunctions + * @~English + * @brief Struct for applications to pass Vulkan function pointers to the + * ktxTexture_VkUpload functions via a ktxVulkanDeviceInfo struct. + * + * @c vkGetInstanceProcAddr and @c vkGetDeviceProcAddr should be set, others + * are optional. + */ +[CRepr] public struct ktxVulkanFunctions { + // These are functions pointers we need to perform our vulkan duties. + public PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; + public PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr; + + // These we optionally specify + public PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers; + public PFN_vkAllocateMemory vkAllocateMemory; + public PFN_vkBeginCommandBuffer vkBeginCommandBuffer; + public PFN_vkBindBufferMemory vkBindBufferMemory; + public PFN_vkBindImageMemory vkBindImageMemory; + public PFN_vkCmdBlitImage vkCmdBlitImage; + public PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage; + public PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier; + public PFN_vkCreateImage vkCreateImage; + public PFN_vkDestroyImage vkDestroyImage; + public PFN_vkCreateBuffer vkCreateBuffer; + public PFN_vkDestroyBuffer vkDestroyBuffer; + public PFN_vkCreateFence vkCreateFence; + public PFN_vkDestroyFence vkDestroyFence; + public PFN_vkEndCommandBuffer vkEndCommandBuffer; + public PFN_vkFreeCommandBuffers vkFreeCommandBuffers; + public PFN_vkFreeMemory vkFreeMemory; + public PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements; + public PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements; + public PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout; + public PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties; + public PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties; + public PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties; + public PFN_vkMapMemory vkMapMemory; + public PFN_vkQueueSubmit vkQueueSubmit; + public PFN_vkQueueWaitIdle vkQueueWaitIdle; + public PFN_vkUnmapMemory vkUnmapMemory; + public PFN_vkWaitForFences vkWaitForFences; +} + +/** + * @class ktxVulkanTexture + * @~English + * @brief Struct for returning information about the Vulkan texture image + * created by the ktxTexture_VkUpload* functions. + * + * Creation of these objects is internal to the upload functions. + */ +[CRepr] public struct ktxVulkanTexture +{ + public PFN_vkDestroyImage vkDestroyImage; /*!< Pointer to vkDestroyImage function */ + public PFN_vkFreeMemory vkFreeMemory; /*!< Pointer to vkFreeMemory function */ + + public VkImage image; /*!< Handle to the Vulkan image created by the loader. */ + public VkFormat imageFormat; /*!< Format of the image data. */ + public VkImageLayout imageLayout; /*!< Layout of the created image. Has the same + value as @p layout parameter passed to the + loader. */ + public VkDeviceMemory deviceMemory; /*!< The memory (sub)allocation for the + image on the Vulkan device. Will not be + used with suballocators.*/ + public VkImageViewType viewType; /*!< ViewType corresponding to @p image. Reflects + the dimensionality, cubeness and arrayness + of the image. */ + public uint32 width; /*!< The width of the image. */ + public uint32 height; /*!< The height of the image. */ + public uint32 depth; /*!< The depth of the image. */ + public uint32 levelCount; /*!< The number of MIP levels in the image. */ + public uint32 layerCount; /*!< The number of array layers in the image. */ + public uint64 allocationId; /*!< An id referencing suballocation(s). */ +} + +[CallingConvention(KTX_APIENTRYP)] public function uint64 ktxVulkanTexture_subAllocatorAllocMemFuncPtr(VkMemoryAllocateInfo* allocInfo, VkMemoryRequirements* memReq, uint64* pageCount); +[CallingConvention(KTX_APIENTRYP)] public function VkResult ktxVulkanTexture_subAllocatorBindBufferFuncPtr(VkBuffer buffer, uint64 allocId); +[CallingConvention(KTX_APIENTRYP)] public function VkResult ktxVulkanTexture_subAllocatorBindImageFuncPtr(VkImage image, uint64 allocId); +[CallingConvention(KTX_APIENTRYP)] public function VkResult ktxVulkanTexture_subAllocatorMemoryMapFuncPtr(uint64 allocId, uint64 pageNumber, VkDeviceSize* mapLength, void** dataPtr); +[CallingConvention(KTX_APIENTRYP)] public function void ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr(uint64 allocId, uint64 pageNumber); +[CallingConvention(KTX_APIENTRYP)] public function void ktxVulkanTexture_subAllocatorFreeMemFuncPtr(uint64 allocId); +/** + * @class ktxVulkanTexture_subAllocatorCallbacks + * @~English + * @brief Struct that contains all callbacks necessary for suballocation. + * + * These pointers must all be provided for upload or destroy to occur using suballocator callbacks. + */ +[CRepr] public struct ktxVulkanTexture_subAllocatorCallbacks { + public ktxVulkanTexture_subAllocatorAllocMemFuncPtr allocMemFuncPtr; /*!< Pointer to the memory procurement function. Can suballocate one or more pages. */ + public ktxVulkanTexture_subAllocatorBindBufferFuncPtr bindBufferFuncPtr; /*!< Pointer to bind-buffer-to-suballocation(s) function. */ + public ktxVulkanTexture_subAllocatorBindImageFuncPtr bindImageFuncPtr; /*!< Pointer to bind-image-to-suballocation(s) function. */ + public ktxVulkanTexture_subAllocatorMemoryMapFuncPtr memoryMapFuncPtr; /*!< Pointer to function for mapping the memory of a specific page. */ + public ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr memoryUnmapFuncPtr; /*!< Pointer to function for unmapping the memory of a specific page. */ + public ktxVulkanTexture_subAllocatorFreeMemFuncPtr freeMemFuncPtr; /*!< Pointer to the free procurement function. */ +} + + +extension ktxVulkanTexture +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanTexture_Destruct_WithSuballocator")] public static extern ktx_error_code_e Destruct_WithSuballocator(ktxVulkanTexture* This, VkDevice device, VkAllocationCallbacks* pAllocator, ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanTexture_Destruct")] public static extern void Destruct(ktxVulkanTexture* This, VkDevice device, VkAllocationCallbacks* pAllocator); +} + +/** + * @class ktxVulkanDeviceInfo + * @~English + * @brief Struct for passing information about the Vulkan device on which + * to create images to the texture image loading functions. + * + * Avoids passing a large number of parameters to each loading function. + * Use of ktxVulkanDeviceInfo_create() or ktxVulkanDeviceInfo_construct() to + * populate this structure is highly recommended. + * + * @code + ktxVulkanDeviceInfo vdi; + ktxVulkanTexture texture; + + vdi = ktxVulkanDeviceInfo_create(physicalDevice, + device, + queue, + cmdPool, + &allocator); + ktxLoadVkTextureN("texture_1.ktx", vdi, &texture, NULL, NULL); + // ... + ktxLoadVkTextureN("texture_n.ktx", vdi, &texture, NULL, NULL); + ktxVulkanDeviceInfo_destroy(vdi); + * @endcode + */ +[CRepr] public struct ktxVulkanDeviceInfo { + public VkInstance instance; /*!< Instance used to communicate with vulkan. */ + public VkPhysicalDevice physicalDevice; /*!< Handle of the physical device. */ + public VkDevice device; /*!< Handle of the logical device. */ + public VkQueue queue; /*!< Handle to the queue to which to submit commands. */ + public VkCommandBuffer cmdBuffer; /*!< Handle of the cmdBuffer to use. */ + /** Handle of the command pool from which to allocate the command buffer. */ + public VkCommandPool cmdPool; + /** Pointer to the allocator to use for the command buffer and created + * images. + */ + public VkAllocationCallbacks* pAllocator; + /** Memory properties of the Vulkan physical device. */ + public VkPhysicalDeviceMemoryProperties deviceMemoryProperties; + + /** The functions needed to operate functions */ + public ktxVulkanFunctions vkFuncs; +} + + + +extension ktxVulkanDeviceInfo +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanDeviceInfo_CreateEx")] public static extern ktxVulkanDeviceInfo* CreateEx(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, VkQueue queue, VkCommandPool cmdPool, VkAllocationCallbacks* pAllocator, ktxVulkanFunctions* pFunctions); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanDeviceInfo_Create")] public static extern ktxVulkanDeviceInfo* Create(VkPhysicalDevice physicalDevice, VkDevice device, VkQueue queue, VkCommandPool cmdPool, VkAllocationCallbacks* pAllocator); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanDeviceInfo_Construct")] public static extern ktx_error_code_e Construct(ktxVulkanDeviceInfo* This, VkPhysicalDevice physicalDevice, VkDevice device, VkQueue queue, VkCommandPool cmdPool, VkAllocationCallbacks* pAllocator); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanDeviceInfo_ConstructEx")] public static extern ktx_error_code_e ConstructEx(ktxVulkanDeviceInfo* This, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, VkQueue queue, VkCommandPool cmdPool, VkAllocationCallbacks* pAllocator, ktxVulkanFunctions* pFunctions); + + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanDeviceInfo_Destruct")] public static extern void Destruct(ktxVulkanDeviceInfo* This); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxVulkanDeviceInfo_Destroy")] public static extern void Destroy(ktxVulkanDeviceInfo* This); +} + +extension ktxTexture +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_VkUploadEx_WithSuballocator")] public static extern ktx_error_code_e VkUploadEx_WithSuballocator(ktxTexture* This, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture, VkImageTiling tiling, VkImageUsageFlags usageFlags, VkImageLayout finalLayout, ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_VkUploadEx")] public static extern ktx_error_code_e VkUploadEx(ktxTexture* This, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture, VkImageTiling tiling, VkImageUsageFlags usageFlags, VkImageLayout finalLayout); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_VkUpload")] public static extern ktx_error_code_e VkUpload(ktxTexture* texture, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture); +} + +extension ktxTexture1 +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_VkUploadEx_WithSuballocator")] public static extern ktx_error_code_e VkUploadEx_WithSuballocator(ktxTexture1* This, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture, VkImageTiling tiling, VkImageUsageFlags usageFlags, VkImageLayout finalLayout, ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_VkUploadEx")] public static extern ktx_error_code_e VkUploadEx(ktxTexture1* This, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture, VkImageTiling tiling, VkImageUsageFlags usageFlags, VkImageLayout finalLayout); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_VkUpload")] public static extern ktx_error_code_e VkUpload(ktxTexture1* texture, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture); +} + +extension ktxTexture2 +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_VkUploadEx_WithSuballocator")] public static extern ktx_error_code_e VkUploadEx_WithSuballocator(ktxTexture2* This, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture, VkImageTiling tiling, VkImageUsageFlags usageFlags, VkImageLayout finalLayout, ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_VkUploadEx")] public static extern ktx_error_code_e VkUploadEx(ktxTexture2* This, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture, VkImageTiling tiling, VkImageUsageFlags usageFlags, VkImageLayout finalLayout); + +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_VkUpload")] public static extern ktx_error_code_e VkUpload(ktxTexture2* texture, ktxVulkanDeviceInfo* vdi, ktxVulkanTexture* vkTexture); +} + +extension ktxTexture +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture_GetVkFormat")] public static extern VkFormat GetVkFormat(ktxTexture* This); +} + +extension ktxTexture1 +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture1_GetVkFormat")] public static extern VkFormat GetVkFormat(ktxTexture1* This); +} + +extension ktxTexture2 +{ +[CallingConvention(KTX_APIENTRYP)] [LinkName("ktxTexture2_GetVkFormat")] public static extern VkFormat GetVkFormat(ktxTexture2* This); +} + +/* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ \ No newline at end of file diff --git a/src/Library.bf b/src/Library.bf new file mode 100644 index 0000000..700377f --- /dev/null +++ b/src/Library.bf @@ -0,0 +1,61 @@ +using System; +using CxxBuildTool; + +namespace KTX; + +static +{ + public const CallingConventionAttribute.Kind KTX_APIENTRYP = +#if BF_PLATFORM_WINDOWS + .Stdcall; +#else + .Cdecl; +#endif + + struct FILE; + struct ktxTexture_vvtbl; + struct ktxTexture_protected; + struct ktxTexture1_private; + struct ktxTexture2_private; + + [OnCompile(.TypeDone)] + private static void Build() + { + if (!Compiler.IsBuilding) return; + CxxBuildTool.Ninja( + Compiler.ProjectDir + "/KTX-Software/lib/src", + Compiler.BuildDir + "/" + Compiler.ProjectName, + "libktx", + "-DKHRONOS_STATIC -I\"" + + Compiler.ProjectDir + "/KTX-Software/lib/include\" -I\"" + + Compiler.ProjectDir + "/KTX-Software/utils\" -I\"" + + Compiler.ProjectDir + "/KTX-Software/other_include\" -I\"" + + Compiler.ProjectDir + "/KTX-Software/external\" -I\"" + + Compiler.ProjectDir + "/KTX-Software/external/basis_universal\" -I\"" + + Compiler.ProjectDir + "/KTX-Software/external/basis_universal/zstd\" -I\"" + + Compiler.ProjectDir + "/KTX-Software/external/dfdutils\"", + + "astc_codec.cpp", + "basis_transcode.cpp", + "miniz_wrapper.cpp", + "checkheader.c", + "etcunpack.cxx", + "filestream.c", + "glformat_str.c", + "hashlist.c", + "info.c", + "memstream.c", + "strings.c", + "swap.c", + "texture.c", + "texture2.c", + "vkformat_check.c", + "vkformat_check_variant.c", + "vkformat_str.c", + "vkformat_typesize.c" + ); + } +} + +[CRepr] struct ktxHashList { ktxHashListEntry* head; } +[CRepr] struct ktxHashListEntry;