From 02020214c44c44d9b615fcdb3cee167e38d281aa Mon Sep 17 00:00:00 2001 From: Petros Koutsolampros Date: Thu, 8 Oct 2020 19:31:58 +0100 Subject: [PATCH 1/2] Allow the OpenGL window and related objects to use OpenGL ES This ultimately allows the use of ANGLE for displaying graphics on windows, an implementation of OpengGL ES on directX. In practical terms the changes allow for using the depthmapX glview through Windows desktops without an OpenGL >=2.0 implementation, such as those through Remote Desktop (RDP) while previously the only solution was to switch to the legacy Map view. No special build or configuration parameters should be required, as the current Qt versions (>=5.5, tested on 5.13) dynamically load whatever graphics library is available. This change only affects the glview and not the 3dview (agents), as OpenGL ES does not support the fixed-function pipline (glBegin, glVertex etc.). Thus, glview should be available in both desktop and remote desktop versions of depthmapX, but the 3D view will only be available on local desktops that have a GPU. Other operating systems should are not affected by these changes More information: https://wiki.qt.io/Qt_5_on_Windows_ANGLE_and_OpenGL https://doc.qt.io/qt-5/windows-requirements.html#graphics-drivers https://en.wikipedia.org/wiki/OpenGL_ES https://doc.qt.io/qt-5/qopenglfunctions.html#details --- depthmapX/main.cpp | 1 - depthmapX/views/3dview/3dview.cpp | 2 ++ depthmapX/views/3dview/3dview.h | 4 +++- depthmapX/views/glview/gldynamicline.cpp | 3 ++- depthmapX/views/glview/gldynamicrect.cpp | 19 ++++++++++++------- depthmapX/views/glview/gllines.cpp | 5 +++-- depthmapX/views/glview/gllinesuniform.cpp | 5 +++-- depthmapX/views/glview/glpointmap.h | 5 +++-- depthmapX/views/glview/glrastertexture.cpp | 7 ++++--- depthmapX/views/glview/glshapegraph.h | 5 +++-- depthmapX/views/glview/gltriangles.cpp | 5 +++-- depthmapX/views/glview/gltrianglesuniform.cpp | 5 +++-- 12 files changed, 41 insertions(+), 25 deletions(-) diff --git a/depthmapX/main.cpp b/depthmapX/main.cpp index 3b4d7cd4..08150f33 100644 --- a/depthmapX/main.cpp +++ b/depthmapX/main.cpp @@ -24,7 +24,6 @@ #include #endif - int main(int argc, char *argv[]) { Q_INIT_RESOURCE(resource); diff --git a/depthmapX/views/3dview/3dview.cpp b/depthmapX/views/3dview/3dview.cpp index 8acde114..8ebdb18b 100644 --- a/depthmapX/views/3dview/3dview.cpp +++ b/depthmapX/views/3dview/3dview.cpp @@ -224,6 +224,8 @@ void Q3DView::timerEvent(QTimerEvent *event) //void Q3DView::Init() void Q3DView::initializeGL() { + initializeOpenGLFunctions(); + m_oldRect = QRect(0, 0, width(), height()); glClearDepth(1.0f); diff --git a/depthmapX/views/3dview/3dview.h b/depthmapX/views/3dview/3dview.h index e7408d53..94ca3b33 100644 --- a/depthmapX/views/3dview/3dview.h +++ b/depthmapX/views/3dview/3dview.h @@ -22,6 +22,8 @@ #include #include +#include + #define ID_ADD_AGENT 32947 #define ID_3D_PAN 32948 #define ID_3D_ZOOM 32949 @@ -93,7 +95,7 @@ struct C3DPixelData ///////////////////////////////////////////////////////////////////////////// -class Q3DView : public QOpenGLWidget +class Q3DView : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT diff --git a/depthmapX/views/glview/gldynamicline.cpp b/depthmapX/views/glview/gldynamicline.cpp index be69e899..5a7387ff 100644 --- a/depthmapX/views/glview/gldynamicline.cpp +++ b/depthmapX/views/glview/gldynamicline.cpp @@ -42,7 +42,8 @@ void GLDynamicLine::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView m_program->setUniformValue(m_diagVertices2DLoc, m_selectionBounds); m_program->setUniformValue(m_colourVectorLoc, m_colour_stroke); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount()); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glDrawArrays(GL_LINE_LOOP, 0, vertexCount()); m_program->release(); } diff --git a/depthmapX/views/glview/gldynamicrect.cpp b/depthmapX/views/glview/gldynamicrect.cpp index 21a672fa..c03ded49 100644 --- a/depthmapX/views/glview/gldynamicrect.cpp +++ b/depthmapX/views/glview/gldynamicrect.cpp @@ -19,12 +19,14 @@ static const char *vertexShaderSourceCore = "#version 150\n" "in float vertexIndex;\n" - "int idxx = int(mod(vertexIndex,2.0));\n" - "int idxy = int(vertexIndex/2.0);\n" + "int idxx;\n" + "int idxy;\n" "uniform mat2 diagVertices2D;\n" "uniform mat4 projMatrix;\n" "uniform mat4 mvMatrix;\n" "void main() {\n" + " idxx = int(mod(vertexIndex,2.0));\n" + " idxy = int(vertexIndex/2.0);\n" " gl_Position = projMatrix * mvMatrix * vec4(diagVertices2D[0][idxx],diagVertices2D[1][idxy],0,1);\n" "}\n"; @@ -38,17 +40,19 @@ static const char *fragmentShaderSourceCore = static const char *vertexShaderSource = "attribute float vertexIndex;\n" - "int idxx = int(mod(vertexIndex,2.0));\n" - "int idxy = int(vertexIndex/2.0);\n" + "int idxx;\n" + "int idxy;\n" "uniform mat2 diagVertices2D;\n" "uniform mat4 projMatrix;\n" "uniform mat4 mvMatrix;\n" "void main() {\n" + " idxx = int(mod(vertexIndex,2.0));\n" + " idxy = int(vertexIndex/2.0);\n" " gl_Position = projMatrix * mvMatrix * vec4(diagVertices2D[0][idxx],diagVertices2D[1][idxy],0,1);\n" "}\n"; static const char *fragmentShaderSource = - "uniform vec4 colourVector;\n" + "uniform highp vec4 colourVector;\n" "void main() {\n" " gl_FragColor = colourVector;\n" "}\n"; @@ -153,10 +157,11 @@ void GLDynamicRect::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView m_program->setUniformValue(m_diagVertices2DLoc, m_selectionBounds); m_program->setUniformValue(m_colourVectorLoc, m_colour_fill); - glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount()); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount()); m_program->setUniformValue(m_colourVectorLoc, m_colour_stroke); - glDrawArrays(GL_LINE_LOOP, 0, vertexCount()); + glFuncs->glDrawArrays(GL_LINE_LOOP, 0, vertexCount()); m_program->release(); } diff --git a/depthmapX/views/glview/gllines.cpp b/depthmapX/views/glview/gllines.cpp index ff2d6f86..04570d64 100644 --- a/depthmapX/views/glview/gllines.cpp +++ b/depthmapX/views/glview/gllines.cpp @@ -50,7 +50,7 @@ static const char *vertexShaderSource = "}\n"; static const char *fragmentShaderSource = - "varying vec3 col;\n" + "varying highp vec3 col;\n" "void main() {\n" " gl_FragColor = vec4(col, 1.0);\n" "}\n"; @@ -158,7 +158,8 @@ void GLLines::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, cons m_program->setUniformValue(m_projMatrixLoc, m_mProj); m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel); - glDrawArrays(GL_LINES, 0, vertexCount()); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glDrawArrays(GL_LINES, 0, vertexCount()); m_program->release(); } diff --git a/depthmapX/views/glview/gllinesuniform.cpp b/depthmapX/views/glview/gllinesuniform.cpp index 3c836df9..54a55b1b 100644 --- a/depthmapX/views/glview/gllinesuniform.cpp +++ b/depthmapX/views/glview/gllinesuniform.cpp @@ -43,7 +43,7 @@ static const char *vertexShaderSource = "}\n"; static const char *fragmentShaderSource = - "uniform vec4 colourVector;\n" + "uniform highp vec4 colourVector;\n" "void main() {\n" " gl_FragColor = colourVector;\n" "}\n"; @@ -157,7 +157,8 @@ void GLLinesUniform::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mVie m_program->setUniformValue(m_projMatrixLoc, m_mProj); m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel); - glDrawArrays(GL_LINES, 0, vertexCount()); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glDrawArrays(GL_LINES, 0, vertexCount()); m_program->release(); } diff --git a/depthmapX/views/glview/glpointmap.h b/depthmapX/views/glview/glpointmap.h index a1977a9e..d2153a89 100644 --- a/depthmapX/views/glview/glpointmap.h +++ b/depthmapX/views/glview/glpointmap.h @@ -48,10 +48,11 @@ class GLPointMap void paintGLOverlay(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, const QMatrix4x4 &m_mModel) { if(m_showLinks) { - glLineWidth(3); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glLineWidth(3); m_linkLines.paintGL(m_mProj, m_mView, m_mModel); m_linkFills.paintGL(m_mProj, m_mView, m_mModel); - glLineWidth(1); + glFuncs->glLineWidth(1); } } void paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, const QMatrix4x4 &m_mModel) diff --git a/depthmapX/views/glview/glrastertexture.cpp b/depthmapX/views/glview/glrastertexture.cpp index f3c06eab..a402ea8f 100644 --- a/depthmapX/views/glview/glrastertexture.cpp +++ b/depthmapX/views/glview/glrastertexture.cpp @@ -165,10 +165,11 @@ void GLRasterTexture::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mVi m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel); m_texture.bind(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glFuncs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount()); + glFuncs->glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount()); m_program->release(); } diff --git a/depthmapX/views/glview/glshapegraph.h b/depthmapX/views/glview/glshapegraph.h index a9f2de29..252a29b0 100644 --- a/depthmapX/views/glview/glshapegraph.h +++ b/depthmapX/views/glview/glshapegraph.h @@ -51,12 +51,13 @@ class GLShapeGraph { if(m_showLinks) { - glLineWidth(3); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glLineWidth(3); m_linkLines.paintGL(m_mProj, m_mView, m_mModel); m_linkFills.paintGL(m_mProj, m_mView, m_mModel); m_unlinkLines.paintGL(m_mProj, m_mView, m_mModel); m_unlinkFills.paintGL(m_mProj, m_mView, m_mModel); - glLineWidth(1); + glFuncs->glLineWidth(1); } } void paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, const QMatrix4x4 &m_mModel) diff --git a/depthmapX/views/glview/gltriangles.cpp b/depthmapX/views/glview/gltriangles.cpp index 9126bfd2..1449202d 100644 --- a/depthmapX/views/glview/gltriangles.cpp +++ b/depthmapX/views/glview/gltriangles.cpp @@ -47,7 +47,7 @@ static const char *vertexShaderSource = "}\n"; static const char *fragmentShaderSource = - "varying vec4 fragColour;\n" + "varying highp vec4 fragColour;\n" "void main() {\n" " gl_FragColor = fragColour;\n" "}\n"; @@ -132,7 +132,8 @@ void GLTriangles::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, m_program->setUniformValue(m_projMatrixLoc, m_mProj); m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel); - glDrawArrays(GL_TRIANGLES, 0, vertexCount()); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glDrawArrays(GL_TRIANGLES, 0, vertexCount()); m_program->release(); } diff --git a/depthmapX/views/glview/gltrianglesuniform.cpp b/depthmapX/views/glview/gltrianglesuniform.cpp index 2acb46c1..e805eaea 100644 --- a/depthmapX/views/glview/gltrianglesuniform.cpp +++ b/depthmapX/views/glview/gltrianglesuniform.cpp @@ -43,7 +43,7 @@ static const char *vertexShaderSource = "}\n"; static const char *fragmentShaderSource = - "uniform vec4 colourVector;\n" + "uniform highp vec4 colourVector;\n" "void main() {\n" " gl_FragColor = colourVector;\n" "}\n"; @@ -150,7 +150,8 @@ void GLTrianglesUniform::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_ m_program->setUniformValue(m_projMatrixLoc, m_mProj); m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel); - glDrawArrays(GL_TRIANGLES, 0, vertexCount()); + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glDrawArrays(GL_TRIANGLES, 0, vertexCount()); m_program->release(); } From 4a4179e42e0e00f829dc5d1e89bd6e5d0288bfc6 Mon Sep 17 00:00:00 2001 From: Petros Koutsolampros <2184600+pklampros@users.noreply.github.com> Date: Thu, 8 Oct 2020 19:36:14 +0100 Subject: [PATCH 2/2] Update main.cpp --- depthmapX/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/depthmapX/main.cpp b/depthmapX/main.cpp index 08150f33..3b4d7cd4 100644 --- a/depthmapX/main.cpp +++ b/depthmapX/main.cpp @@ -24,6 +24,7 @@ #include #endif + int main(int argc, char *argv[]) { Q_INIT_RESOURCE(resource);