pub fn write<DrawIter: Iterator<Item=Draw>>(&mut self, drawing: DrawIter) {
        let mut drawing_cleared = false;
        let mut balance_frames  = false;
        let mut has_stack_ops   = false;

        for draw in drawing {
            // Process the drawing instruction
            match &draw {
                Draw::Layer(layer_id)   => { self.target_resource = DrawResource::Layer(*layer_id); },
                Draw::Sprite(sprite_id) => { self.target_resource = DrawResource::Sprite(*sprite_id); },

                Draw::ClearLayer        |
                Draw::ClearSprite       => { 
                    self.clear_resource(self.target_resource);
                    drawing_cleared = true; 
                    
                    match self.target_resource {
                        DrawResource::Layer(layer_id)   => self.pending_drawing.push((self.target_resource, Draw::Layer(layer_id))),
                        DrawResource::Sprite(sprite_id) => self.pending_drawing.push((self.target_resource, Draw::Sprite(sprite_id))),
                        _                               => unimplemented!()
                    }
                },

                Draw::ClearCanvas(_)    => { 
                    self.pending_drawing.retain(|(tgt, _action)| tgt == &DrawResource::Frame);
                    self.target_resource = DrawResource::Layer(LayerId(0));
                },

                Draw::ClearAllLayers    => {
                    self.clear_all_layers();
                    drawing_cleared = true;
                }

                Draw::PopState          => {
                    has_stack_ops = true;
                }

                _                       => { }
            }

            // Append the drawing instruction to the pending drawing
            match &draw {
                Draw::Restore => {
                    // Add the 'restore' operation in case we can't rewind anything
                    let drawing_target = draw.target_resource(&self.target_resource);
                    self.pending_drawing.push((drawing_target, draw));

                    // Rewind if the action is a 'restore' action
                    self.rewind_to_last_store();
                    drawing_cleared = true;
                },

                Draw::FreeStoredBuffer => {
                    // If we free a stored buffer immediately after a store, then both operations
                    if let Some((_, Draw::Store)) = self.pending_drawing.last() {
                        self.pending_drawing.pop();
                    } else {
                        let drawing_target = draw.target_resource(&self.target_resource);
                        self.pending_drawing.push((drawing_target, draw));
                    }
                }

                Draw::ShowFrame         |
                Draw::ResetFrame        => {
                    balance_frames = true;
                    self.pending_drawing.push((DrawResource::Frame, draw));
                }

                _ => {
                    // Add everything else to the pending drawing
                    let drawing_target = draw.target_resource(&self.target_resource);
                    self.pending_drawing.push((drawing_target, draw));
                }
            }
        }

        // If we've processed a clear instruction, clear out any unused resources from the pending list
        if drawing_cleared {
            self.remove_unused_resources();
        }

        if drawing_cleared && has_stack_ops {
            self.remove_unused_state_stack_ops();
        }

        if balance_frames {
            self.balance_show_frames();
        }
    }
///
/// Writes a stream of instructions to this drawing stream
///
Writes a stream of instructions to this drawing stream
Writes a stream of instructions to this drawing stream
pub fn write<DrawIter: Iterator<Item=Draw>>(&mut self, drawing: DrawIter) {
        let mut drawing_cleared = false;
        let mut balance_frames  = false;
        let mut has_stack_ops   = false;
        for draw in drawing {
            // Process the drawing instruction
            match &draw {
                Draw::Layer(layer_id)   => { self.target_resource = DrawResource::Layer(*layer_id); },
                Draw::Sprite(sprite_id) => { self.target_resource = DrawResource::Sprite(*sprite_id); },
                Draw::ClearLayer        |
                Draw::ClearSprite       => { 
                    self.clear_resource(self.target_resource);
                    drawing_cleared = true; 
                    match self.target_resource {
                        DrawResource::Layer(layer_id)   => self.pending_drawing.push((self.target_resource, Draw::Layer(layer_id))),
                        DrawResource::Sprite(sprite_id) => self.pending_drawing.push((self.target_resource, Draw::Sprite(sprite_id))),
                        _                               => unimplemented!()
                    }
                },
                Draw::ClearCanvas(_)    => { 
                    self.pending_drawing.retain(|(tgt, _action)| tgt == &DrawResource::Frame);
                    self.target_resource = DrawResource::Layer(LayerId(0));
                },
                Draw::ClearAllLayers    => {
                    self.clear_all_layers();
                    drawing_cleared = true;
                }
                Draw::PopState          => {
                    has_stack_ops = true;
                }
                _                       => { }
            }
            // Append the drawing instruction to the pending drawing
            match &draw {
                Draw::Restore => {
                    // Add the 'restore' operation in case we can't rewind anything
                    let drawing_target = draw.target_resource(&self.target_resource);
                    self.pending_drawing.push((drawing_target, draw));
                    // Rewind if the action is a 'restore' action
                    self.rewind_to_last_store();
                    drawing_cleared = true;
                },
                Draw::FreeStoredBuffer => {
                    // If we free a stored buffer immediately after a store, then both operations
                    if let Some((_, Draw::Store)) = self.pending_drawing.last() {
                        self.pending_drawing.pop();
                    } else {
                        let drawing_target = draw.target_resource(&self.target_resource);
                        self.pending_drawing.push((drawing_target, draw));
                    }
                }
                Draw::ShowFrame         |
                Draw::ResetFrame        => {
                    balance_frames = true;
                    self.pending_drawing.push((DrawResource::Frame, draw));
                }
                _ => {
                    // Add everything else to the pending drawing
                    let drawing_target = draw.target_resource(&self.target_resource);
                    self.pending_drawing.push((drawing_target, draw));
                }
            }
        }
        // If we've processed a clear instruction, clear out any unused resources from the pending list
        if drawing_cleared {
            self.remove_unused_resources();
        }
        if drawing_cleared && has_stack_ops {
            self.remove_unused_state_stack_ops();
        }
        if balance_frames {
            self.balance_show_frames();
        }
    }
