Fix glow backend on mac

Without this change, the screen was blank when using the glow backend on macos.

Some debugging traced it down to the shader attribute configuration.
@dabreegster suggested trying to declare a newer version of the shader
language which supports the syntax for explicit attribute layout, which
fixed it.

Specifically, before this commit, this diff was interesting on macos:

diff --git a/ezgui/src/backend_glow.rs b/ezgui/src/backend_glow.rs
index 2046bccd..f834a4fa 100644
--- a/ezgui/src/backend_glow.rs
+++ b/ezgui/src/backend_glow.rs
@@ -244,31 +244,7 @@ impl PrerenderInnards {
                 glow::FLOAT,
                 false,
                 stride,
-                // WTF: this offset seems correct, but on macos (OpenGL 4.1)
-                // a blank screen is rendered.
-                //
-                // To debug, I've hardcoded a color assignment in the fragment shader.
-                //
-                // What's fascinating is that, even if we don't use this second "style"
-                // input for anything, the mere act of passing it in with the expected
-                // offset causes all the geometries to not be visible.
-                //
-                // That is:
-                // - with a hardcoded color in the fragment shader
-                // - set offset `0` here (which is surely wrong?)
-                // - I can see the correct shapes with my hardcoded color
-                //
-                // - with a hardcoded color in the fragment shader
-                // - set offset `2*size_of(f32)` here (which should be right)
-                // - I'd expect to see the correct shapes with my hardcoded color
-                // - But instead I can no longer see any shapes on the screen
-                //
-                // So it seems like something about setting the offset on this second attribute
-                // configuration is corrupting our vertex data, even if we never read from that
-                // attribute data.
-                //
-                // 2 * std::mem::size_of::<f32>() as i32,
-                0
+                2 * std::mem::size_of::<f32>() as i32,
             );
This commit is contained in:
Michael Kirk 2020-08-19 08:30:20 -07:00 committed by Dustin Carlino
parent f31c4ec7fb
commit 7856671ac6
2 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
#version 140 #version 410
// (x offset, y offset, zoom) // (x offset, y offset, zoom)
uniform vec3 transform; uniform vec3 transform;

View File

@ -1,12 +1,12 @@
#version 140 #version 410
// (x offset, y offset, zoom) // (x offset, y offset, zoom)
uniform vec3 transform; uniform vec3 transform;
// (window width, window height, z value) // (window width, window height, z value)
uniform vec3 window; uniform vec3 window;
in vec2 position; layout (location = 0) in vec2 position;
in vec4 style; layout (location = 1) in vec4 style;
out vec4 pass_style; out vec4 pass_style;
void main() { void main() {
@ -15,7 +15,7 @@ void main() {
// This is map_to_screen // This is map_to_screen
float screen_x = (position[0] * transform[2]) - transform[0]; float screen_x = (position[0] * transform[2]) - transform[0];
float screen_y = (position[1] * transform[2]) - transform[1]; float screen_y = (position[1] * transform[2]) - transform[1];
// Translate that to clip-space or whatever it's called // Translate that to normalized device coordinates (NDC)
float x = (screen_x / window[0] * 2.0) - 1.0; float x = (screen_x / window[0] * 2.0) - 1.0;
float y = (screen_y / window[1] * 2.0) - 1.0; float y = (screen_y / window[1] * 2.0) - 1.0;