/ktx-async

KTX Texture File Asynchronous Loader in Rust

Primary LanguageRustMIT LicenseMIT

ktx-async

crate-badge docs-badge ci-status deps-status

Asynchronous reader for KTX texture format

Features:

  • Asynchronous IO API
  • Works with tokio
  • Supports KTX 1.1

TODO:

  • Custom buffer allocation (ex: OpenGL Pixel Buffer Object)
  • Add std::io::Read support (?)
  • KTX 2.0 (?) spec

Example:

use ktx_async as ktx;
use tokio::fs::File;
use tokio::stream::StreamExt as _;

// In async code

// Open AsyncRead
let file = File::open("example.ktx").await.unwrap();

// Start decoding KTX
let decoder = ktx::Decoder::new(file);
let (info, mut stream) = decoder.read_async().await.unwrap();

// create and bind a texture object ...

// Get all the frames from the stream
while let Some((frame, buf)) = stream.next().await.map(|r| r.unwrap()) {
    unsafe {
        gl::TexImage2D(gl::TEXTURE_2D,
            frame.level as GLint,
            info.gl_internal_format as GLint,
            frame.pixel_width as GLsizei,
            frame.pixel_height as GLsizei,
            /*border*/ 0,
            info.gl_format as GLenum,
            info.gl_type as GLenum,
            buf.as_ptr() as *const GLvoid);
    }
}

Development

Build:

cargo build

Run Test:

cargo test

Run Example:

cargo run --example basic

License

This project is licensed under the MIT License

References