File tree Expand file tree Collapse file tree 3 files changed +64
-2
lines changed Expand file tree Collapse file tree 3 files changed +64
-2
lines changed Original file line number Diff line number Diff line change
1
+ #![ cfg_attr(
2
+ all( target_os = "windows" , not( debug_assertions) ) ,
3
+ windows_subsystem = "windows"
4
+ ) ]
1
5
use state:: State ;
2
6
use std:: sync:: { Arc , Mutex } ;
3
7
use std:: time:: Instant ;
@@ -105,6 +109,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
105
109
WindowEvent :: RedrawRequested => {
106
110
frames += 1 ;
107
111
112
+ #[ cfg( debug_assertions) ]
108
113
if fps_counter. elapsed ( ) . as_secs ( ) >= 3 {
109
114
fps_counter = Instant :: now ( ) ;
110
115
println ! ( "\x1b [32mFPS - {}\x1b [0m" , frames / 3 ) ;
Original file line number Diff line number Diff line change @@ -114,6 +114,62 @@ impl Texture {
114
114
}
115
115
}
116
116
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
+ }
117
173
pub fn from_path (
118
174
path : & str ,
119
175
name : String ,
Original file line number Diff line number Diff line change @@ -135,8 +135,9 @@ impl Pipeline for MainPipeline {
135
135
usage : wgpu:: BufferUsages :: UNIFORM ,
136
136
} ) ;
137
137
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,
140
141
"tex_atlas" . to_string ( ) ,
141
142
& state. device ,
142
143
& state. queue ,
You can’t perform that action at this time.
0 commit comments