Merge branch 'master' into feature/test-recorder
This commit is contained in:
commit
9e81c2b9e8
88 changed files with 1225 additions and 1158 deletions
|
|
@ -105,13 +105,8 @@ pub struct Frame {
|
|||
}
|
||||
|
||||
impl Frame {
|
||||
/// Creates a new [`Frame`] with the given [`Size`].
|
||||
pub fn new(size: Size) -> Frame {
|
||||
Self::with_clip(Rectangle::with_size(size))
|
||||
}
|
||||
|
||||
/// Creates a new [`Frame`] with the given clip bounds.
|
||||
pub fn with_clip(bounds: Rectangle) -> Frame {
|
||||
pub fn new(bounds: Rectangle) -> Frame {
|
||||
Frame {
|
||||
clip_bounds: bounds,
|
||||
buffers: BufferStack::new(),
|
||||
|
|
@ -120,9 +115,7 @@ impl Frame {
|
|||
text: Vec::new(),
|
||||
transforms: Transforms {
|
||||
previous: Vec::new(),
|
||||
current: Transform(lyon::math::Transform::translation(
|
||||
bounds.x, bounds.y,
|
||||
)),
|
||||
current: Transform(lyon::math::Transform::identity()),
|
||||
},
|
||||
fill_tessellator: tessellation::FillTessellator::new(),
|
||||
stroke_tessellator: tessellation::StrokeTessellator::new(),
|
||||
|
|
@ -409,7 +402,7 @@ impl geometry::frame::Backend for Frame {
|
|||
}
|
||||
|
||||
fn draft(&mut self, clip_bounds: Rectangle) -> Frame {
|
||||
Frame::with_clip(clip_bounds)
|
||||
Frame::new(clip_bounds)
|
||||
}
|
||||
|
||||
fn paste(&mut self, frame: Frame) {
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ impl Batch {
|
|||
pub fn is_empty(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn append(&mut self, _batch: &mut Self) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,11 +49,14 @@ impl Layer {
|
|||
position: [bounds.x, bounds.y],
|
||||
size: [bounds.width, bounds.height],
|
||||
border_color: color::pack(quad.border.color),
|
||||
border_radius: quad.border.radius.into(),
|
||||
border_width: quad.border.width,
|
||||
border_radius: (quad.border.radius * transformation.scale_factor())
|
||||
.into(),
|
||||
border_width: quad.border.width * transformation.scale_factor(),
|
||||
shadow_color: color::pack(quad.shadow.color),
|
||||
shadow_offset: quad.shadow.offset.into(),
|
||||
shadow_blur_radius: quad.shadow.blur_radius,
|
||||
shadow_offset: (quad.shadow.offset * transformation.scale_factor())
|
||||
.into(),
|
||||
shadow_blur_radius: quad.shadow.blur_radius
|
||||
* transformation.scale_factor(),
|
||||
snap: quad.snap as u32,
|
||||
};
|
||||
|
||||
|
|
@ -268,6 +271,10 @@ impl graphics::Layer for Layer {
|
|||
}
|
||||
}
|
||||
|
||||
fn bounds(&self) -> Rectangle {
|
||||
self.bounds
|
||||
}
|
||||
|
||||
fn flush(&mut self) {
|
||||
self.flush_meshes();
|
||||
self.flush_text();
|
||||
|
|
@ -288,6 +295,62 @@ impl graphics::Layer for Layer {
|
|||
self.pending_meshes.clear();
|
||||
self.pending_text.clear();
|
||||
}
|
||||
|
||||
fn start(&self) -> usize {
|
||||
if !self.quads.is_empty() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if !self.triangles.is_empty() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if !self.primitives.is_empty() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if !self.images.is_empty() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
if !self.text.is_empty() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
usize::MAX
|
||||
}
|
||||
|
||||
fn end(&self) -> usize {
|
||||
if !self.text.is_empty() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
if !self.images.is_empty() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
if !self.primitives.is_empty() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if !self.triangles.is_empty() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if !self.quads.is_empty() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn merge(&mut self, layer: &mut Self) {
|
||||
self.quads.append(&mut layer.quads);
|
||||
self.triangles.append(&mut layer.triangles);
|
||||
self.primitives.append(&mut layer.primitives);
|
||||
self.images.append(&mut layer.images);
|
||||
self.text.append(&mut layer.text);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Layer {
|
||||
|
|
|
|||
|
|
@ -311,7 +311,9 @@ impl Renderer {
|
|||
viewport.physical_size(),
|
||||
));
|
||||
|
||||
for layer in self.layers.iter_mut() {
|
||||
self.layers.merge();
|
||||
|
||||
for layer in self.layers.iter() {
|
||||
if physical_bounds
|
||||
.intersection(&(layer.bounds * scale_factor))
|
||||
.and_then(Rectangle::snap)
|
||||
|
|
@ -648,8 +650,8 @@ impl core::Renderer for Renderer {
|
|||
layer.draw_quad(quad, background.into(), transformation);
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
self.layers.clear();
|
||||
fn reset(&mut self, new_bounds: Rectangle) {
|
||||
self.layers.reset(new_bounds);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -759,8 +761,8 @@ impl graphics::geometry::Renderer for Renderer {
|
|||
type Geometry = Geometry;
|
||||
type Frame = geometry::Frame;
|
||||
|
||||
fn new_frame(&self, size: core::Size) -> Self::Frame {
|
||||
geometry::Frame::new(size)
|
||||
fn new_frame(&self, bounds: Rectangle) -> Self::Frame {
|
||||
geometry::Frame::new(bounds)
|
||||
}
|
||||
|
||||
fn draw_geometry(&mut self, geometry: Self::Geometry) {
|
||||
|
|
|
|||
|
|
@ -304,6 +304,12 @@ impl Batch {
|
|||
self.gradients.clear();
|
||||
self.order.clear();
|
||||
}
|
||||
|
||||
pub fn append(&mut self, batch: &mut Batch) {
|
||||
self.solids.append(&mut batch.solids);
|
||||
self.gradients.append(&mut batch.gradients);
|
||||
self.order.append(&mut batch.order);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -72,8 +72,6 @@ impl Pipeline {
|
|||
) -> Self {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
use crate::graphics::color;
|
||||
|
||||
let layout = device.create_pipeline_layout(
|
||||
&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("iced_wgpu.quad.gradient.pipeline"),
|
||||
|
|
@ -86,39 +84,17 @@ impl Pipeline {
|
|||
device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||
label: Some("iced_wgpu.quad.gradient.shader"),
|
||||
source: wgpu::ShaderSource::Wgsl(
|
||||
std::borrow::Cow::Borrowed(
|
||||
if color::GAMMA_CORRECTION {
|
||||
concat!(
|
||||
include_str!("../shader/quad.wgsl"),
|
||||
"\n",
|
||||
include_str!("../shader/vertex.wgsl"),
|
||||
"\n",
|
||||
include_str!(
|
||||
"../shader/quad/gradient.wgsl"
|
||||
),
|
||||
"\n",
|
||||
include_str!("../shader/color.wgsl"),
|
||||
"\n",
|
||||
include_str!("../shader/color/oklab.wgsl")
|
||||
)
|
||||
} else {
|
||||
concat!(
|
||||
include_str!("../shader/quad.wgsl"),
|
||||
"\n",
|
||||
include_str!("../shader/vertex.wgsl"),
|
||||
"\n",
|
||||
include_str!(
|
||||
"../shader/quad/gradient.wgsl"
|
||||
),
|
||||
"\n",
|
||||
include_str!("../shader/color.wgsl"),
|
||||
"\n",
|
||||
include_str!(
|
||||
"../shader/color/linear_rgb.wgsl"
|
||||
)
|
||||
)
|
||||
},
|
||||
),
|
||||
std::borrow::Cow::Borrowed(concat!(
|
||||
include_str!("../shader/quad.wgsl"),
|
||||
"\n",
|
||||
include_str!("../shader/vertex.wgsl"),
|
||||
"\n",
|
||||
include_str!("../shader/quad/gradient.wgsl"),
|
||||
"\n",
|
||||
include_str!("../shader/color.wgsl"),
|
||||
"\n",
|
||||
include_str!("../shader/color/linear_rgb.wgsl")
|
||||
)),
|
||||
),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
const to_lms = mat3x4<f32>(
|
||||
vec4<f32>(0.4121656120, 0.2118591070, 0.0883097947, 0.0),
|
||||
vec4<f32>(0.5362752080, 0.6807189584, 0.2818474174, 0.0),
|
||||
vec4<f32>(0.0514575653, 0.1074065790, 0.6302613616, 0.0),
|
||||
);
|
||||
|
||||
const to_rgb = mat3x4<f32>(
|
||||
vec4<f32>( 4.0767245293, -3.3072168827, 0.2307590544, 0.0),
|
||||
vec4<f32>(-1.2681437731, 2.6093323231, -0.3411344290, 0.0),
|
||||
vec4<f32>(-0.0041119885, -0.7034763098, 1.7068625689, 0.0),
|
||||
);
|
||||
|
||||
fn interpolate_color(from_: vec4<f32>, to_: vec4<f32>, factor: f32) -> vec4<f32> {
|
||||
// To Oklab
|
||||
let lms_a = pow(from_ * to_lms, vec3<f32>(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0));
|
||||
let lms_b = pow(to_ * to_lms, vec3<f32>(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0));
|
||||
let mixed = mix(lms_a, lms_b, factor);
|
||||
|
||||
// Back to linear RGB
|
||||
var color = to_rgb * (mixed * mixed * mixed);
|
||||
|
||||
// Alpha interpolation
|
||||
color.a = mix(from_.a, to_.a, factor);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
@ -827,7 +827,6 @@ mod solid {
|
|||
mod gradient {
|
||||
use crate::Buffer;
|
||||
use crate::graphics::Antialiasing;
|
||||
use crate::graphics::color;
|
||||
use crate::graphics::mesh;
|
||||
use crate::triangle;
|
||||
|
||||
|
|
@ -922,35 +921,15 @@ mod gradient {
|
|||
device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||
label: Some("iced_wgpu.triangle.gradient.shader"),
|
||||
source: wgpu::ShaderSource::Wgsl(
|
||||
std::borrow::Cow::Borrowed(
|
||||
if color::GAMMA_CORRECTION {
|
||||
concat!(
|
||||
include_str!("shader/triangle.wgsl"),
|
||||
"\n",
|
||||
include_str!(
|
||||
"shader/triangle/gradient.wgsl"
|
||||
),
|
||||
"\n",
|
||||
include_str!("shader/color.wgsl"),
|
||||
"\n",
|
||||
include_str!("shader/color/oklab.wgsl")
|
||||
)
|
||||
} else {
|
||||
concat!(
|
||||
include_str!("shader/triangle.wgsl"),
|
||||
"\n",
|
||||
include_str!(
|
||||
"shader/triangle/gradient.wgsl"
|
||||
),
|
||||
"\n",
|
||||
include_str!("shader/color.wgsl"),
|
||||
"\n",
|
||||
include_str!(
|
||||
"shader/color/linear_rgb.wgsl"
|
||||
)
|
||||
)
|
||||
},
|
||||
),
|
||||
std::borrow::Cow::Borrowed(concat!(
|
||||
include_str!("shader/triangle.wgsl"),
|
||||
"\n",
|
||||
include_str!("shader/triangle/gradient.wgsl"),
|
||||
"\n",
|
||||
include_str!("shader/color.wgsl"),
|
||||
"\n",
|
||||
include_str!("shader/color/linear_rgb.wgsl")
|
||||
)),
|
||||
),
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue