@@ -36,11 +36,8 @@ const CAM_POSITION: cgmath::Point3<f32> = cgmath::Point3 {
3636} ;
3737
3838fn print_matrix ( m : [ [ f32 ; 4 ] ; 4 ] ) {
39- for i in 0 ..4 {
40- debug ! (
41- "{:.3}\t {:.3}\t {:.3}\t {:.3}" ,
42- m[ i] [ 0 ] , m[ i] [ 1 ] , m[ i] [ 2 ] , m[ i] [ 3 ]
43- ) ;
39+ for row in & m {
40+ debug ! ( "{:.3}\t {:.3}\t {:.3}\t {:.3}" , row[ 0 ] , row[ 1 ] , row[ 2 ] , row[ 3 ] ) ;
4441 }
4542 debug ! ( "" ) ;
4643}
@@ -175,7 +172,7 @@ where
175172 let pixel_shader_src = include_str ! ( "shaders/model.frag" ) ;
176173
177174 // TODO: Cache program binary
178- let program = glium:: Program :: from_source ( display, & vertex_shader_src, & pixel_shader_src, None ) ;
175+ let program = glium:: Program :: from_source ( display, vertex_shader_src, pixel_shader_src, None ) ;
179176 let program = match program {
180177 Ok ( p) => p,
181178 Err ( glium:: CompilationError ( err, _) ) => {
@@ -246,7 +243,7 @@ where
246243 target
247244 . draw (
248245 ( & vertex_buf, & normal_buf) ,
249- & indices,
246+ indices,
250247 & program,
251248 & uniforms,
252249 & params,
@@ -261,9 +258,8 @@ where
261258 let pixels: glium:: texture:: RawImage2d < u8 > = texture. read ( ) ;
262259 let img = image:: ImageBuffer :: from_raw ( config. width , config. height , pixels. data . into_owned ( ) )
263260 . unwrap ( ) ;
264- let img = image:: DynamicImage :: ImageRgba8 ( img) . flipv ( ) ;
265261
266- img
262+ image :: DynamicImage :: ImageRgba8 ( img) . flipv ( )
267263}
268264
269265pub fn render_to_window ( config : Config ) -> Result < ( ) , Box < dyn Error > > {
@@ -292,13 +288,14 @@ pub fn render_to_window(config: Config) -> Result<(), Box<dyn Error>> {
292288 . unwrap ( ) ;
293289
294290 match ev {
295- glutin:: event:: Event :: WindowEvent { event, .. }
296- if event == glutin:: event:: WindowEvent :: CloseRequested =>
297- {
291+ glutin:: event:: Event :: WindowEvent {
292+ event : glutin:: event:: WindowEvent :: CloseRequested ,
293+ ..
294+ } => {
298295 * control_flow = ControlFlow :: Exit ;
299296 return ;
300297 }
301- glutin:: event:: Event :: NewEvents ( cause ) if cause == glutin:: event:: StartCause :: Init => {
298+ glutin:: event:: Event :: NewEvents ( glutin:: event:: StartCause :: Init ) => {
302299 render_pipeline ( & display, & config, & mesh, & mut framebuffer, & texture) ;
303300 }
304301 _ => ( ) ,
@@ -330,13 +327,11 @@ pub fn render_to_image(config: &Config) -> Result<image::DynamicImage, Box<dyn E
330327 // =========================
331328 let mesh = Mesh :: load ( & config. stl_filename , config. recalc_normals ) ?;
332329
333- let img: image:: DynamicImage ;
334-
335330 // Create GL context
336331 // =================
337332 // 1. If not visible create a headless context.
338333 // 2. If headless context creation fails, create a normal context with a hidden window.
339- match create_headless_display ( & config) {
334+ let img : image :: DynamicImage = match create_headless_display ( config) {
340335 Ok ( display) => {
341336 let texture = glium:: Texture2d :: empty ( & display, config. width , config. height ) . unwrap ( ) ;
342337 let depthtexture =
@@ -348,14 +343,14 @@ pub fn render_to_image(config: &Config) -> Result<image::DynamicImage, Box<dyn E
348343 & depthtexture,
349344 )
350345 . unwrap ( ) ;
351- img = render_pipeline ( & display, & config, & mesh, & mut framebuffer, & texture) ;
346+ render_pipeline ( & display, config, & mesh, & mut framebuffer, & texture)
352347 }
353348 Err ( e) => {
354349 warn ! (
355350 "Unable to create headless GL context. Trying hidden window instead. Reason: {:?}" ,
356351 e
357352 ) ;
358- let ( display, _) = create_normal_display ( & config) ?;
353+ let ( display, _) = create_normal_display ( config) ?;
359354 let texture = glium:: Texture2d :: empty ( & display, config. width , config. height ) . unwrap ( ) ;
360355 let depthtexture =
361356 glium:: texture:: DepthTexture2d :: empty ( & display, config. width , config. height )
@@ -366,15 +361,15 @@ pub fn render_to_image(config: &Config) -> Result<image::DynamicImage, Box<dyn E
366361 & depthtexture,
367362 )
368363 . unwrap ( ) ;
369- img = render_pipeline ( & display, & config, & mesh, & mut framebuffer, & texture) ;
364+ render_pipeline ( & display, config, & mesh, & mut framebuffer, & texture)
370365 }
371366 } ;
372367
373368 Ok ( img)
374369}
375370
376371pub fn render_to_file ( config : & Config ) -> Result < ( ) , Box < dyn Error > > {
377- let img = render_to_image ( & config) ?;
372+ let img = render_to_image ( config) ?;
378373
379374 // Choose output
380375 // Write to stdout if user did not specify a file
@@ -438,6 +433,11 @@ pub fn render_to_file(config: &Config) -> Result<(), Box<dyn Error>> {
438433///
439434/// render_to_buffer(buf_ptr, width, height, stl_filename_c);
440435/// ```
436+ ///
437+ /// # Safety
438+ ///
439+ /// * `buf_ptr` _must_ point to a valid initialized buffer, at least `width * height * 4` bytes long.
440+ /// * `stl_filename_c` must point to a valid null-terminated string.
441441#[ no_mangle]
442442pub unsafe extern "C" fn render_to_buffer (
443443 buf_ptr : * mut u8 ,
@@ -476,8 +476,8 @@ pub unsafe extern "C" fn render_to_buffer(
476476 // Setup configuration for the renderer
477477 let config = Config {
478478 stl_filename : stl_filename_str. to_string ( ) ,
479- width : width ,
480- height : height ,
479+ width,
480+ height,
481481 ..Default :: default ( )
482482 } ;
483483
0 commit comments