From a2a5536822ab101e8c0d066bd9039e5de732d8ad Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 18 Mar 2015 18:07:57 +0100 Subject: [PATCH] Fix timeline shaders for OpenGL ES In OpenGL ES you have to: * Specify the precision for most values in fragment shaders * Add a special declaration to use fwidth() * Make sure both values passed to max() are of the same type (this may be the case for some Desktop OpenGL implementations, too) Repeating the default precision (highp float) in vertex shaders is useless and might lead to type casting problems, so we drop it. Without this change, the timeline doesn't work on Windows with ANGLE. Change-Id: I69a1976eddb6f4dc6dfe5fe9f270839432088cbb Reviewed-by: Maurice Kalinowski Reviewed-by: Joerg Bornemann Reviewed-by: Kai Koehne --- src/libs/timeline/qml/notes.frag | 4 ++-- src/libs/timeline/qml/timelineitems.frag | 13 +++++++++---- src/libs/timeline/qml/timelineitems.vert | 8 ++++---- src/plugins/qmlprofiler/qml/bindingloops.frag | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/libs/timeline/qml/notes.frag b/src/libs/timeline/qml/notes.frag index 472c0174db0..72ecfa93718 100644 --- a/src/libs/timeline/qml/notes.frag +++ b/src/libs/timeline/qml/notes.frag @@ -28,8 +28,8 @@ ** ****************************************************************************/ -vec4 orange = vec4(1.0, 165.0 / 255.0, 0.0, 1.0); -varying float d; +lowp vec4 orange = vec4(1.0, 165.0 / 255.0, 0.0, 1.0); +varying lowp float d; void main() { diff --git a/src/libs/timeline/qml/timelineitems.frag b/src/libs/timeline/qml/timelineitems.frag index 0ee0ad2aba6..5f44fbcf019 100644 --- a/src/libs/timeline/qml/timelineitems.frag +++ b/src/libs/timeline/qml/timelineitems.frag @@ -28,17 +28,22 @@ ** ****************************************************************************/ +#ifdef GL_OES_standard_derivatives +#extension GL_OES_standard_derivatives : enable +// else we probably have fwidth() in core +#endif + varying lowp vec3 edgeColor; varying lowp vec3 color; varying lowp vec2 barycentric; -vec4 zero = vec4(0.0); +lowp vec4 zero = vec4(0.0); void main() { - vec2 d = fwidth(barycentric) * 5.0; - vec4 edge_closeness = smoothstep(zero, vec4(d.x, d.y, d.x, d.y), + lowp vec2 d = fwidth(barycentric) * 5.0; + lowp vec4 edge_closeness = smoothstep(zero, vec4(d.x, d.y, d.x, d.y), vec4(barycentric.x, barycentric.y, 1.0 - barycentric.x, 1.0 - barycentric.y)); - float total = min(min(edge_closeness[0], edge_closeness[1]), + lowp float total = min(min(edge_closeness[0], edge_closeness[1]), min(edge_closeness[2], edge_closeness[3])); // square to make lines sharper total = total > 0.5 ? (1.0 - (1.0 - total) * (1.0 - total) * 2.0) : total * total * 2.0; diff --git a/src/libs/timeline/qml/timelineitems.vert b/src/libs/timeline/qml/timelineitems.vert index 58f28b558a9..cea5b49cd42 100644 --- a/src/libs/timeline/qml/timelineitems.vert +++ b/src/libs/timeline/qml/timelineitems.vert @@ -47,13 +47,13 @@ void main() gl_Position = matrix * vertexCoord; // Make very narrow events somewhat wider so that they don't collapse into 0 pixels - highp float scaledWidth = scale.x * rectSize.x; - highp float shift = sign(scaledWidth) * max(0, 3.0 - abs(scaledWidth)) * 0.0005; + float scaledWidth = scale.x * rectSize.x; + float shift = sign(scaledWidth) * max(0.0, 3.0 - abs(scaledWidth)) * 0.0005; gl_Position.x += shift; // Ditto for events with very small height - highp float scaledHeight = scale.y * rectSize.y; - gl_Position.y += float(rectSize.y > 0.0) * max(0, 3.0 - scaledHeight) * 0.003; + float scaledHeight = scale.y * rectSize.y; + gl_Position.y += float(rectSize.y > 0.0) * max(0.0, 3.0 - scaledHeight) * 0.003; barycentric = vec2(rectSize.x > 0.0 ? 1.0 : 0.0, rectSize.y > 0.0 ? 1.0 : 0.0); color = vertexColor.rgb; diff --git a/src/plugins/qmlprofiler/qml/bindingloops.frag b/src/plugins/qmlprofiler/qml/bindingloops.frag index 8f364adea43..135252ea9d7 100644 --- a/src/plugins/qmlprofiler/qml/bindingloops.frag +++ b/src/plugins/qmlprofiler/qml/bindingloops.frag @@ -28,7 +28,7 @@ ** ****************************************************************************/ -vec4 orange = vec4(1.0, 165.0 / 255.0, 0.0, 1.0); +lowp vec4 orange = vec4(1.0, 165.0 / 255.0, 0.0, 1.0); void main() { gl_FragColor = orange;