From 9259003354c0fd5504d7d0c4f04b7b4b2a8b43b5 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Sat, 3 Jul 2021 13:36:37 +0200 Subject: [PATCH] Add generated textures to repo for now --- .gitignore | 11 ++++++++++- assets/font/ascii_shadow.png | 3 +++ assets/grass_block_side_plains.png | 3 +++ assets/grass_block_top_plains.png | 3 +++ src/text_renderer.rs | 8 ++++++-- src/texture.rs | 11 +++++++---- 6 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 assets/font/ascii_shadow.png create mode 100644 assets/grass_block_side_plains.png create mode 100644 assets/grass_block_top_plains.png diff --git a/.gitignore b/.gitignore index 2d52597..8c27cd6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,16 @@ /flamegraph.svg /perf.data* /chunks/ -/assets + +/assets/* +!/assets/grass_block_*.png +!/assets/font + +/assets/font/* +!/assets/font/ascii_shadow.png + +/release/ + profile.txt callgrind.out.* diff --git a/assets/font/ascii_shadow.png b/assets/font/ascii_shadow.png new file mode 100644 index 0000000..0ca6141 --- /dev/null +++ b/assets/font/ascii_shadow.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7957e6805ef93ac66a1903964cbd5c065e6756789ef56f9f5e91c1cd092ef42 +size 16444 diff --git a/assets/grass_block_side_plains.png b/assets/grass_block_side_plains.png new file mode 100644 index 0000000..099b4ca --- /dev/null +++ b/assets/grass_block_side_plains.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0016fc8494d81346d8b94b86c4fdc01606ffee25129c35a5fa04df792db63d1e +size 2578 diff --git a/assets/grass_block_top_plains.png b/assets/grass_block_top_plains.png new file mode 100644 index 0000000..568f03c --- /dev/null +++ b/assets/grass_block_top_plains.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d162e8b3229feb7306b5419e65e3da60a7ee771d23fd6b1fde7a9d7279ca8148 +size 2901 diff --git a/src/text_renderer.rs b/src/text_renderer.rs index 434aa4d..970da6c 100644 --- a/src/text_renderer.rs +++ b/src/text_renderer.rs @@ -1,5 +1,7 @@ use std::convert::TryInto; +use anyhow::Context; + use crate::{ geometry::Geometry, geometry_buffers::GeometryBuffers, render_context::RenderContext, texture::Texture, vertex::HudVertex, @@ -27,8 +29,10 @@ pub struct TextRenderer { impl TextRenderer { pub fn new(render_context: &RenderContext) -> anyhow::Result { - let bytes = std::fs::read("assets/font/ascii_shadow.png")?; - let texture = Texture::from_bytes(render_context, &bytes, "font")?; + let bytes = std::fs::read("assets/font/ascii_shadow.png") + .context("Failed to load assets/font/ascii_shadow.png")?; + let texture = Texture::from_bytes(render_context, &bytes, "font") + .context("Failed to decode assets/font/ascii_shadow.png")?; let sampler = render_context .device diff --git a/src/texture.rs b/src/texture.rs index 931a856..0ae57ee 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -1,5 +1,6 @@ use std::{num::NonZeroU32, ops::Range}; +use anyhow::Context; use cgmath::{Vector2, Zero}; use image::{EncodableLayout, ImageBuffer, Rgba}; use wgpu::Origin3d; @@ -317,8 +318,9 @@ impl TextureManager { } pub fn load(&mut self, render_context: &RenderContext, path: &str) -> anyhow::Result { - let bytes = std::fs::read(path)?; - let texture = Texture::from_bytes(render_context, &bytes, path)?; + let bytes = std::fs::read(path).context(format!("Failed to load {}", path))?; + let texture = Texture::from_bytes(render_context, &bytes, path) + .context(format!("Failed to decode {}", path))?; let id = self.textures.len(); self.textures.push(texture); @@ -333,8 +335,9 @@ impl TextureManager { path: &str, tile_size: Vector2, ) -> anyhow::Result> { - let bytes = std::fs::read(path)?; - let mut textures = Texture::from_bytes_atlas(render_context, &bytes, tile_size, path)?; + let bytes = std::fs::read(path).context(format!("Failed to load {}", path))?; + let mut textures = Texture::from_bytes_atlas(render_context, &bytes, tile_size, path) + .context(format!("Failed to decode {}", path))?; let start = self.textures.len(); self.textures.append(&mut textures);