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