summaryrefslogtreecommitdiffstats
path: root/glow/src
diff options
context:
space:
mode:
Diffstat (limited to 'glow/src')
-rw-r--r--glow/src/backend.rs10
-rw-r--r--glow/src/image.rs22
-rw-r--r--glow/src/lib.rs2
-rw-r--r--glow/src/quad/compatibility.rs8
-rw-r--r--glow/src/quad/core.rs4
-rw-r--r--glow/src/shader/compatibility/quad.frag24
-rw-r--r--glow/src/shader/compatibility/quad.vert12
-rw-r--r--glow/src/shader/core/quad.frag24
-rw-r--r--glow/src/shader/core/quad.vert12
9 files changed, 89 insertions, 29 deletions
diff --git a/glow/src/backend.rs b/glow/src/backend.rs
index 1a41d540..416c3b94 100644
--- a/glow/src/backend.rs
+++ b/glow/src/backend.rs
@@ -128,8 +128,14 @@ impl Backend {
let scaled = transformation
* Transformation::scale(scale_factor, scale_factor);
- self.image_pipeline
- .draw(gl, scaled, scale_factor, &layer.images);
+ self.image_pipeline.draw(
+ gl,
+ target_height,
+ scaled,
+ scale_factor,
+ &layer.images,
+ bounds,
+ );
}
if !layer.text.is_empty() {
diff --git a/glow/src/image.rs b/glow/src/image.rs
index f906cd4c..521a01e7 100644
--- a/glow/src/image.rs
+++ b/glow/src/image.rs
@@ -14,6 +14,7 @@ use iced_graphics::image::raster;
use iced_graphics::image::vector;
use iced_graphics::layer;
+use iced_graphics::Rectangle;
use iced_graphics::Size;
use glow::HasContext;
@@ -141,14 +142,17 @@ impl Pipeline {
pub fn draw(
&mut self,
mut gl: &glow::Context,
+ target_height: u32,
transformation: Transformation,
_scale_factor: f32,
images: &[layer::Image],
+ layer_bounds: Rectangle<u32>,
) {
unsafe {
gl.use_program(Some(self.program));
gl.bind_vertex_array(Some(self.vertex_array));
gl.bind_buffer(glow::ARRAY_BUFFER, Some(self.vertex_buffer));
+ gl.enable(glow::SCISSOR_TEST);
}
#[cfg(feature = "image")]
@@ -168,11 +172,16 @@ impl Pipeline {
layer::Image::Raster { handle: _, bounds } => (None, bounds),
#[cfg(feature = "svg")]
- layer::Image::Vector { handle, bounds } => {
+ layer::Image::Vector {
+ handle,
+ color,
+ bounds,
+ } => {
let size = [bounds.width, bounds.height];
(
vector_cache.upload(
handle,
+ *color,
size,
_scale_factor,
&mut gl,
@@ -183,10 +192,18 @@ impl Pipeline {
}
#[cfg(not(feature = "svg"))]
- layer::Image::Vector { handle: _, bounds } => (None, bounds),
+ layer::Image::Vector { bounds, .. } => (None, bounds),
};
unsafe {
+ gl.scissor(
+ layer_bounds.x as i32,
+ (target_height - (layer_bounds.y + layer_bounds.height))
+ as i32,
+ layer_bounds.width as i32,
+ layer_bounds.height as i32,
+ );
+
if let Some(storage::Entry { texture, .. }) = entry {
gl.bind_texture(glow::TEXTURE_2D, Some(*texture))
} else {
@@ -213,6 +230,7 @@ impl Pipeline {
gl.bind_buffer(glow::ARRAY_BUFFER, None);
gl.bind_vertex_array(None);
gl.use_program(None);
+ gl.disable(glow::SCISSOR_TEST);
}
}
diff --git a/glow/src/lib.rs b/glow/src/lib.rs
index e6ca0562..710ac36d 100644
--- a/glow/src/lib.rs
+++ b/glow/src/lib.rs
@@ -3,7 +3,7 @@
//! ![The native path of the Iced ecosystem](https://github.com/iced-rs/iced/blob/0525d76ff94e828b7b21634fa94a747022001c83/docs/graphs/native.png?raw=true)
//!
//! [`glow`]: https://github.com/grovesNL/glow
-//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
diff --git a/glow/src/quad/compatibility.rs b/glow/src/quad/compatibility.rs
index 28a5ea7c..e909162c 100644
--- a/glow/src/quad/compatibility.rs
+++ b/glow/src/quad/compatibility.rs
@@ -254,7 +254,7 @@ unsafe fn create_buffers(
gl.enable_vertex_attrib_array(4);
gl.vertex_attrib_pointer_f32(
4,
- 1,
+ 4,
glow::FLOAT,
false,
stride,
@@ -268,7 +268,7 @@ unsafe fn create_buffers(
glow::FLOAT,
false,
stride,
- 4 * (2 + 2 + 4 + 4 + 1),
+ 4 * (2 + 2 + 4 + 4 + 4),
);
gl.enable_vertex_attrib_array(6);
@@ -278,7 +278,7 @@ unsafe fn create_buffers(
glow::FLOAT,
false,
stride,
- 4 * (2 + 2 + 4 + 4 + 1 + 1),
+ 4 * (2 + 2 + 4 + 4 + 4 + 1),
);
gl.bind_vertex_array(None);
@@ -307,7 +307,7 @@ pub struct Vertex {
pub border_color: [f32; 4],
/// The border radius of the [`Vertex`].
- pub border_radius: f32,
+ pub border_radius: [f32; 4],
/// The border width of the [`Vertex`].
pub border_width: f32,
diff --git a/glow/src/quad/core.rs b/glow/src/quad/core.rs
index 16bec385..89036530 100644
--- a/glow/src/quad/core.rs
+++ b/glow/src/quad/core.rs
@@ -218,7 +218,7 @@ unsafe fn create_instance_buffer(
gl.enable_vertex_attrib_array(4);
gl.vertex_attrib_pointer_f32(
4,
- 1,
+ 4,
glow::FLOAT,
false,
stride,
@@ -233,7 +233,7 @@ unsafe fn create_instance_buffer(
glow::FLOAT,
false,
stride,
- 4 * (2 + 2 + 4 + 4 + 1),
+ 4 * (2 + 2 + 4 + 4 + 4),
);
gl.vertex_attrib_divisor(5, 1);
diff --git a/glow/src/shader/compatibility/quad.frag b/glow/src/shader/compatibility/quad.frag
index 8ea5693d..bb9d8122 100644
--- a/glow/src/shader/compatibility/quad.frag
+++ b/glow/src/shader/compatibility/quad.frag
@@ -12,7 +12,7 @@ varying vec4 v_Color;
varying vec4 v_BorderColor;
varying vec2 v_Pos;
varying vec2 v_Scale;
-varying float v_BorderRadius;
+varying vec4 v_BorderRadius;
varying float v_BorderWidth;
float _distance(vec2 frag_coord, vec2 position, vec2 size, float radius)
@@ -33,10 +33,26 @@ float _distance(vec2 frag_coord, vec2 position, vec2 size, float radius)
return sqrt(distance.x * distance.x + distance.y * distance.y);
}
+float selectBorderRadius(vec4 radi, vec2 position, vec2 center)
+{
+ float rx = radi.x;
+ float ry = radi.y;
+ rx = position.x > center.x ? radi.y : radi.x;
+ ry = position.x > center.x ? radi.z : radi.w;
+ rx = position.y > center.y ? ry : rx;
+ return rx;
+}
+
void main() {
vec2 fragCoord = vec2(gl_FragCoord.x, u_ScreenHeight - gl_FragCoord.y);
- float internal_border = max(v_BorderRadius - v_BorderWidth, 0.0);
+ float border_radius = selectBorderRadius(
+ v_BorderRadius,
+ fragCoord,
+ (v_Pos + v_Scale * 0.5).xy
+ );
+
+ float internal_border = max(border_radius - v_BorderWidth, 0.0);
float internal_distance = _distance(
fragCoord,
@@ -57,11 +73,11 @@ void main() {
fragCoord,
v_Pos,
v_Scale,
- v_BorderRadius
+ border_radius
);
float radius_alpha =
- 1.0 - smoothstep(max(v_BorderRadius - 0.5, 0.0), v_BorderRadius + 0.5, d);
+ 1.0 - smoothstep(max(border_radius - 0.5, 0.0), border_radius + 0.5, d);
gl_FragColor = vec4(mixed_color.xyz, mixed_color.w * radius_alpha);
}
diff --git a/glow/src/shader/compatibility/quad.vert b/glow/src/shader/compatibility/quad.vert
index abe70c0e..89931f06 100644
--- a/glow/src/shader/compatibility/quad.vert
+++ b/glow/src/shader/compatibility/quad.vert
@@ -5,7 +5,7 @@ attribute vec2 i_Pos;
attribute vec2 i_Scale;
attribute vec4 i_Color;
attribute vec4 i_BorderColor;
-attribute float i_BorderRadius;
+attribute vec4 i_BorderRadius;
attribute float i_BorderWidth;
attribute vec2 q_Pos;
@@ -13,7 +13,7 @@ varying vec4 v_Color;
varying vec4 v_BorderColor;
varying vec2 v_Pos;
varying vec2 v_Scale;
-varying float v_BorderRadius;
+varying vec4 v_BorderRadius;
varying float v_BorderWidth;
@@ -21,9 +21,11 @@ void main() {
vec2 p_Pos = i_Pos * u_Scale;
vec2 p_Scale = i_Scale * u_Scale;
- float i_BorderRadius = min(
- i_BorderRadius,
- min(i_Scale.x, i_Scale.y) / 2.0
+ vec4 i_BorderRadius = vec4(
+ min(i_BorderRadius.x, min(i_Scale.x, i_Scale.y) / 2.0),
+ min(i_BorderRadius.y, min(i_Scale.x, i_Scale.y) / 2.0),
+ min(i_BorderRadius.z, min(i_Scale.x, i_Scale.y) / 2.0),
+ min(i_BorderRadius.w, min(i_Scale.x, i_Scale.y) / 2.0)
);
mat4 i_Transform = mat4(
diff --git a/glow/src/shader/core/quad.frag b/glow/src/shader/core/quad.frag
index 57e2e8e7..71147aa5 100644
--- a/glow/src/shader/core/quad.frag
+++ b/glow/src/shader/core/quad.frag
@@ -17,7 +17,7 @@ in vec4 v_Color;
in vec4 v_BorderColor;
in vec2 v_Pos;
in vec2 v_Scale;
-in float v_BorderRadius;
+in vec4 v_BorderRadius;
in float v_BorderWidth;
float fDistance(vec2 frag_coord, vec2 position, vec2 size, float radius)
@@ -38,14 +38,30 @@ float fDistance(vec2 frag_coord, vec2 position, vec2 size, float radius)
return sqrt(distance.x * distance.x + distance.y * distance.y);
}
+float selectBorderRadius(vec4 radi, vec2 position, vec2 center)
+{
+ float rx = radi.x;
+ float ry = radi.y;
+ rx = position.x > center.x ? radi.y : radi.x;
+ ry = position.x > center.x ? radi.z : radi.w;
+ rx = position.y > center.y ? ry : rx;
+ return rx;
+}
+
void main() {
vec4 mixed_color;
vec2 fragCoord = vec2(gl_FragCoord.x, u_ScreenHeight - gl_FragCoord.y);
+ float border_radius = selectBorderRadius(
+ v_BorderRadius,
+ fragCoord,
+ (v_Pos + v_Scale * 0.5).xy
+ );
+
// TODO: Remove branching (?)
if(v_BorderWidth > 0.0) {
- float internal_border = max(v_BorderRadius - v_BorderWidth, 0.0);
+ float internal_border = max(border_radius - v_BorderWidth, 0.0);
float internal_distance = fDistance(
fragCoord,
@@ -69,11 +85,11 @@ void main() {
fragCoord,
v_Pos,
v_Scale,
- v_BorderRadius
+ border_radius
);
float radius_alpha =
- 1.0 - smoothstep(max(v_BorderRadius - 0.5, 0.0), v_BorderRadius + 0.5, d);
+ 1.0 - smoothstep(max(border_radius - 0.5, 0.0), border_radius + 0.5, d);
gl_FragColor = vec4(mixed_color.xyz, mixed_color.w * radius_alpha);
}
diff --git a/glow/src/shader/core/quad.vert b/glow/src/shader/core/quad.vert
index b1fb2365..17c3e641 100644
--- a/glow/src/shader/core/quad.vert
+++ b/glow/src/shader/core/quad.vert
@@ -5,14 +5,14 @@ in vec2 i_Pos;
in vec2 i_Scale;
in vec4 i_Color;
in vec4 i_BorderColor;
-in float i_BorderRadius;
+in vec4 i_BorderRadius;
in float i_BorderWidth;
out vec4 v_Color;
out vec4 v_BorderColor;
out vec2 v_Pos;
out vec2 v_Scale;
-out float v_BorderRadius;
+out vec4 v_BorderRadius;
out float v_BorderWidth;
vec2 positions[4] = vec2[](
@@ -27,9 +27,11 @@ void main() {
vec2 p_Pos = i_Pos * u_Scale;
vec2 p_Scale = i_Scale * u_Scale;
- float i_BorderRadius = min(
- i_BorderRadius,
- min(i_Scale.x, i_Scale.y) / 2.0
+ vec4 i_BorderRadius = vec4(
+ min(i_BorderRadius.x, min(i_Scale.x, i_Scale.y) / 2.0),
+ min(i_BorderRadius.y, min(i_Scale.x, i_Scale.y) / 2.0),
+ min(i_BorderRadius.z, min(i_Scale.x, i_Scale.y) / 2.0),
+ min(i_BorderRadius.w, min(i_Scale.x, i_Scale.y) / 2.0)
);
mat4 i_Transform = mat4(