{.deadCodeElim: on.}

import streams
, glformat

const
  KTX_GL_UNPACK_ALIGNMENT* = 4

type

 BlockCount* = ref object
  x*,y*,z*: uint32 

 KtxTextureCreateFlagBits* = enum
  TextureCreateNoFlags = 0 
  TextureCreateLoadImageData = 1 # Load the images from the KTX source
  TextureCreateRawKVData = 2 # Load the raw key-value data instead of creating a @c ktxHashList from it
  TextureCreateSkipKVData = 4 # Skip any key-value data. This overrides the RAW_KVDATA_BIT

 KtxExtraInfo* = ref object
  compressed*: uint8
  generateMipmaps*: uint8
  textureDimension*: uint16

 KtxHeader* = ref object
  identifier*: array[12,uint8]
  endianness*: uint32
  glType*: uint32
  glTypeSize*: uint32
  glFormat*: uint32
  glInternalformat*: uint32
  glBaseInternalformat*: uint32
  pixelWidth*: uint32
  pixelHeight*: uint32
  pixelDepth*: uint32
  numberOfArrayElements*: uint32
  numberOfFaces*: uint32
  numberOfMipmapLevels*: uint32
  bytesOfKeyValueData*: uint32
  
 KtxTextureObj = object of RootObj
  glFormat*: cuint # Format of the texture data, e.g., GL_RGB. 
  glInternalformat*: cuint # Internal format of the texture data,  e.g., GL_RGB8. 
  glBaseInternalformat*: cuint # Base format of the texture data, e.g., GL_RGB. 
  glType*: cuint # Type of the texture data, e.g, GL_UNSIGNED_BYTE.
  isArray*: bool # true if the texture is an array texture, i.e, a GL_TEXTURE_*_ARRAY target is to be used. 
  isCubemap*: bool # true if the texture is a cubemap or  cubemap array. 
  isCompressed*: bool # true if @c glInternalFormat is that of a compressed texture. 
  generateMipmaps*: bool # true if mipmaps should be generated for the texture by ktxTexture_GLUpload() or ktx_Texture_VkUpload(). 
  baseWidth*: uint  # Width of the base level of the texture. 
  baseHeight*: uint # Height of the base level of the texture. 
  baseDepth*: uint  # Depth of the base level of the texture. 
  numDimensions*: uint # Number of dimensions in the texture: 1, 2 or 3. 
  numLevels*: uint # Number of mip levels in the texture. Should be 1, if @c generateMipmaps is true. Can be less than a full pyramid but always starts at the base level. 
  numLayers*: uint # Number of array layers in the texture.   
  numFaces*: uint # Number of faces, 6 for cube maps, 1 otherw ise.
  createFlags*: uint32
  extraInfo*: KtxExtraInfo
  formatInfo*: GlFormatSize  # Info about the image data format. */
  # The following are needed because image data reading can be delayed.
  glTypeSize*: uint32   # Size of the image data type in bytes. */
  stream*: StringStream          # Stream connected to KTX source. */
  needSwap*: bool    # If KTX_TRUE, image data needs byte swapping. */
  # kvDataHead: ktxHashList # hash list of metadata.  
  kvDataLen: uint # Length of the metadata, if it has been extracted in its raw form, otherwise 0. 
  # kvData: pointer  # Pointer to the metadata, if it has been extracted   in its raw form, otherwise NULL. 
  dataSize*: csize_t # Length of the image data in bytes. 
  pData*: pointer  # Pointer to the image data. 
 KtxTexture* = ref object of KtxTextureObj