mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
wip
This commit is contained in:
parent
f56c7a4b8f
commit
f8cd34443a
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -112,15 +112,6 @@ version = "1.0.75"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "approx"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayref"
|
name = "arrayref"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
|
@ -680,7 +671,6 @@ version = "0.24.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945"
|
checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"approx",
|
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ publish = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hashbrown = "0.14"
|
hashbrown = "0.14"
|
||||||
nohash-hasher = "0.2"
|
nohash-hasher = "0.2"
|
||||||
glam = { version = "0.24", features = ["approx"] }
|
glam = "0.24"
|
||||||
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf", optional = true }
|
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf", optional = true }
|
||||||
fontdue = { version = "0.7", optional = true }
|
fontdue = { version = "0.7", optional = true }
|
||||||
rect_packer = { version = "0.2.1", optional = true }
|
rect_packer = { version = "0.2.1", optional = true }
|
||||||
|
@ -21,7 +21,7 @@ winit = "0.29"
|
||||||
[features]
|
[features]
|
||||||
default = ["builtin_elements", "texture_manager", "text_rendering", "builtin_font", "backend_glium"]
|
default = ["builtin_elements", "texture_manager", "text_rendering", "builtin_font", "backend_glium"]
|
||||||
backend_glium = ["dep:glium"]
|
backend_glium = ["dep:glium"]
|
||||||
texture_manager = []
|
texture_manager = ["dep:rect_packer"]
|
||||||
text_rendering = ["dep:fontdue", "texture_manager"]
|
text_rendering = ["dep:fontdue", "texture_manager"]
|
||||||
builtin_font = ["text_rendering"]
|
builtin_font = ["text_rendering"]
|
||||||
builtin_elements = []
|
builtin_elements = []
|
||||||
|
|
|
@ -1,3 +1,57 @@
|
||||||
struct TextureSpace {
|
use rect_packer::{Packer, Config as PackerConfig};
|
||||||
|
use glam::{IVec2, ivec2};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct TextureAllocation {
|
||||||
|
// pub index: usize,
|
||||||
|
pub position: IVec2,
|
||||||
|
pub size: IVec2,
|
||||||
|
in_texture_size: IVec2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextureAllocation {
|
||||||
|
pub fn uv(&self) -> (f32, f32, f32, f32) {
|
||||||
|
let p0 = self.position.as_vec2() / self.in_texture_size.as_vec2();
|
||||||
|
let p1 = (self.position + self.size).as_vec2() / self.in_texture_size.as_vec2();
|
||||||
|
(p0.x, p0.y, p1.x, p1.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TextureSpace {
|
||||||
|
size: IVec2,
|
||||||
|
packer: Packer,
|
||||||
|
// allocations: Vec<TextureAllocation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextureSpace {
|
||||||
|
pub fn new(size: IVec2) -> Self {
|
||||||
|
Self {
|
||||||
|
size,
|
||||||
|
packer: Packer::new(PackerConfig {
|
||||||
|
width: size.x,
|
||||||
|
height: size.y,
|
||||||
|
border_padding: 1,
|
||||||
|
rectangle_padding: 1,
|
||||||
|
}),
|
||||||
|
// allocations: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(&self) -> IVec2 {
|
||||||
|
self.size
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn allocate(&mut self, size: IVec2) -> Option<TextureAllocation> {
|
||||||
|
let position = self.packer.pack(size.x, size.y, false)
|
||||||
|
.map(|rect| ivec2(rect.x, rect.y))?;
|
||||||
|
Some(TextureAllocation {
|
||||||
|
position,
|
||||||
|
size,
|
||||||
|
in_texture_size: self.size
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// pub fn lookup(&self, index: usize) -> Option<TextureAllocation> {
|
||||||
|
// self.allocations.get(index).copied()
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue