pub fn render_to_buffer<Actions: IntoIterator<Item=RenderAction>>(&mut self, actions: Actions, target_texture: &metal::Texture) -> metal::CommandBuffer {
        // Create the render state
        let command_queue       = self.command_queue.clone();
        let matrix              = if self.flip_y { Matrix::identity().flip_y() } else { Matrix::identity() };
        let matrix              = MatrixBuffer::from_matrix(&self.device, matrix);
        let pipeline_config     = PipelineConfiguration::for_texture(target_texture);
        let pipeline_state      = self.get_pipeline_state(&pipeline_config);
        let command_buffer      = command_queue.new_command_buffer();
        let command_encoder     = self.get_command_encoder_with_clear(command_buffer, target_texture, Rgba8([0, 0, 0, 0]));

        let mut render_state    = RenderState {
            main_texture:           target_texture.clone(),
            target_texture:         target_texture.clone(),
            fill_texture:           None,
            erase_texture:          None,
            clip_texture:           None,
            matrix:                 matrix,
            texture_transform:      None,
            texture_alpha:          None,
            pipeline_config:        pipeline_config,
            pipeline_state:         pipeline_state,
            command_buffer:         command_buffer,
            command_encoder:        command_encoder
        };

        self.setup_command_encoder(&render_state);

        // Evaluate the actions
        for action in actions {
            use self::RenderAction::*;

            match action {
                SetTransform(matrix)                                                    => { self.set_transform(matrix, &mut render_state); }
                CreateVertex2DBuffer(id, vertices)                                      => { self.create_vertex_buffer_2d(id, vertices); }
                CreateIndexBuffer(id, indices)                                          => { self.create_index_buffer(id, indices); }
                FreeVertexBuffer(id)                                                    => { self.free_vertex_buffer(id); }
                FreeIndexBuffer(id)                                                     => { self.free_index_buffer(id); }
                BlendMode(blend_mode)                                                   => { self.blend_mode(blend_mode, &mut render_state); }
                CreateRenderTarget(render_id, texture_id, width, height, render_type)   => { self.create_render_target(render_id, texture_id, width, height, render_type); }
                FreeRenderTarget(render_id)                                             => { self.free_render_target(render_id); }
                SelectRenderTarget(render_id)                                           => { self.select_render_target(render_id, &mut render_state); }
                RenderToFrameBuffer                                                     => { self.select_main_frame_buffer(&mut render_state); }
                DrawFrameBuffer(render_id, x, y)                                        => { self.draw_frame_buffer(render_id, x, y, &mut render_state); }
                ShowFrameBuffer                                                         => { /* This doesn't double-buffer so nothing to do */ }
                CreateTextureBgra(texture_id, width, height)                            => { self.create_bgra_texture(texture_id, width, height); }
                CreateTextureMono(texture_id, width, height)                            => { self.create_mono_texture(texture_id, width, height); }
                Create1DTextureBgra(texture_id, width)                                  => { self.create_bgra_1d_texture(texture_id, width); }
                Create1DTextureMono(texture_id, width)                                  => { self.create_mono_1d_texture(texture_id, width); }
                WriteTextureData(texture_id, (x1, y1), (x2, y2), data)                  => { self.write_texture_data_2d(texture_id, x1, y1, x2, y2, data); }
                WriteTexture1D(texture_id, x1, x2, data)                                => { self.write_texture_data_1d(texture_id, x1, x2, data); }
                CreateMipMaps(texture_id)                                               => { self.create_mipmaps(texture_id, &mut render_state); }
                CopyTexture(src_texture, tgt_texture)                                   => { self.copy_texture(src_texture, tgt_texture, &mut render_state); }
                FreeTexture(texture_id)                                                 => { self.free_texture(texture_id); }
                Clear(color)                                                            => { self.clear(color, &mut render_state); }
                UseShader(shader_type)                                                  => { self.use_shader(shader_type, &mut render_state); }
                DrawTriangles(buffer_id, buffer_range)                                  => { self.draw_triangles(buffer_id, buffer_range, &mut render_state); }
                DrawIndexedTriangles(vertex_buffer, index_buffer, num_vertices)         => { self.draw_indexed_triangles(vertex_buffer, index_buffer, num_vertices, &mut render_state); }
            }
        }

        // Finish up
        render_state.command_encoder.end_encoding();

        command_buffer.to_owned()
    }
