1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![warn(clippy::all)]
#![allow(
    clippy::must_use_candidate,
    clippy::range_plus_one,
    clippy::module_name_repetitions,
    clippy::cast_sign_loss,
    clippy::cast_possible_truncation,
    clippy::cast_precision_loss,
    clippy::items_after_statements,
    clippy::too_many_lines,
    clippy::too_many_arguments,
    clippy::cast_lossless
)]

pub use wgpu;

mod batch;
mod canvas;
mod color;
mod geom;
mod image;
mod paint;
mod path;
mod picture;
mod pipeline;
mod renderer;
mod tessellator;

#[cfg(feature = "bevy")]
#[cfg_attr(docsrs, doc(cfg(feature = "bevy")))]
pub mod plugin;

pub use crate::{
    canvas::Canvas,
    color::Color,
    geom::{Offset, Rect, Rounding, Transform},
    image::Images,
    paint::{
        BoxGradient, IntoPaint, LineCap, LineJoin, LinearGradient, Paint, RadialGradient, Stroke,
    },
    path::{Command, FillRule, Path, Solidity},
    picture::{Picture, Recorder},
    pipeline::Pipeline,
    renderer::{Image, Renderer},
};

pub mod internals {
    pub use crate::{
        batch::{Batch, GpuBatch},
        canvas::TransformStack,
        image::ImageBind,
        path::{PathIter, PathTransformIter},
        picture::DrawCall,
        pipeline::{Instance, Vertex},
        tessellator::{Draw, Tessellator},
    };
}

pub fn render_pictures<'a>(
    encoder: &'a mut wgpu::CommandEncoder,
    color_view: &'a wgpu::TextureView,
    depth_view: &'a wgpu::TextureView,
    bundles: impl IntoIterator<Item = &'a wgpu::RenderBundle> + 'a,
    clear_color: Option<wgpu::Color>,
    clear: bool,
) {
    let cload = clear_color.map_or(wgpu::LoadOp::Load, wgpu::LoadOp::Clear);
    let dload = clear.then_some(wgpu::LoadOp::Load).unwrap_or_default();
    let sload = clear.then_some(wgpu::LoadOp::Load).unwrap_or_default();
    let store = true;

    let desc = wgpu::RenderPassDescriptor {
        label: Some("reui"),
        color_attachments: &[Some(wgpu::RenderPassColorAttachment {
            view: color_view,
            resolve_target: None,
            ops: wgpu::Operations { load: cload, store },
        })],
        depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
            view: depth_view,
            depth_ops: Some(wgpu::Operations { load: dload, store }),
            stencil_ops: Some(wgpu::Operations { load: sload, store }),
        }),
    };

    encoder.begin_render_pass(&desc).execute_bundles(bundles)
}

pub fn combine_viewport(width: u32, height: u32) -> [f32; 4] {
    let w = f32::recip(width as f32);
    let h = f32::recip(height as f32);
    [w, h, w, h]
}