impl std::error::Error for LoadError {}
-pub struct Texture {
+pub struct Image {
width: usize,
height: usize,
components: usize,
buffer: NonNull<u8>,
}
-impl Texture {
- pub fn from_buffer(buffer: &[u8]) -> Result<Texture, LoadError> {
+impl Image {
+ pub fn from_buffer(buffer: &[u8]) -> Result<Image, LoadError> {
let mut x = 0;
let mut y = 0;
let mut components = 0;
let components = components as usize;
let len = x * y * components;
- Ok(Texture {
+ Ok(Image {
width: x,
height: y,
components,
}
}
-impl Drop for Texture {
+impl Drop for Image {
fn drop(&mut self) {
// Safety: Always allocated by `stbi_load_xxx` functions.
unsafe { stbi_image_free(self.buffer.as_ptr() as *mut _) }
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {}
+}
use std::{path::Path, time::Instant};
use narcissus_app::{create_app, Event, Key, WindowDesc};
-use narcissus_core::{cstr, default, obj, rand::Pcg64, Texture};
+use narcissus_core::{cstr, default, obj, rand::Pcg64};
use narcissus_gpu::{
create_device, Access, Bind, BindGroupLayoutDesc, BindGroupLayoutEntryDesc, BindingType,
Buffer, BufferDesc, BufferImageCopy, BufferUsageFlags, ClearValue, CompareOp, CullingMode,
SamplerAddressMode, SamplerDesc, SamplerFilter, Scissor, ShaderDesc, ShaderStageFlags, StoreOp,
ThreadToken, Topology, TypedBind, Viewport,
};
+use narcissus_image as image;
use narcissus_maths::{
sin_cos_pi_f32, vec2, vec3, vec4, Affine3, Deg, HalfTurn, Mat3, Mat4, Point3, Vec2, Vec3,
};
(vertices, indices)
}
-fn load_texture<P: AsRef<Path>>(path: P) -> Texture {
+fn load_image<P: AsRef<Path>>(path: P) -> image::Image {
let start = std::time::Instant::now();
let path = path.as_ref();
let texture =
- Texture::from_buffer(std::fs::read(path).expect("failed to read file").as_slice())
+ image::Image::from_buffer(std::fs::read(path).expect("failed to read file").as_slice())
.expect("failed to load image");
println!(
"loading image {path:?} took {:?}",
stencil_front: default(),
});
- let blåhaj_image = load_texture("narcissus/data/blåhaj.png");
+ let blåhaj_image = load_image("narcissus/data/blåhaj.png");
let (blåhaj_vertices, blåhaj_indices) = load_obj("narcissus/data/blåhaj.obj");
let blåhaj_vertex_buffer = create_buffer_with_data(