remove TextureType

This commit is contained in:
Carter Anderson 2020-06-05 19:38:03 -07:00
parent 9a51b3e0fd
commit ffc4246a74
4 changed files with 12 additions and 32 deletions

View file

@ -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<u8>, usize, usize),
Png(String), // TODO: please rethink this
}
pub struct Texture {
pub data: Vec<u8>,
@ -22,28 +18,14 @@ pub struct Texture {
}
impl Texture {
pub fn new(data: Vec<u8>, size: Vec2) -> Self {
Self { data, size }
}
pub fn aspect(&self) -> f32 {
self.size.y() / self.size.x()
}
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 texture_resource_system(
mut state: ResMut<TextureResourceSystemState>,
render_resources: Res<RenderResources>,

View file

@ -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"

View file

@ -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::<Vec<u8>>(),
width,
height,
))
Vec2::new(width as f32, height as f32)
)
}
}

View file

@ -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},