mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-17 13:51:47 -05:00
OpenGL modernization: generalize simple shader program class
This commit is contained in:
parent
7d0fe882d7
commit
34df31ad27
@ -117,7 +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/glshadersimplepolyline.cpp
|
sdrbase/gui/glshadersimple.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
|
||||||
@ -200,7 +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/glshadersimplepolyline.h
|
include/gui/glshadersimple.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
|
||||||
|
@ -24,17 +24,22 @@ class QOpenGLShaderProgram;
|
|||||||
class QMatrix4x4;
|
class QMatrix4x4;
|
||||||
class QVector4D;
|
class QVector4D;
|
||||||
|
|
||||||
class GLShaderSimplePolyline
|
class GLShaderSimple
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLShaderSimplePolyline();
|
GLShaderSimple();
|
||||||
~GLShaderSimplePolyline();
|
~GLShaderSimple();
|
||||||
|
|
||||||
void initializeGL();
|
void initializeGL();
|
||||||
void draw(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices);
|
void drawPolyline(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices);
|
||||||
|
void drawSegments(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices);
|
||||||
|
void drawContour(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices);
|
||||||
|
void drawSurface(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void draw(unsigned int mode, const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices);
|
||||||
|
|
||||||
QOpenGLShaderProgram *m_program;
|
QOpenGLShaderProgram *m_program;
|
||||||
int m_matrixLoc;
|
int m_matrixLoc;
|
||||||
int m_colorLoc;
|
int m_colorLoc;
|
@ -26,7 +26,7 @@
|
|||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include "dsp/dsptypes.h"
|
#include "dsp/dsptypes.h"
|
||||||
#include "gui/scaleengine.h"
|
#include "gui/scaleengine.h"
|
||||||
#include "gui/glshadersimplepolyline.h"
|
#include "gui/glshadersimple.h"
|
||||||
#include "dsp/channelmarker.h"
|
#include "dsp/channelmarker.h"
|
||||||
#include "util/export.h"
|
#include "util/export.h"
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ private:
|
|||||||
int m_histogramStroke;
|
int m_histogramStroke;
|
||||||
QRectF m_glHistogramRect;
|
QRectF m_glHistogramRect;
|
||||||
QMatrix4x4 m_glHistogramMatrix;
|
QMatrix4x4 m_glHistogramMatrix;
|
||||||
GLShaderSimplePolyline m_glShaderSimplePolyline;
|
GLShaderSimple m_glShaderSimple;
|
||||||
bool m_displayHistogram;
|
bool m_displayHistogram;
|
||||||
|
|
||||||
bool m_displayChanged;
|
bool m_displayChanged;
|
||||||
|
@ -21,18 +21,18 @@
|
|||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QVector4D>
|
#include <QVector4D>
|
||||||
|
|
||||||
#include <gui/glshadersimplepolyline.h>
|
#include "gui/glshadersimple.h"
|
||||||
|
|
||||||
GLShaderSimplePolyline::GLShaderSimplePolyline() :
|
GLShaderSimple::GLShaderSimple() :
|
||||||
m_program(0)
|
m_program(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
GLShaderSimplePolyline::~GLShaderSimplePolyline()
|
GLShaderSimple::~GLShaderSimple()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimplePolyline::initializeGL()
|
void GLShaderSimple::initializeGL()
|
||||||
{
|
{
|
||||||
m_program = new QOpenGLShaderProgram;
|
m_program = new QOpenGLShaderProgram;
|
||||||
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple);
|
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple);
|
||||||
@ -45,7 +45,27 @@ void GLShaderSimplePolyline::initializeGL()
|
|||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimplePolyline::draw(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices)
|
void GLShaderSimple::drawPolyline(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices)
|
||||||
|
{
|
||||||
|
draw(GL_LINE_STRIP, transformMatrix, color, vertices, nbVertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLShaderSimple::drawSegments(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices)
|
||||||
|
{
|
||||||
|
draw(GL_LINES, transformMatrix, color, vertices, nbVertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLShaderSimple::drawContour(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices)
|
||||||
|
{
|
||||||
|
draw(GL_LINE_LOOP, transformMatrix, color, vertices, nbVertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLShaderSimple::drawSurface(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices)
|
||||||
|
{
|
||||||
|
draw(GL_TRIANGLE_FAN, transformMatrix, color, vertices, nbVertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLShaderSimple::draw(unsigned int mode, const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices)
|
||||||
{
|
{
|
||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
@ -56,12 +76,12 @@ void GLShaderSimplePolyline::draw(const QMatrix4x4& transformMatrix, const QVect
|
|||||||
f->glLineWidth(1.0f);
|
f->glLineWidth(1.0f);
|
||||||
f->glEnableVertexAttribArray(0); // vertex
|
f->glEnableVertexAttribArray(0); // vertex
|
||||||
f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||||
f->glDrawArrays(GL_LINE_STRIP, 0, nbVertices);
|
f->glDrawArrays(mode, 0, nbVertices);
|
||||||
f->glDisableVertexAttribArray(0);
|
f->glDisableVertexAttribArray(0);
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimplePolyline::cleanup()
|
void GLShaderSimple::cleanup()
|
||||||
{
|
{
|
||||||
if (m_program)
|
if (m_program)
|
||||||
{
|
{
|
||||||
@ -70,7 +90,7 @@ void GLShaderSimplePolyline::cleanup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString GLShaderSimplePolyline::m_vertexShaderSourceSimple = QString(
|
const QString GLShaderSimple::m_vertexShaderSourceSimple = QString(
|
||||||
"uniform mat4 uMatrix;\n"
|
"uniform mat4 uMatrix;\n"
|
||||||
"attribute vec4 vertex;\n"
|
"attribute vec4 vertex;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
@ -78,7 +98,7 @@ const QString GLShaderSimplePolyline::m_vertexShaderSourceSimple = QString(
|
|||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderSimplePolyline::m_fragmentShaderSourceColored = QString(
|
const QString GLShaderSimple::m_fragmentShaderSourceColored = QString(
|
||||||
"uniform mediump vec4 uColour;\n"
|
"uniform mediump vec4 uColour;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_FragColor = uColour;\n"
|
" gl_FragColor = uColour;\n"
|
@ -23,7 +23,6 @@
|
|||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
#include "gui/glspectrum.h"
|
#include "gui/glspectrum.h"
|
||||||
#include <gui/glshadersimplepolyline.h>
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -507,7 +506,7 @@ void GLSpectrum::initializeGL()
|
|||||||
|
|
||||||
connect(glCurrentContext, &QOpenGLContext::aboutToBeDestroyed, this, &GLSpectrum::cleanup); // TODO: when migrating to QOpenGLWidget
|
connect(glCurrentContext, &QOpenGLContext::aboutToBeDestroyed, this, &GLSpectrum::cleanup); // TODO: when migrating to QOpenGLWidget
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
m_glShaderSimplePolyline.initializeGL();
|
m_glShaderSimple.initializeGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSpectrum::resizeGL(int width, int height)
|
void GLSpectrum::resizeGL(int width, int height)
|
||||||
@ -1162,7 +1161,7 @@ void GLSpectrum::paintGL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVector4D color(1.0f, 0.0f, 0.0f, (float) m_displayTraceIntensity / 100.0f);
|
QVector4D color(1.0f, 0.0f, 0.0f, (float) m_displayTraceIntensity / 100.0f);
|
||||||
m_glShaderSimplePolyline.draw(m_glHistogramMatrix, color, q3, m_fftSize);
|
m_glShaderSimple.drawPolyline(m_glHistogramMatrix, color, q3, m_fftSize);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1226,7 +1225,7 @@ void GLSpectrum::paintGL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVector4D color(1.0f, 1.0f, 0.25f, (float) m_displayTraceIntensity / 100.0f);
|
QVector4D color(1.0f, 1.0f, 0.25f, (float) m_displayTraceIntensity / 100.0f);
|
||||||
m_glShaderSimplePolyline.draw(m_glHistogramMatrix, color, q3, m_fftSize);
|
m_glShaderSimple.drawPolyline(m_glHistogramMatrix, color, q3, m_fftSize);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2081,6 +2080,6 @@ void GLSpectrum::connectTimer(const QTimer& timer)
|
|||||||
void GLSpectrum::cleanup()
|
void GLSpectrum::cleanup()
|
||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
m_glShaderSimplePolyline.cleanup();
|
m_glShaderSimple.cleanup();
|
||||||
doneCurrent();
|
doneCurrent();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user