pub fn remove_unused_state_stack_ops(&mut self) {
        // A stack of push states which have no drawing operations (cleared on any drawing operation)
        let mut push_state_stack    = vec![];

        // The indexes that we should remove
        let mut to_remove           = HashSet::new();

        for (idx, (_tgt_resource, draw)) in self.pending_drawing.iter().enumerate() {
            match draw {
                Draw::PushState => {
                    // This pushes a state onto the stack
                    push_state_stack.push(idx);
                }

                Draw::PopState => {
                    // If there's a 'unaffected' state on top of the push state stack, then clear all the indexes
                    // The stack is cleared when the state is used, so the pop will return None in that case
                    if let Some(initial_idx) = push_state_stack.pop() {
                        for remove_idx in initial_idx..=idx {
                            to_remove.insert(remove_idx);
                        }
                    }
                }

                draw => {
                    // Clear the state stack so nothing will be removed if the operation uses the state that's present there
                    if !draw.is_state_stack_resource() {
                        if push_state_stack.len() > 0 {
                            push_state_stack = vec![];
                        }
                    }
                }
            }
        }

        // Remove anything in the to_remove hashset
        if to_remove.len() > 0 {
            let old_drawing         = mem::take(&mut self.pending_drawing);
            self.pending_drawing    = old_drawing.into_iter()
                .enumerate()
                .filter(|(idx, _item)| !to_remove.contains(idx))
                .map(|(_idx, item)| item)
                .collect();
        }
    }
///
/// Removes any PushState/PopState operation that performs no drawing (ie, just sets up state and throws it away)
///
Removes any PushState/PopState operation that performs no drawing
Removes any PushState / PopState operation that performs no drawing
pub fn remove_unused_state_stack_ops(&mut self) {
        // A stack of push states which have no drawing operations (cleared on any drawing operation)
        let mut push_state_stack    = vec![];
        // The indexes that we should remove
        let mut to_remove           = HashSet::new();
        for (idx, (_tgt_resource, draw)) in self.pending_drawing.iter().enumerate() {
            match draw {
                Draw::PushState => {
                    // This pushes a state onto the stack
                    push_state_stack.push(idx);
                }
                Draw::PopState => {
                    // If there's a 'unaffected' state on top of the push state stack, then clear all the indexes
                    // The stack is cleared when the state is used, so the pop will return None in that case
                    if let Some(initial_idx) = push_state_stack.pop() {
                        for remove_idx in initial_idx..=idx {
                            to_remove.insert(remove_idx);
                        }
                    }
                }
                draw => {
                    // Clear the state stack so nothing will be removed if the operation uses the state that's present there
                    if !draw.is_state_stack_resource() {
                        if push_state_stack.len() > 0 {
                            push_state_stack = vec![];
                        }
                    }
                }
            }
        }
        // Remove anything in the to_remove hashset
        if to_remove.len() > 0 {
            let old_drawing         = mem::take(&mut self.pending_drawing);
            self.pending_drawing    = old_drawing.into_iter()
                .enumerate()
                .filter(|(idx, _item)| !to_remove.contains(idx))
                .map(|(_idx, item)| item)
                .collect();
        }
    }
pub fn remove_unused_state_stack_ops ( & mut self ) { // A stack of push states which have no drawing operations (cleared on any drawing operation) let mut push_state_stack = vec ! [ ] ; // The indexes that we should remove let mut to_remove = HashSet :: new ( ) ; for ( idx , ( _tgt_resource , draw ) ) in self . pending_drawing . iter ( ) . enumerate ( ) { match draw { Draw :: PushState => { // This pushes a state onto the stack push_state_stack . push ( idx ) ; } Draw :: PopState => { // If there's a 'unaffected' state on top of the push state stack, then clear all the indexes // The stack is cleared when the state is used, so the pop will return None in that case if let Some ( initial_idx ) = push_state_stack . pop ( ) { for remove_idx in initial_idx ..= idx { to_remove . insert ( remove_idx ) ; } } } draw => { // Clear the state stack so nothing will be removed if the operation uses the state that's present there if ! draw . is_state_stack_resource ( ) { if push_state_stack . len ( ) > 0 { push_state_stack = vec ! [ ] ; } } } } } // Remove anything in the to_remove hashset if to_remove . len ( ) > 0 { let old_drawing = mem :: take ( & mut self . pending_drawing ) ; self . pending_drawing = old_drawing . into_iter ( ) . enumerate ( ) . filter ( | ( idx , _item ) | ! to_remove . contains ( idx ) ) . map ( | ( _idx , item ) | item ) . collect ( ) ; } }
Removes any PushState/PopState operation that performs no drawing (ie, just sets up state and throws it away)
Removes any PushState / PopState operation that performs no drawing ( ie just sets up state and throws it away )
&mut self