pub fn write < DrawIter : Iterator < Item = Draw > > ( & mut self , drawing : DrawIter ) { let mut drawing_cleared = false ; let mut balance_frames = false ; let mut has_stack_ops = false ; for draw in drawing { // Process the drawing instruction match & draw { Draw :: Layer ( layer_id ) => { self . target_resource = DrawResource :: Layer ( * layer_id ) ; } , Draw :: Sprite ( sprite_id ) => { self . target_resource = DrawResource :: Sprite ( * sprite_id ) ; } , Draw :: ClearLayer | Draw :: ClearSprite => { self . clear_resource ( self . target_resource ) ; drawing_cleared = true ; match self . target_resource { DrawResource :: Layer ( layer_id ) => self . pending_drawing . push ( ( self . target_resource , Draw :: Layer ( layer_id ) ) ) , DrawResource :: Sprite ( sprite_id ) => self . pending_drawing . push ( ( self . target_resource , Draw :: Sprite ( sprite_id ) ) ) , _ => unimplemented ! ( ) } } , Draw :: ClearCanvas ( _ ) => { self . pending_drawing . retain ( | ( tgt , _action ) | tgt == & DrawResource :: Frame ) ; self . target_resource = DrawResource :: Layer ( LayerId ( 0 ) ) ; } , Draw :: ClearAllLayers => { self . clear_all_layers ( ) ; drawing_cleared = true ; } Draw :: PopState => { has_stack_ops = true ; } _ => { } } // Append the drawing instruction to the pending drawing match & draw { Draw :: Restore => { // Add the 'restore' operation in case we can't rewind anything let drawing_target = draw . target_resource ( & self . target_resource ) ; self . pending_drawing . push ( ( drawing_target , draw ) ) ; // Rewind if the action is a 'restore' action self . rewind_to_last_store ( ) ; drawing_cleared = true ; } , Draw :: FreeStoredBuffer => { // If we free a stored buffer immediately after a store, then both operations if let Some ( ( _ , Draw :: Store ) ) = self . pending_drawing . last ( ) { self . pending_drawing . pop ( ) ; } else { let drawing_target = draw . target_resource ( & self . target_resource ) ; self . pending_drawing . push ( ( drawing_target , draw ) ) ; } } Draw :: ShowFrame | Draw :: ResetFrame => { balance_frames = true ; self . pending_drawing . push ( ( DrawResource :: Frame , draw ) ) ; } _ => { // Add everything else to the pending drawing let drawing_target = draw . target_resource ( & self . target_resource ) ; self . pending_drawing . push ( ( drawing_target , draw ) ) ; } } } // If we've processed a clear instruction, clear out any unused resources from the pending list if drawing_cleared { self . remove_unused_resources ( ) ; } if drawing_cleared && has_stack_ops { self . remove_unused_state_stack_ops ( ) ; } if balance_frames { self . balance_show_frames ( ) ; } }
Writes a stream of instructions to this drawing stream
Writes a stream of instructions to this drawing stream
&mut self
drawing
DrawIter