gpu_formats/texture_optimize

  Source   Edit

This module takes textures decoded from JPEG, PNG, etc. and encodes them in compressed GPU formats like BCn and ASTC. In order to use it:

  • Configure Engine.CacheSettings
  • Add one or both of these defines: myouUseBC7Encoder, myouUseAstcEncoder

The resulting cache can be used in builds without encoders.

Types

BlockSize = enum
  Bs4x4 = 68,               ## 8.00 BPP
  Bs5x4 = 84,               ## 6.40 BPP
  Bs5x5 = 85,               ## 5.12 BPP
  Bs6x5 = 101,              ## 4.27 BPP
  Bs6x6 = 102,              ## 3.56 BPP
  Bs8x5 = 133,              ## 3.20 BPP
  Bs8x6 = 134,              ## 2.67 BPP
  Bs8x8 = 136,              ## 2.00 BPP (below 10x6)
  Bs10x5 = 165,             ## 2.56 BPP
  Bs10x6 = 166,             ## 2.13 BPP
  Bs10x8 = 168,             ## 1.60 BPP
  Bs10x10 = 170,            ## 1.28 BPP
  Bs12x10 = 202,            ## 1.07 BPP
  Bs12x12 = 204              ## 0.89 BPP
  Source   Edit
CacheSettings = object
  compress_textures*: bool   ## Whether to compress textures on load
                             ## when not loaded from cache cache
  use_cache*: bool           ## Whether to try to load from cache
  save_cache*: bool          ## Whether to save compressed textures
  cache_dir*: string         ## Cache directory
  quality_speed*: EncodingSpeed ## Whether you need them fast or good
  bc_format_for_RGB*: RgbBcFmt ## Which BCn to use for RGB images.
                               ## BC7 is the best but BC1 is half the
                               ## size and encodes very fast
  astc_block_size*: BlockSize ## Defines quality and size of ASTC.
                              ## 4x4 is the best but biggest,
                              ## 6x6 is a good balance,
                              ## 8x8 is bad but very small.
  astc_block_1ch*: BlockSize ## Block size for 1 channel textures,
                             ## since less data has to be encoded
  astc_block_2ch*: BlockSize ## Block size for 2 channel textures
  compress_all_formats*: bool ## Encode textures for all platforms
  cache_dir_bc*: string      ## Cache directory for writing bc
  cache_dir_astc*: string    ## Cache directory for writing astc
  
  Source   Edit
EncodingSpeed = enum
  UltraFast, VeryFast, Fast, Basic, Slow, VerySlow, Slowest
  Source   Edit
RgbBcFmt = enum
  BC1 = 1,                  ## 4 BPP (0.5 bytes per pixel), very small but low quality.
  BC7 = 7                    ## 8 BPP (1 byte per pixel), larger but very good quality.
  Source   Edit

Procs

proc loadOptimized(tex: Texture; slices: seq[SliceMem[byte]];
                   callback_uncompressed: CallbackUncompressed = nil;
                   callback_compressed: CallbackCompressed = nil; flip = true;
                   min_channels = 0) {....gcsafe, raises: [Exception], tags: [
    ReadDirEffect, ReadIOEffect, WriteIOEffect, RootEffect].}
  Source   Edit
proc loadOptimizedThreaded(tex: Texture; slices: seq[SliceMem[byte]];
                           callback_uncompressed: CallbackUncompressed = nil;
                           callback_compressed: CallbackCompressed = nil;
                           flip = true; min_channels = 0) {....raises: [], tags: [].}
  Source   Edit
proc terminateTextureWorkerThreads() {....raises: [], tags: [].}
  Source   Edit
proc updateTextureWorkerThreads() {....raises: [ValueError, Exception],
                                    tags: [RootEffect].}
  Source   Edit