Skip to content

Commit

Permalink
Fixed issues with old GL versions ( <= 2.1 )
Browse files Browse the repository at this point in the history
  • Loading branch information
bungoboingo committed Nov 8, 2022
1 parent d9f408d commit bbdffb1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions examples/modern_art/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ publish = false
[dependencies]
iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
rand = "0.8.5"
env_logger = "0.9"
2 changes: 2 additions & 0 deletions examples/modern_art/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use iced::{
use rand::{thread_rng, Rng};

fn main() -> iced::Result {
env_logger::builder().format_timestamp(None).init();

ModernArt::run(Settings {
antialiasing: true,
..Settings::default()
Expand Down
18 changes: 9 additions & 9 deletions glow/src/shader/common/gradient.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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];
Expand All @@ -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
Expand All @@ -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];
}
}
}
16 changes: 8 additions & 8 deletions glow/src/shader/common/triangle.frag
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#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
out vec4 fragColor;
#define gl_FragColor fragColor
out vec4 fragColor;
#define gl_FragColor fragColor
#endif

uniform vec4 color;

void main() {
fragColor = color;
gl_FragColor = color;
}
10 changes: 5 additions & 5 deletions glow/src/shader/compatibility/quad.frag
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#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

uniform float u_ScreenHeight;
Expand Down
14 changes: 7 additions & 7 deletions glow/src/shader/core/quad.frag
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#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
out vec4 fragColor;
#define gl_FragColor fragColor
out vec4 fragColor;
#define gl_FragColor fragColor
#endif

uniform float u_ScreenHeight;
Expand Down
4 changes: 2 additions & 2 deletions glow/src/triangle/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ impl Program {
linear.end.y,
);

gl.uniform_1_u32(
gl.uniform_1_i32(
Some(
&self
.uniform_data
.uniform_locations
.color_stops_size_location,
),
(linear.color_stops.len() * 2) as u32,
(linear.color_stops.len() * 2) as i32,
);

let mut stops = [0.0; 128];
Expand Down

0 comments on commit bbdffb1

Please sign in to comment.