///
/// Performs some rendering instructions and returns the resulting command buffer
///
Performs some rendering instructions and returns the resulting command buffer
Performs some rendering instructions and returns the resulting command buffer
pub fn render_to_buffer<Actions: IntoIterator<Item=RenderAction>>(&mut self, actions: Actions, target_texture: &metal::Texture) -> metal::CommandBuffer {
        // Create the render state
        let command_queue       = self.command_queue.clone();
        let matrix              = if self.flip_y { Matrix::identity().flip_y() } else { Matrix::identity() };
        let matrix              = MatrixBuffer::from_matrix(&self.device, matrix);
        let pipeline_config     = PipelineConfiguration::for_texture(target_texture);
        let pipeline_state      = self.get_pipeline_state(&pipeline_config);
        let command_buffer      = command_queue.new_command_buffer();
        let command_encoder     = self.get_command_encoder_with_clear(command_buffer, target_texture, Rgba8([0, 0, 0, 0]));
        let mut render_state    = RenderState {
            main_texture:           target_texture.clone(),
            target_texture:         target_texture.clone(),
            fill_texture:           None,
            erase_texture:          None,
            clip_texture:           None,
            matrix:                 matrix,
            texture_transform:      None,
            texture_alpha:          None,
            pipeline_config:        pipeline_config,
            pipeline_state:         pipeline_state,
            command_buffer:         command_buffer,
            command_encoder:        command_encoder
        };
        self.setup_command_encoder(&render_state);
        // Evaluate the actions
        for action in actions {
            use self::RenderAction::*;
            match action {
                SetTransform(matrix)                                                    => { self.set_transform(matrix, &mut render_state); }
                CreateVertex2DBuffer(id, vertices)                                      => { self.create_vertex_buffer_2d(id, vertices); }
                CreateIndexBuffer(id, indices)                                          => { self.create_index_buffer(id, indices); }
                FreeVertexBuffer(id)                                                    => { self.free_vertex_buffer(id); }
                FreeIndexBuffer(id)                                                     => { self.free_index_buffer(id); }
                BlendMode(blend_mode)                                                   => { self.blend_mode(blend_mode, &mut render_state); }
                CreateRenderTarget(render_id, texture_id, width, height, render_type)   => { self.create_render_target(render_id, texture_id, width, height, render_type); }
                FreeRenderTarget(render_id)                                             => { self.free_render_target(render_id); }
                SelectRenderTarget(render_id)                                           => { self.select_render_target(render_id, &mut render_state); }
                RenderToFrameBuffer                                                     => { self.select_main_frame_buffer(&mut render_state); }
                DrawFrameBuffer(render_id, x, y)                                        => { self.draw_frame_buffer(render_id, x, y, &mut render_state); }
                ShowFrameBuffer                                                         => { /* This doesn't double-buffer so nothing to do */ }
                CreateTextureBgra(texture_id, width, height)                            => { self.create_bgra_texture(texture_id, width, height); }
                CreateTextureMono(texture_id, width, height)                            => { self.create_mono_texture(texture_id, width, height); }
                Create1DTextureBgra(texture_id, width)                                  => { self.create_bgra_1d_texture(texture_id, width); }
                Create1DTextureMono(texture_id, width)                                  => { self.create_mono_1d_texture(texture_id, width); }
                WriteTextureData(texture_id, (x1, y1), (x2, y2), data)                  => { self.write_texture_data_2d(texture_id, x1, y1, x2, y2, data); }
                WriteTexture1D(texture_id, x1, x2, data)                                => { self.write_texture_data_1d(texture_id, x1, x2, data); }
                CreateMipMaps(texture_id)                                               => { self.create_mipmaps(texture_id, &mut render_state); }
                CopyTexture(src_texture, tgt_texture)                                   => { self.copy_texture(src_texture, tgt_texture, &mut render_state); }
                FreeTexture(texture_id)                                                 => { self.free_texture(texture_id); }
                Clear(color)                                                            => { self.clear(color, &mut render_state); }
                UseShader(shader_type)                                                  => { self.use_shader(shader_type, &mut render_state); }
                DrawTriangles(buffer_id, buffer_range)                                  => { self.draw_triangles(buffer_id, buffer_range, &mut render_state); }
                DrawIndexedTriangles(vertex_buffer, index_buffer, num_vertices)         => { self.draw_indexed_triangles(vertex_buffer, index_buffer, num_vertices, &mut render_state); }
            }
        }
        // Finish up
        render_state.command_encoder.end_encoding();
        command_buffer.to_owned()
    }
