11#![ allow( dead_code) ]
22#![ allow( non_snake_case) ]
33#![ allow( non_camel_case_types) ]
4+ #![ allow( clippy:: too_many_arguments) ]
45
56use std:: cell:: { Ref , RefCell , RefMut } ;
67use std:: collections:: HashMap ;
@@ -9,8 +10,8 @@ use std::os::raw::c_void;
910use std:: ptr:: NonNull ;
1011use std:: rc:: Rc ;
1112
12- use canvas_core:: context_attributes:: { ColorSpace , ContextAttributes } ;
1313use canvas_core:: context_attributes:: PowerPreference ;
14+ use canvas_core:: context_attributes:: { ColorSpace , ContextAttributes } ;
1415
1516pub fn get_sdk_version ( ) -> i32 {
1617 18
@@ -143,19 +144,19 @@ impl WebGLState {
143144 //state.gl_context = GLContext::get_current();
144145 }
145146
146- fn get_state ( & self ) -> Ref < WebGLStateInner > {
147+ fn get_state ( & ' _ self ) -> Ref < ' _ , WebGLStateInner > {
147148 Ref :: map ( self . state . borrow ( ) , |v| v)
148149 }
149150
150- fn get_state_mut ( & self ) -> RefMut < WebGLStateInner > {
151+ fn get_state_mut ( & ' _ self ) -> RefMut < ' _ , WebGLStateInner > {
151152 RefMut :: map ( self . state . borrow_mut ( ) , |v| v)
152153 }
153154
154- fn get_attributes ( & self ) -> Ref < ContextAttributes > {
155+ fn get_attributes ( & ' _ self ) -> Ref < ' _ , ContextAttributes > {
155156 Ref :: map ( self . attributes . borrow ( ) , |v| v)
156157 }
157158
158- fn get_attributes_mut ( & self ) -> RefMut < ContextAttributes > {
159+ fn get_attributes_mut ( & ' _ self ) -> RefMut < ' _ , ContextAttributes > {
159160 RefMut :: map ( self . attributes . borrow_mut ( ) , |v| v)
160161 }
161162
@@ -220,7 +221,7 @@ impl WebGLState {
220221 false ,
221222 false ,
222223 version == WebGLVersion :: V1 ,
223- ColorSpace :: Srgb
224+ ColorSpace :: Srgb ,
224225 ) ) ) ,
225226 state : Rc :: new ( RefCell :: new ( WebGLStateInner {
226227 version,
@@ -285,7 +286,7 @@ impl WebGLState {
285286 xr_compatible,
286287 is_canvas,
287288 gl_legacy,
288- ColorSpace :: Srgb
289+ ColorSpace :: Srgb ,
289290 ) ) ) ,
290291 state : Rc :: new ( RefCell :: new ( WebGLStateInner {
291292 version,
@@ -509,28 +510,44 @@ impl WebGLState {
509510
510511 // MAX_COMBINED_TEXTURE_IMAGE_UNITS is available in GLES2 and GLES3
511512 let mut max_units: i32 = 0 ;
512- unsafe { gl_bindings:: GetIntegerv ( gl_bindings:: MAX_COMBINED_TEXTURE_IMAGE_UNITS , & mut max_units) }
513+ unsafe {
514+ gl_bindings:: GetIntegerv (
515+ gl_bindings:: MAX_COMBINED_TEXTURE_IMAGE_UNITS ,
516+ & mut max_units,
517+ )
518+ }
513519 self . state . borrow_mut ( ) . max_combined_texture_image_units = max_units;
514520
515521 if self . get_version ( ) == WebGLVersion :: V2 {
516522 let mut max_ub: i32 = 0 ;
517- unsafe { gl_bindings:: GetIntegerv ( gl_bindings:: MAX_UNIFORM_BUFFER_BINDINGS , & mut max_ub) }
523+ unsafe {
524+ gl_bindings:: GetIntegerv ( gl_bindings:: MAX_UNIFORM_BUFFER_BINDINGS , & mut max_ub)
525+ }
518526 self . state . borrow_mut ( ) . max_uniform_buffer_bindings = max_ub;
519527
520528 let mut max_vub: i32 = 0 ;
521- unsafe { gl_bindings:: GetIntegerv ( gl_bindings:: MAX_VERTEX_UNIFORM_BLOCKS , & mut max_vub) }
529+ unsafe {
530+ gl_bindings:: GetIntegerv ( gl_bindings:: MAX_VERTEX_UNIFORM_BLOCKS , & mut max_vub)
531+ }
522532 self . state . borrow_mut ( ) . max_vertex_uniform_blocks = max_vub;
523533
524534 let mut max_fub: i32 = 0 ;
525- unsafe { gl_bindings:: GetIntegerv ( gl_bindings:: MAX_FRAGMENT_UNIFORM_BLOCKS , & mut max_fub) }
535+ unsafe {
536+ gl_bindings:: GetIntegerv ( gl_bindings:: MAX_FRAGMENT_UNIFORM_BLOCKS , & mut max_fub)
537+ }
526538 self . state . borrow_mut ( ) . max_fragment_uniform_blocks = max_fub;
527539
528540 // Quick runtime UBO smoke-test: create a small UBO, bind base, check for GL errors
529541 let mut buf: u32 = 0 ;
530542 unsafe {
531543 gl_bindings:: GenBuffers ( 1 , & mut buf) ;
532544 gl_bindings:: BindBuffer ( gl_bindings:: UNIFORM_BUFFER , buf) ;
533- gl_bindings:: BufferData ( gl_bindings:: UNIFORM_BUFFER , 16 , std:: ptr:: null ( ) , gl_bindings:: DYNAMIC_DRAW ) ;
545+ gl_bindings:: BufferData (
546+ gl_bindings:: UNIFORM_BUFFER ,
547+ 16 ,
548+ std:: ptr:: null ( ) ,
549+ gl_bindings:: DYNAMIC_DRAW ,
550+ ) ;
534551 gl_bindings:: BindBufferBase ( gl_bindings:: UNIFORM_BUFFER , 0 , buf) ;
535552 }
536553 let err = unsafe { gl_bindings:: GetError ( ) } ;
@@ -542,7 +559,10 @@ impl WebGLState {
542559 }
543560 self . state . borrow_mut ( ) . gpu_safe = err == gl_bindings:: NO_ERROR ;
544561 if !self . state . borrow ( ) . gpu_safe {
545- log:: warn!( "GPU safety probe failed (GetError = {}). Disabling GPU-only paths." , err) ;
562+ log:: warn!(
563+ "GPU safety probe failed (GetError = {}). Disabling GPU-only paths." ,
564+ err
565+ ) ;
546566 }
547567 }
548568 }
@@ -565,30 +585,46 @@ impl WebGLState {
565585 /// Get cached active uniform-block count for a program. If not cached and
566586 /// the context is WebGL2, the value is queried from GL and cached.
567587 pub fn get_program_active_uniform_blocks ( & self , program : u32 ) -> Option < i32 > {
568- if let Some ( v) = self . state . borrow ( ) . program_active_uniform_blocks . get ( & program) {
588+ if let Some ( v) = self
589+ . state
590+ . borrow ( )
591+ . program_active_uniform_blocks
592+ . get ( & program)
593+ {
569594 return Some ( * v) ;
570595 }
571596 if self . get_version ( ) != WebGLVersion :: V2 {
572597 return None ;
573598 }
574599 self . context . make_current ( ) ;
575600 let mut active_blocks: i32 = 0 ;
576- unsafe { gl_bindings:: GetProgramiv ( program, gl_bindings:: ACTIVE_UNIFORM_BLOCKS , & mut active_blocks) }
577- self . state . borrow_mut ( ) . program_active_uniform_blocks . insert ( program, active_blocks) ;
601+ unsafe {
602+ gl_bindings:: GetProgramiv (
603+ program,
604+ gl_bindings:: ACTIVE_UNIFORM_BLOCKS ,
605+ & mut active_blocks,
606+ )
607+ }
608+ self . state
609+ . borrow_mut ( )
610+ . program_active_uniform_blocks
611+ . insert ( program, active_blocks) ;
578612 Some ( active_blocks)
579613 }
580614
581615 /// Set the cached active uniform-block count for a program (used after linking)
582616 pub fn set_program_active_uniform_blocks ( & mut self , program : u32 , count : i32 ) {
583- self . state . borrow_mut ( ) . program_active_uniform_blocks . insert ( program, count) ;
617+ self . state
618+ . borrow_mut ( )
619+ . program_active_uniform_blocks
620+ . insert ( program, count) ;
584621 }
585622
586623 /// Remove the current context if it's the stored context. Returns true if it was removed.
587624 pub fn remove_if_current ( & mut self ) -> bool {
588625 // Delegate to the GLContext's portable helper which returns a bool consistently
589626 self . context . remove_if_current ( )
590627 }
591-
592628}
593629
594630#[ derive( Clone ) ]
0 commit comments