Skip to content

davll/ktx-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

KTX Texture File Asynchronous Loader in Rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages