88use vello_cpu:: color:: palette:: css:: YELLOW ;
99use vello_cpu:: kurbo:: Affine ;
1010use vello_cpu:: {
11- Level , Pixmap , RenderContext , RenderMode , RenderSettings , Resources ,
11+ Level , Pixmap , RasterizerSettings , RenderContext , RenderMode , RenderSettings , Resources ,
1212 color:: palette:: css:: { BLUE , GREEN , RED } ,
1313 kurbo:: { Circle , Rect , Shape } ,
1414} ;
@@ -52,14 +52,17 @@ fn main() {
5252 // using 4+ threads might result in diminishing results, depending on
5353 // the workload.
5454 num_threads : 0 ,
55+ } ;
56+ let rasterizer_settings = RasterizerSettings {
5557 // Define whether the renderer should prioritize speed or quality
5658 // during rendering. Currently, the only difference is that
5759 // `OptimizeSpeed` will use u8/u16 for the rasterization
5860 // while `OptimizeQuality` uses f32. The former is much faster, but
5961 // has the disadvantage that the overall color accuracy might be slightly
6062 // worse due to quantization. Unless you really care about that, it is
6163 // highly recommended to use the `OptimizeSpeed` rendering mode.
62- render_mode : RenderMode :: OptimizeSpeed ,
64+ quality : RenderMode :: OptimizeSpeed ,
65+ ..Default :: default ( )
6366 } ;
6467
6568 // Vello CPU embraces a slightly different paradigm than a lot of other 2D
@@ -126,12 +129,12 @@ fn main() {
126129
127130 // Now the second step is to copy the results of the render context into the
128131 // pixmap. We do this by creating a new pixmap (or reusing an existing one).
129- // Please note that the pixmap and the render context need to have the same
130- // dimensions! Otherwise, the renderer will panic .
132+ // The pixmap and render context can have different dimensions. See the documentation
133+ // of the `render` method for more information .
131134 let mut pixmap_1 = Pixmap :: new ( 100 , 100 ) ;
132135 // Now, simply extract the results from the render context into the
133136 // pixmap.
134- ctx. render_to_pixmap ( & mut resources , & mut pixmap_1 ) ;
137+ ctx. render ( & mut pixmap_1 , & mut resources , rasterizer_settings ) ;
135138
136139 // Now you can do whatever you want with the pixmap, which provides raw
137140 // access to the premultiplied RGBA pixels of the image. If you have enabled
@@ -155,11 +158,11 @@ fn main() {
155158
156159 // Once again, we render the results into a pixmap again. If you can,
157160 // you can just reuse existing pixmaps (assuming they have the correct
158- // dimension), since all previous pixels in the pixmap will be
159- // discarded . In our case, we need to create a new one since our call
160- // to `into_png` consumed the pixmap.
161+ // dimension), since all previous pixels in the pixmap will be cleared by
162+ // the default replace mode . In our case, we need to create a new one since
163+ // our call to `into_png` consumed the pixmap.
161164 let mut pixmap_2 = Pixmap :: new ( 100 , 100 ) ;
162- ctx. render_to_pixmap ( & mut resources , & mut pixmap_2 ) ;
165+ ctx. render ( & mut pixmap_2 , & mut resources , rasterizer_settings ) ;
163166 let png_2 = pixmap_2. into_png ( ) . unwrap ( ) ;
164167 std:: fs:: write ( "example_basic2.png" , png_2) . unwrap ( ) ;
165168}
0 commit comments