diff --git a/crates/bevy_render/src/texture/texture.rs b/crates/bevy_render/src/texture/texture.rs index 86312fdf12..79d8499ec1 100644 --- a/crates/bevy_render/src/texture/texture.rs +++ b/crates/bevy_render/src/texture/texture.rs @@ -7,14 +7,10 @@ use bevy_app::{EventReader, Events}; use bevy_asset::{AssetEvent, Assets, Handle}; use glam::Vec2; use legion::prelude::*; -use std::{collections::HashSet, fs::File}; +use std::collections::HashSet; pub const TEXTURE_ASSET_INDEX: usize = 0; pub const SAMPLER_ASSET_INDEX: usize = 1; -pub enum TextureType { - Data(Vec, usize, usize), - Png(String), // TODO: please rethink this -} pub struct Texture { pub data: Vec, @@ -22,26 +18,12 @@ pub struct Texture { } impl Texture { - pub fn aspect(&self) -> f32 { - self.size.y() / self.size.x() + pub fn new(data: Vec, size: Vec2) -> Self { + Self { data, size } } - pub fn load(descriptor: TextureType) -> Self { - let (data, width, height) = match descriptor { - TextureType::Data(data, width, height) => (data.clone(), width, height), - TextureType::Png(path) => { - let decoder = png::Decoder::new(File::open(&path).unwrap()); - let (info, mut reader) = decoder.read_info().unwrap(); - let mut buf = vec![0; info.buffer_size()]; - reader.next_frame(&mut buf).unwrap(); - (buf, info.width as usize, info.height as usize) - } - }; - - Texture { - data, - size: Vec2::new(width as f32, height as f32), - } + pub fn aspect(&self) -> f32 { + self.size.y() / self.size.x() } pub fn texture_resource_system( diff --git a/crates/bevy_text/Cargo.toml b/crates/bevy_text/Cargo.toml index c6ddcb3ad5..8744186804 100644 --- a/crates/bevy_text/Cargo.toml +++ b/crates/bevy_text/Cargo.toml @@ -11,4 +11,5 @@ bevy_app = { path = "../bevy_app" } bevy_asset = { path = "../bevy_asset" } bevy_render = { path = "../bevy_render" } ab_glyph = "0.2.2" +glam = "0.8.7" anyhow = "1.0" \ No newline at end of file diff --git a/crates/bevy_text/src/font.rs b/crates/bevy_text/src/font.rs index 88aaf7646b..1b48d2bc89 100644 --- a/crates/bevy_text/src/font.rs +++ b/crates/bevy_text/src/font.rs @@ -1,8 +1,6 @@ use ab_glyph::{FontVec, Glyph, InvalidFont, Point, PxScale, ScaleFont}; -use bevy_render::{ - texture::{Texture, TextureType}, - Color, -}; +use bevy_render::{texture::Texture, Color}; +use glam::Vec2; pub struct Font { pub font: FontVec, @@ -64,7 +62,7 @@ impl Font { } } - Texture::load(TextureType::Data( + Texture::new( alpha .iter() .map(|a| { @@ -77,9 +75,8 @@ impl Font { }) .flatten() .collect::>(), - width, - height, - )) + Vec2::new(width as f32, height as f32) + ) } } diff --git a/src/prelude.rs b/src/prelude.rs index ad5b30a28e..435170f61b 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -27,7 +27,7 @@ pub use crate::{ RenderGraph, }, shader::{Shader, ShaderDefSuffixProvider, ShaderStage, ShaderStages}, - texture::{Texture, TextureType}, + texture::Texture, Camera, Color, ColorSource, OrthographicProjection, PerspectiveProjection, Renderable, }, scene::{Scene, SceneSpawner},