From 5575e6ea0897e406674e7e4239808fbf9daa07c3 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 24 Oct 2022 17:06:02 -0700 Subject: Add image/svg support to `iced_glow` https://github.com/iced-rs/iced/issues/674 Uses image/svg support in `iced_graphics`. The is not currently using an atlas, and uses one texture/draw per image. This should be good enough for now; supporting images with glow is better than not supporting them, and if something else performs better, that improvement can be made without any change to the public API. --- glow/src/shader/common/image.frag | 22 ++++++++++++++++++++++ glow/src/shader/common/image.vert | 9 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 glow/src/shader/common/image.frag create mode 100644 glow/src/shader/common/image.vert (limited to 'glow/src/shader') diff --git a/glow/src/shader/common/image.frag b/glow/src/shader/common/image.frag new file mode 100644 index 00000000..5e05abdf --- /dev/null +++ b/glow/src/shader/common/image.frag @@ -0,0 +1,22 @@ +#ifdef GL_ES +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif +#endif + +uniform sampler2D tex; +in vec2 tex_pos; + +#ifdef HIGHER_THAN_300 +out vec4 fragColor; +#define gl_FragColor fragColor +#endif +#ifdef GL_ES +#define texture texture2D +#endif + +void main() { + gl_FragColor = texture(tex, tex_pos); +} diff --git a/glow/src/shader/common/image.vert b/glow/src/shader/common/image.vert new file mode 100644 index 00000000..93e541f2 --- /dev/null +++ b/glow/src/shader/common/image.vert @@ -0,0 +1,9 @@ +uniform mat4 u_Transform; + +in vec2 i_Position; +out vec2 tex_pos; + +void main() { + gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0); + tex_pos = i_Position; +} -- cgit From 9841d1938142cb453495a50e4a88059c6eae3074 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Tue, 8 Nov 2022 11:32:27 -0800 Subject: Fixed issues with old GL versions ( <= 2.1 ) --- glow/src/shader/common/gradient.frag | 32 ++++++++++++++++---------------- glow/src/shader/common/triangle.frag | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'glow/src/shader') diff --git a/glow/src/shader/common/gradient.frag b/glow/src/shader/common/gradient.frag index 42d0201f..9af0cb6e 100644 --- a/glow/src/shader/common/gradient.frag +++ b/glow/src/shader/common/gradient.frag @@ -1,20 +1,20 @@ #ifdef GL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - precision highp float; - #else - precision mediump float; - #endif +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif #endif #ifdef HIGHER_THAN_300 - layout (location = 0) out vec4 fragColor; - #define gl_FragColor fragColor +layout (location = 0) out vec4 fragColor; +#define gl_FragColor fragColor #endif in vec2 raw_position; uniform vec4 gradient_direction; -uniform uint color_stops_size; +uniform int color_stops_size; // GLSL does not support dynamically sized arrays without SSBOs so this is capped to 16 stops //stored as color(vec4) -> offset(vec4) sequentially; uniform vec4 color_stops[32]; @@ -28,23 +28,23 @@ void main() { vec2 unit = normalize(gradient_vec); float coord_offset = dot(unit, current_vec) / length(gradient_vec); //if a gradient has a start/end stop that is identical, the mesh will have a transparent fill - fragColor = vec4(0.0, 0.0, 0.0, 0.0); + gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); float min_offset = color_stops[1].x; - float max_offset = color_stops[color_stops_size - 1u].x; + float max_offset = color_stops[color_stops_size - 1].x; - for (uint i = 0u; i < color_stops_size - 2u; i += 2u) { - float curr_offset = color_stops[i+1u].x; - float next_offset = color_stops[i+3u].x; + for (int i = 0; i < color_stops_size - 2; i += 2) { + float curr_offset = color_stops[i+1].x; + float next_offset = color_stops[i+3].x; if (coord_offset <= min_offset) { //current coordinate is before the first defined offset, set it to the start color - fragColor = color_stops[0]; + gl_FragColor = color_stops[0]; } if (curr_offset <= coord_offset && coord_offset <= next_offset) { //current fragment is between the current offset processing & the next one, interpolate colors - fragColor = mix(color_stops[i], color_stops[i+2u], smoothstep( + gl_FragColor = mix(color_stops[i], color_stops[i+2], smoothstep( curr_offset, next_offset, coord_offset @@ -53,7 +53,7 @@ void main() { if (coord_offset >= max_offset) { //current coordinate is before the last defined offset, set it to the last color - fragColor = color_stops[color_stops_size - 2u]; + gl_FragColor = color_stops[color_stops_size - 2]; } } } diff --git a/glow/src/shader/common/triangle.frag b/glow/src/shader/common/triangle.frag index ead40fe5..8260f6a6 100644 --- a/glow/src/shader/common/triangle.frag +++ b/glow/src/shader/common/triangle.frag @@ -14,5 +14,5 @@ out vec4 fragColor; uniform vec4 color; void main() { - fragColor = color; + gl_FragColor = color; } -- cgit From 33c3c0c0aa774bb7462e3c42aa04c591a66376a7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 14 Nov 2022 00:02:42 +0100 Subject: Group all solid triangles independently of color --- glow/src/shader/common/gradient.vert | 9 +++++++++ glow/src/shader/common/solid.frag | 18 ++++++++++++++++++ glow/src/shader/common/solid.vert | 11 +++++++++++ glow/src/shader/common/triangle.frag | 18 ------------------ glow/src/shader/common/triangle.vert | 9 --------- 5 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 glow/src/shader/common/gradient.vert create mode 100644 glow/src/shader/common/solid.frag create mode 100644 glow/src/shader/common/solid.vert delete mode 100644 glow/src/shader/common/triangle.frag delete mode 100644 glow/src/shader/common/triangle.vert (limited to 'glow/src/shader') diff --git a/glow/src/shader/common/gradient.vert b/glow/src/shader/common/gradient.vert new file mode 100644 index 00000000..fe505997 --- /dev/null +++ b/glow/src/shader/common/gradient.vert @@ -0,0 +1,9 @@ +uniform mat4 u_Transform; + +in vec2 i_Position; +out vec2 raw_position; + +void main() { + gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0); + raw_position = i_Position; +} diff --git a/glow/src/shader/common/solid.frag b/glow/src/shader/common/solid.frag new file mode 100644 index 00000000..174ffdd3 --- /dev/null +++ b/glow/src/shader/common/solid.frag @@ -0,0 +1,18 @@ +#ifdef GL_ES +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif +#endif + +#ifdef HIGHER_THAN_300 +out vec4 fragColor; +#define gl_FragColor fragColor +#endif + +in vec4 v_Color; + +void main() { + gl_FragColor = v_Color; +} diff --git a/glow/src/shader/common/solid.vert b/glow/src/shader/common/solid.vert new file mode 100644 index 00000000..59ed88e5 --- /dev/null +++ b/glow/src/shader/common/solid.vert @@ -0,0 +1,11 @@ +uniform mat4 u_Transform; + +in vec2 i_Position; +in vec4 i_Color; + +out vec4 v_Color; + +void main() { + gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0); + v_Color = i_Color; +} diff --git a/glow/src/shader/common/triangle.frag b/glow/src/shader/common/triangle.frag deleted file mode 100644 index 8260f6a6..00000000 --- a/glow/src/shader/common/triangle.frag +++ /dev/null @@ -1,18 +0,0 @@ -#ifdef GL_ES -#ifdef GL_FRAGMENT_PRECISION_HIGH -precision highp float; -#else -precision mediump float; -#endif -#endif - -#ifdef HIGHER_THAN_300 -out vec4 fragColor; -#define gl_FragColor fragColor -#endif - -uniform vec4 color; - -void main() { - gl_FragColor = color; -} diff --git a/glow/src/shader/common/triangle.vert b/glow/src/shader/common/triangle.vert deleted file mode 100644 index fe505997..00000000 --- a/glow/src/shader/common/triangle.vert +++ /dev/null @@ -1,9 +0,0 @@ -uniform mat4 u_Transform; - -in vec2 i_Position; -out vec2 raw_position; - -void main() { - gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0); - raw_position = i_Position; -} -- cgit