Skip to content

Commit cecc122

Browse files
committed
hide terminal on windows release mode
1 parent 1930fae commit cecc122

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#![cfg_attr(
2+
all(target_os = "windows", not(debug_assertions)),
3+
windows_subsystem = "windows"
4+
)]
15
use state::State;
26
use std::sync::{Arc, Mutex};
37
use std::time::Instant;
@@ -105,6 +109,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
105109
WindowEvent::RedrawRequested => {
106110
frames += 1;
107111

112+
#[cfg(debug_assertions)]
108113
if fps_counter.elapsed().as_secs() >= 3 {
109114
fps_counter = Instant::now();
110115
println!("\x1b[32mFPS - {}\x1b[0m", frames / 3);

src/material.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,62 @@ impl Texture {
114114
}
115115
}
116116

117+
pub fn from_bytes(
118+
bytes: &[u8],
119+
name: String,
120+
device: &wgpu::Device,
121+
queue: &wgpu::Queue,
122+
) -> Result<Self, Box<dyn std::error::Error>> {
123+
let image = image::load_from_memory(bytes)?;
124+
let dimensions = image.dimensions();
125+
let rgba = image.as_rgba8().unwrap();
126+
127+
let size = wgpu::Extent3d {
128+
width: dimensions.0,
129+
height: dimensions.1,
130+
depth_or_array_layers: 1,
131+
};
132+
133+
let texture = device.create_texture(&wgpu::TextureDescriptor {
134+
label: Some(&name.clone()),
135+
size,
136+
mip_level_count: 1,
137+
sample_count: 1,
138+
dimension: wgpu::TextureDimension::D2,
139+
view_formats: &[],
140+
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
141+
format: wgpu::TextureFormat::Rgba8UnormSrgb,
142+
});
143+
144+
queue.write_texture(
145+
wgpu::ImageCopyTexture {
146+
aspect: wgpu::TextureAspect::All,
147+
texture: &texture,
148+
mip_level: 0,
149+
origin: wgpu::Origin3d::ZERO,
150+
},
151+
&rgba,
152+
wgpu::ImageDataLayout {
153+
offset: 0,
154+
bytes_per_row: Some(4 * dimensions.0),
155+
rows_per_image: Some(dimensions.1),
156+
},
157+
size,
158+
);
159+
160+
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
161+
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
162+
..Default::default()
163+
});
164+
165+
Ok(Self {
166+
view,
167+
sampler,
168+
texture,
169+
name,
170+
data: None,
171+
})
172+
}
117173
pub fn from_path(
118174
path: &str,
119175
name: String,

src/pipelines/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ impl Pipeline for MainPipeline {
135135
usage: wgpu::BufferUsages::UNIFORM,
136136
});
137137

138-
let texture_atlas = Texture::from_path(
139-
"assets/tex_atlas.png",
138+
let image_bytes = include_bytes!("../../assets/tex_atlas.png");
139+
let texture_atlas = Texture::from_bytes(
140+
image_bytes,
140141
"tex_atlas".to_string(),
141142
&state.device,
142143
&state.queue,

0 commit comments

Comments
 (0)