pub fn render_to_buffer < Actions : IntoIterator < Item = RenderAction > > ( & mut self , actions : Actions , target_texture : & metal :: Texture ) -> metal :: CommandBuffer { // Create the render state let command_queue = self . command_queue . clone ( ) ; let matrix = if self . flip_y { Matrix :: identity ( ) . flip_y ( ) } else { Matrix :: identity ( ) } ; let matrix = MatrixBuffer :: from_matrix ( & self . device , matrix ) ; let pipeline_config = PipelineConfiguration :: for_texture ( target_texture ) ; let pipeline_state = self . get_pipeline_state ( & pipeline_config ) ; let command_buffer = command_queue . new_command_buffer ( ) ; let command_encoder = self . get_command_encoder_with_clear ( command_buffer , target_texture , Rgba8 ( [ 0 , 0 , 0 , 0 ] ) ) ; let mut render_state = RenderState { main_texture : target_texture . clone ( ) , target_texture : target_texture . clone ( ) , fill_texture : None , erase_texture : None , clip_texture : None , matrix : matrix , texture_transform : None , texture_alpha : None , pipeline_config : pipeline_config , pipeline_state : pipeline_state , command_buffer : command_buffer , command_encoder : command_encoder } ; self . setup_command_encoder ( & render_state ) ; // Evaluate the actions for action in actions { use self :: RenderAction :: * ; match action { SetTransform ( matrix ) => { self . set_transform ( matrix , & mut render_state ) ; } CreateVertex2DBuffer ( id , vertices ) => { self . create_vertex_buffer_2d ( id , vertices ) ; } CreateIndexBuffer ( id , indices ) => { self . create_index_buffer ( id , indices ) ; } FreeVertexBuffer ( id ) => { self . free_vertex_buffer ( id ) ; } FreeIndexBuffer ( id ) => { self . free_index_buffer ( id ) ; } BlendMode ( blend_mode ) => { self . blend_mode ( blend_mode , & mut render_state ) ; } CreateRenderTarget ( render_id , texture_id , width , height , render_type ) => { self . create_render_target ( render_id , texture_id , width , height , render_type ) ; } FreeRenderTarget ( render_id ) => { self . free_render_target ( render_id ) ; } SelectRenderTarget ( render_id ) => { self . select_render_target ( render_id , & mut render_state ) ; } RenderToFrameBuffer => { self . select_main_frame_buffer ( & mut render_state ) ; } DrawFrameBuffer ( render_id , x , y ) => { self . draw_frame_buffer ( render_id , x , y , & mut render_state ) ; } ShowFrameBuffer => { /* This doesn't double-buffer so nothing to do */ } CreateTextureBgra ( texture_id , width , height ) => { self . create_bgra_texture ( texture_id , width , height ) ; } CreateTextureMono ( texture_id , width , height ) => { self . create_mono_texture ( texture_id , width , height ) ; } Create1DTextureBgra ( texture_id , width ) => { self . create_bgra_1d_texture ( texture_id , width ) ; } Create1DTextureMono ( texture_id , width ) => { self . create_mono_1d_texture ( texture_id , width ) ; } WriteTextureData ( texture_id , ( x1 , y1 ) , ( x2 , y2 ) , data ) => { self . write_texture_data_2d ( texture_id , x1 , y1 , x2 , y2 , data ) ; } WriteTexture1D ( texture_id , x1 , x2 , data ) => { self . write_texture_data_1d ( texture_id , x1 , x2 , data ) ; } CreateMipMaps ( texture_id ) => { self . create_mipmaps ( texture_id , & mut render_state ) ; } CopyTexture ( src_texture , tgt_texture ) => { self . copy_texture ( src_texture , tgt_texture , & mut render_state ) ; } FreeTexture ( texture_id ) => { self . free_texture ( texture_id ) ; } Clear ( color ) => { self . clear ( color , & mut render_state ) ; } UseShader ( shader_type ) => { self . use_shader ( shader_type , & mut render_state ) ; } DrawTriangles ( buffer_id , buffer_range ) => { self . draw_triangles ( buffer_id , buffer_range , & mut render_state ) ; } DrawIndexedTriangles ( vertex_buffer , index_buffer , num_vertices ) => { self . draw_indexed_triangles ( vertex_buffer , index_buffer , num_vertices , & mut render_state ) ; } } } // Finish up render_state . command_encoder . end_encoding ( ) ; command_buffer . to_owned ( ) }
Performs some rendering instructions and returns the resulting command buffer
Performs some rendering instructions and returns the resulting command buffer
&mut self
actions
Actions
target_texture
&metal::Texture