From 0f19cbab554dda2e8d729ce181fe7ed55c3ccd03 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 25 Feb 2020 10:02:40 -0800 Subject: [PATCH] glsl 300 isnt working on mac. go back to 140 on native, and only use 300 for wasm. [rebuild] --- ezgui/src/assets/fragment_140.glsl | 5 +--- ezgui/src/assets/fragment_300.glsl | 41 ++++++++++++++++++++++++++++++ ezgui/src/assets/vertex_140.glsl | 8 +++--- ezgui/src/assets/vertex_300.glsl | 26 +++++++++++++++++++ ezgui/src/backend_wasm.rs | 4 +-- 5 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 ezgui/src/assets/fragment_300.glsl create mode 100644 ezgui/src/assets/vertex_300.glsl diff --git a/ezgui/src/assets/fragment_140.glsl b/ezgui/src/assets/fragment_140.glsl index 58a6423092..d588d49e7c 100644 --- a/ezgui/src/assets/fragment_140.glsl +++ b/ezgui/src/assets/fragment_140.glsl @@ -1,7 +1,4 @@ -#version 300 es - -precision mediump float; -precision mediump sampler2DArray; +#version 140 // (x offset, y offset, zoom) uniform vec3 transform; diff --git a/ezgui/src/assets/fragment_300.glsl b/ezgui/src/assets/fragment_300.glsl new file mode 100644 index 0000000000..58a6423092 --- /dev/null +++ b/ezgui/src/assets/fragment_300.glsl @@ -0,0 +1,41 @@ +#version 300 es + +precision mediump float; +precision mediump sampler2DArray; + +// (x offset, y offset, zoom) +uniform vec3 transform; +// (window width, window height, _) +uniform vec3 window; + +in vec4 pass_style; +out vec4 f_color; + +void main() { + // See actually_upload in drawing.rs to understand the different things encoded. + if (pass_style[0] == 100.0) { + // The hatching should be done in map-space, so panning/zooming doesn't move the stripes. + // This is screen_to_map, also accounting for the y-inversion done by the vertex shader. + float map_x = (gl_FragCoord.x + transform[0]) / transform[2]; + float map_y = (window[1] - gl_FragCoord.y + transform[1]) / transform[2]; + if (mod(map_x + map_y, 2.0) <= 0.1) { + f_color = vec4(0.0, 1.0, 1.0, 1.0); + } else if (mod(map_x - map_y, 2.0) <= 0.1) { + f_color = vec4(0.0, 1.0, 1.0, 1.0); + } else { + // Let the polygon with its original colors show instead. + discard; + } + } else if (pass_style[0] == 101.0) { + float map_x = (gl_FragCoord.x + transform[0]) / transform[2]; + float map_y = (window[1] - gl_FragCoord.y + transform[1]) / transform[2]; + if (mod(map_x + map_y, 2.0) <= 0.5) { + f_color = vec4(1.0, 1.0, 1.0, 1.0); + } else { + // Let the polygon with its original colors show instead. + discard; + } + } else { + f_color = pass_style; + } +} diff --git a/ezgui/src/assets/vertex_140.glsl b/ezgui/src/assets/vertex_140.glsl index 75e74cf19b..6e5233d89b 100644 --- a/ezgui/src/assets/vertex_140.glsl +++ b/ezgui/src/assets/vertex_140.glsl @@ -1,14 +1,12 @@ -#version 300 es - -precision mediump float; +#version 140 // (x offset, y offset, zoom) uniform vec3 transform; // (window width, window height, z value) uniform vec3 window; -layout (location = 0) in vec2 position; -layout (location = 1) in vec4 style; +in vec2 position; +in vec4 style; out vec4 pass_style; void main() { diff --git a/ezgui/src/assets/vertex_300.glsl b/ezgui/src/assets/vertex_300.glsl new file mode 100644 index 0000000000..75e74cf19b --- /dev/null +++ b/ezgui/src/assets/vertex_300.glsl @@ -0,0 +1,26 @@ +#version 300 es + +precision mediump float; + +// (x offset, y offset, zoom) +uniform vec3 transform; +// (window width, window height, z value) +uniform vec3 window; + +layout (location = 0) in vec2 position; +layout (location = 1) in vec4 style; +out vec4 pass_style; + +void main() { + pass_style = style; + + // This is map_to_screen + float screen_x = (position[0] * transform[2]) - transform[0]; + float screen_y = (position[1] * transform[2]) - transform[1]; + // Translate that to clip-space or whatever it's called + float x = (screen_x / window[0] * 2.0) - 1.0; + float y = (screen_y / window[1] * 2.0) - 1.0; + + // Note the y inversion + gl_Position = vec4(x, -y, window[2], 1.0); +} diff --git a/ezgui/src/backend_wasm.rs b/ezgui/src/backend_wasm.rs index 83171ebacb..58c088fd68 100644 --- a/ezgui/src/backend_wasm.rs +++ b/ezgui/src/backend_wasm.rs @@ -39,10 +39,10 @@ pub fn setup( unsafe { let shaders = [ - (glow::VERTEX_SHADER, include_str!("assets/vertex_140.glsl")), + (glow::VERTEX_SHADER, include_str!("assets/vertex_300.glsl")), ( glow::FRAGMENT_SHADER, - include_str!("assets/fragment_140.glsl"), + include_str!("assets/fragment_300.glsl"), ), ] .iter()