2 releases

0.1.1 Dec 20, 2019
0.1.0 Dec 19, 2019

#827 in Graphics APIs

MIT license

22KB
246 lines

ktx-async

crate-badge docs-badge ci-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

Dependencies

~7–13MB
~157K SLoC