From 479f58e7e30cb5bc84b7e12d99dfa995f32769aa Mon Sep 17 00:00:00 2001 From: k-a-z-u Date: Wed, 4 Apr 2018 10:09:22 +0200 Subject: [PATCH] switched openGL to es --- mapview/3D/MapView3D.cpp | 5 +++-- mapview/3D/misc/Shader.cpp | 37 +++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/mapview/3D/MapView3D.cpp b/mapview/3D/MapView3D.cpp index d3419cc..f737555 100644 --- a/mapview/3D/MapView3D.cpp +++ b/mapview/3D/MapView3D.cpp @@ -101,8 +101,9 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) { grabGesture(Qt::PanGesture); grabGesture(Qt::PinchGesture); - auto format = QSurfaceFormat(); - format.setVersion(3,3); + auto format = QSurfaceFormat(); + format.setRenderableType(QSurfaceFormat::OpenGLES); + format.setVersion(3, 0); //format.setSamples(2); auto ver = format.version(); diff --git a/mapview/3D/misc/Shader.cpp b/mapview/3D/misc/Shader.cpp index b3bc206..f9e1657 100644 --- a/mapview/3D/misc/Shader.cpp +++ b/mapview/3D/misc/Shader.cpp @@ -4,16 +4,15 @@ Shader::Shader() { addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, R"( - #version 330 - in highp vec3 a_vertex; - in highp vec3 a_normal; - in lowp vec4 a_color; + attribute highp vec3 a_vertex; + attribute highp vec3 a_normal; + attribute lowp vec4 a_color; uniform highp mat4 M; uniform highp mat4 V; uniform highp mat4 P; - out highp vec3 v_normal; - out lowp vec4 v_color; - out lowp vec4 v_vertex; + varying highp vec3 v_normal; + varying lowp vec4 v_color; + varying lowp vec4 v_vertex; void main() { gl_Position = P * V * M * vec4(a_vertex, 1.0); v_normal = (V * M * vec4(a_normal, 0.0)).xyz; @@ -23,26 +22,24 @@ Shader::Shader() { )"); addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, R"( - #version 330 - uniform vec4 color; + uniform lowp vec4 color; uniform bool useNormal; uniform bool useVertexColor; - in highp vec3 v_normal; - in lowp vec4 v_color; - in lowp vec4 v_vertex; - - layout(location=1) out vec4 fragColor; + varying highp vec3 v_normal; + varying lowp vec4 v_color; + varying lowp vec4 v_vertex; void main() { - vec3 lightPos = vec3(0,0,0); // camera + mediump vec3 lightPos = vec3(0,0,0); // camera //vec3 lightVec = normalize(vec3(0,0,1)); - vec3 lightVec = normalize(lightPos - v_vertex.xyz); - float intensity = useNormal ? 0.3 + 0.7 * dot( normalize(v_normal), lightVec ) : 1.0; // light at camera pos - vec4 col = useVertexColor ? v_color : color; - fragColor.rgb = col.rgb * intensity; - fragColor.a = col.a; + mediump vec3 lightVec = normalize(lightPos - v_vertex.xyz); + lowp float intensity = useNormal ? 0.3 + 0.7 * dot( normalize(v_normal), lightVec ) : 1.0; // light at camera pos + lowp vec4 col = useVertexColor ? v_color : color; + gl_FragColor.rgb = col.rgb * intensity; + gl_FragColor.a = col.a; } )"); + //bindAttributeLocation("vertices", 0); if (!link()) {