Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the OpenGL window and related objects to use OpenGL ES #379

Merged
merged 2 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions depthmapX/views/3dview/3dview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion depthmapX/views/3dview/3dview.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <QPoint>
#include <QSize>

#include <QOpenGLFunctions>

#define ID_ADD_AGENT 32947
#define ID_3D_PAN 32948
#define ID_3D_ZOOM 32949
Expand Down Expand Up @@ -93,7 +95,7 @@ struct C3DPixelData

/////////////////////////////////////////////////////////////////////////////

class Q3DView : public QOpenGLWidget
class Q3DView : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT

Expand Down
3 changes: 2 additions & 1 deletion depthmapX/views/glview/gldynamicline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
19 changes: 12 additions & 7 deletions depthmapX/views/glview/gldynamicrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions depthmapX/views/glview/gllines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions depthmapX/views/glview/gllinesuniform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions depthmapX/views/glview/glpointmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions depthmapX/views/glview/glrastertexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions depthmapX/views/glview/glshapegraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions depthmapX/views/glview/gltriangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions depthmapX/views/glview/gltrianglesuniform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down