remove TextureType
This commit is contained in:
parent
9a51b3e0fd
commit
ffc4246a74
@ -7,14 +7,10 @@ use bevy_app::{EventReader, Events};
|
|||||||
use bevy_asset::{AssetEvent, Assets, Handle};
|
use bevy_asset::{AssetEvent, Assets, Handle};
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use legion::prelude::*;
|
use legion::prelude::*;
|
||||||
use std::{collections::HashSet, fs::File};
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub const TEXTURE_ASSET_INDEX: usize = 0;
|
pub const TEXTURE_ASSET_INDEX: usize = 0;
|
||||||
pub const SAMPLER_ASSET_INDEX: usize = 1;
|
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 struct Texture {
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
@ -22,28 +18,14 @@ pub struct Texture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Texture {
|
impl Texture {
|
||||||
|
pub fn new(data: Vec<u8>, size: Vec2) -> Self {
|
||||||
|
Self { data, size }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn aspect(&self) -> f32 {
|
pub fn aspect(&self) -> f32 {
|
||||||
self.size.y() / self.size.x()
|
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(
|
pub fn texture_resource_system(
|
||||||
mut state: ResMut<TextureResourceSystemState>,
|
mut state: ResMut<TextureResourceSystemState>,
|
||||||
render_resources: Res<RenderResources>,
|
render_resources: Res<RenderResources>,
|
||||||
|
|||||||
@ -11,4 +11,5 @@ bevy_app = { path = "../bevy_app" }
|
|||||||
bevy_asset = { path = "../bevy_asset" }
|
bevy_asset = { path = "../bevy_asset" }
|
||||||
bevy_render = { path = "../bevy_render" }
|
bevy_render = { path = "../bevy_render" }
|
||||||
ab_glyph = "0.2.2"
|
ab_glyph = "0.2.2"
|
||||||
|
glam = "0.8.7"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
@ -1,8 +1,6 @@
|
|||||||
use ab_glyph::{FontVec, Glyph, InvalidFont, Point, PxScale, ScaleFont};
|
use ab_glyph::{FontVec, Glyph, InvalidFont, Point, PxScale, ScaleFont};
|
||||||
use bevy_render::{
|
use bevy_render::{texture::Texture, Color};
|
||||||
texture::{Texture, TextureType},
|
use glam::Vec2;
|
||||||
Color,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Font {
|
pub struct Font {
|
||||||
pub font: FontVec,
|
pub font: FontVec,
|
||||||
@ -64,7 +62,7 @@ impl Font {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::load(TextureType::Data(
|
Texture::new(
|
||||||
alpha
|
alpha
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| {
|
.map(|a| {
|
||||||
@ -77,9 +75,8 @@ impl Font {
|
|||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect::<Vec<u8>>(),
|
.collect::<Vec<u8>>(),
|
||||||
width,
|
Vec2::new(width as f32, height as f32)
|
||||||
height,
|
)
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ pub use crate::{
|
|||||||
RenderGraph,
|
RenderGraph,
|
||||||
},
|
},
|
||||||
shader::{Shader, ShaderDefSuffixProvider, ShaderStage, ShaderStages},
|
shader::{Shader, ShaderDefSuffixProvider, ShaderStage, ShaderStages},
|
||||||
texture::{Texture, TextureType},
|
texture::Texture,
|
||||||
Camera, Color, ColorSource, OrthographicProjection, PerspectiveProjection, Renderable,
|
Camera, Color, ColorSource, OrthographicProjection, PerspectiveProjection, Renderable,
|
||||||
},
|
},
|
||||||
scene::{Scene, SceneSpawner},
|
scene::{Scene, SceneSpawner},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user