mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-06-02 15:02:26 -04:00
OpenGL modernization: compile and link basic shaders
This commit is contained in:
parent
8b800d8354
commit
22d9e77974
@ -117,6 +117,7 @@ set(sdrbase_SOURCES
|
|||||||
sdrbase/gui/colormapper.cpp
|
sdrbase/gui/colormapper.cpp
|
||||||
sdrbase/gui/glscope.cpp
|
sdrbase/gui/glscope.cpp
|
||||||
sdrbase/gui/glscopegui.cpp
|
sdrbase/gui/glscopegui.cpp
|
||||||
|
sdrbase/gui/glshadersources.cpp
|
||||||
sdrbase/gui/glspectrum.cpp
|
sdrbase/gui/glspectrum.cpp
|
||||||
sdrbase/gui/glspectrumgui.cpp
|
sdrbase/gui/glspectrumgui.cpp
|
||||||
sdrbase/gui/indicator.cpp
|
sdrbase/gui/indicator.cpp
|
||||||
@ -199,6 +200,7 @@ set(sdrbase_HEADERS
|
|||||||
include/gui/colormapper.h
|
include/gui/colormapper.h
|
||||||
include/gui/glscope.h
|
include/gui/glscope.h
|
||||||
include/gui/glscopegui.h
|
include/gui/glscopegui.h
|
||||||
|
include/gui/glshadersources.h
|
||||||
include/gui/glspectrum.h
|
include/gui/glspectrum.h
|
||||||
include/gui/glspectrumgui.h
|
include/gui/glspectrumgui.h
|
||||||
include/gui/indicator.h
|
include/gui/indicator.h
|
||||||
|
@ -23,13 +23,11 @@
|
|||||||
class GLShaderSources
|
class GLShaderSources
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const QString& getVertexShaderSourceSimple();
|
static const QString& getVertexShaderSourceSimple() { return m_vertexShaderSourceSimple; }
|
||||||
static const QString& getFragmentShaderSourceColored();
|
static const QString& getFragmentShaderSourceColored() { return m_fragmentShaderSourceColored; }
|
||||||
private:
|
private:
|
||||||
static const QString m_vertexShaderSourceSimple;
|
static const QString m_vertexShaderSourceSimple;
|
||||||
static const QString m_fragmentShaderSourceColored;
|
static const QString m_fragmentShaderSourceColored;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* INCLUDE_GUI_GLSHADERSOURCES_H_ */
|
#endif /* INCLUDE_GUI_GLSHADERSOURCES_H_ */
|
||||||
|
@ -21,11 +21,15 @@
|
|||||||
#include <QGLWidget>
|
#include <QGLWidget>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QOpenGLBuffer>
|
||||||
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include "dsp/dsptypes.h"
|
#include "dsp/dsptypes.h"
|
||||||
#include "gui/scaleengine.h"
|
#include "gui/scaleengine.h"
|
||||||
#include "dsp/channelmarker.h"
|
#include "dsp/channelmarker.h"
|
||||||
#include "util/export.h"
|
#include "util/export.h"
|
||||||
|
|
||||||
|
class QOpenGLShaderProgram;
|
||||||
|
|
||||||
class SDRANGEL_API GLSpectrum : public QGLWidget {
|
class SDRANGEL_API GLSpectrum : public QGLWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -150,6 +154,12 @@ private:
|
|||||||
|
|
||||||
bool m_displayChanged;
|
bool m_displayChanged;
|
||||||
|
|
||||||
|
QOpenGLVertexArrayObject m_vao;
|
||||||
|
QOpenGLBuffer m_vbo;
|
||||||
|
QOpenGLShaderProgram *m_program;
|
||||||
|
int m_matrixLoc;
|
||||||
|
int m_colorLoc;
|
||||||
|
|
||||||
void updateWaterfall(const std::vector<Real>& spectrum);
|
void updateWaterfall(const std::vector<Real>& spectrum);
|
||||||
void updateHistogram(const std::vector<Real>& spectrum);
|
void updateHistogram(const std::vector<Real>& spectrum);
|
||||||
|
|
||||||
@ -167,6 +177,8 @@ private:
|
|||||||
void enterEvent(QEvent* event);
|
void enterEvent(QEvent* event);
|
||||||
void leaveEvent(QEvent* event);
|
void leaveEvent(QEvent* event);
|
||||||
|
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void tick();
|
void tick();
|
||||||
void channelMarkerChanged();
|
void channelMarkerChanged();
|
||||||
|
@ -18,16 +18,14 @@
|
|||||||
#include "gui/glshadersources.h"
|
#include "gui/glshadersources.h"
|
||||||
|
|
||||||
const QString GLShaderSources::m_vertexShaderSourceSimple = QString(
|
const QString GLShaderSources::m_vertexShaderSourceSimple = QString(
|
||||||
"#version 150\n"
|
|
||||||
"uniform mat4 uMatrix;\n"
|
"uniform mat4 uMatrix;\n"
|
||||||
"in vec4 vertex\n"
|
"attribute vec4 vertex;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_Position = uMatrix * vertex;\n"
|
" gl_Position = uMatrix * vertex;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderSources::m_fragmentShaderSourceColored = QString(
|
const QString GLShaderSources::m_fragmentShaderSourceColored = QString(
|
||||||
"#version 150\n"
|
|
||||||
"uniform mediump vec4 uColour;\n"
|
"uniform mediump vec4 uColour;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_FragColor = uColour;\n"
|
" gl_FragColor = uColour;\n"
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QOpenGLShaderProgram>
|
||||||
#include "gui/glspectrum.h"
|
#include "gui/glspectrum.h"
|
||||||
|
#include "gui/glshadersources.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -58,7 +60,8 @@ GLSpectrum::GLSpectrum(QWidget* parent) :
|
|||||||
m_histogramHoldoff(NULL),
|
m_histogramHoldoff(NULL),
|
||||||
m_histogramTextureAllocated(false),
|
m_histogramTextureAllocated(false),
|
||||||
m_displayHistogram(true),
|
m_displayHistogram(true),
|
||||||
m_displayChanged(false)
|
m_displayChanged(false),
|
||||||
|
m_program(0)
|
||||||
{
|
{
|
||||||
setAutoFillBackground(false);
|
setAutoFillBackground(false);
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent, true);
|
setAttribute(Qt::WA_OpaquePaintEvent, true);
|
||||||
@ -110,6 +113,12 @@ GLSpectrum::GLSpectrum(QWidget* parent) :
|
|||||||
m_frequencyScale.setFont(font());
|
m_frequencyScale.setFont(font());
|
||||||
m_frequencyScale.setOrientation(Qt::Horizontal);
|
m_frequencyScale.setOrientation(Qt::Horizontal);
|
||||||
|
|
||||||
|
m_vao.create();
|
||||||
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
|
||||||
|
m_vbo.create();
|
||||||
|
m_vbo.bind();
|
||||||
|
// TODO: allocate VBO
|
||||||
|
|
||||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
m_timer.start(50);
|
m_timer.start(50);
|
||||||
}
|
}
|
||||||
@ -154,6 +163,10 @@ GLSpectrum::~GLSpectrum()
|
|||||||
deleteTexture(m_frequencyTexture);
|
deleteTexture(m_frequencyTexture);
|
||||||
m_frequencyTextureAllocated = false;
|
m_frequencyTextureAllocated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeCurrent(); // TODO: move to cleanup() wnem inheriting from QOpenGLWidget
|
||||||
|
m_vbo.destroy();
|
||||||
|
doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSpectrum::setCenterFrequency(quint64 frequency)
|
void GLSpectrum::setCenterFrequency(quint64 frequency)
|
||||||
@ -484,7 +497,18 @@ void GLSpectrum::updateHistogram(const std::vector<Real>& spectrum)
|
|||||||
|
|
||||||
void GLSpectrum::initializeGL()
|
void GLSpectrum::initializeGL()
|
||||||
{
|
{
|
||||||
|
//connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &GLSpectrum::cleanup); // TODO: when migrating to QOpenGLWidget
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
m_program = new QOpenGLShaderProgram;
|
||||||
|
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, GLShaderSources::getVertexShaderSourceSimple());
|
||||||
|
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, GLShaderSources::getFragmentShaderSourceColored());
|
||||||
|
m_program->bindAttributeLocation("vertex", 0);
|
||||||
|
m_program->link();
|
||||||
|
m_program->bind();
|
||||||
|
m_matrixLoc = m_program->uniformLocation("uMatrix");
|
||||||
|
m_colorLoc = m_program->uniformLocation("uColor");
|
||||||
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSpectrum::resizeGL(int width, int height)
|
void GLSpectrum::resizeGL(int width, int height)
|
||||||
@ -2041,3 +2065,14 @@ void GLSpectrum::connectTimer(const QTimer& timer)
|
|||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
m_timer.stop();
|
m_timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLSpectrum::cleanup()
|
||||||
|
{
|
||||||
|
makeCurrent();
|
||||||
|
if (m_program) {
|
||||||
|
delete m_program;
|
||||||
|
m_program = 0;
|
||||||
|
}
|
||||||
|
m_program = 0;
|
||||||
|
doneCurrent();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user