1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-17 23:28:50 -05:00

OpenGL modernization: generalize simple shader program class

This commit is contained in:
f4exb 2016-03-03 01:09:55 +01:00
parent 7d0fe882d7
commit 34df31ad27
5 changed files with 46 additions and 22 deletions

View File

@ -117,7 +117,7 @@ set(sdrbase_SOURCES
sdrbase/gui/colormapper.cpp
sdrbase/gui/glscope.cpp
sdrbase/gui/glscopegui.cpp
sdrbase/gui/glshadersimplepolyline.cpp
sdrbase/gui/glshadersimple.cpp
sdrbase/gui/glspectrum.cpp
sdrbase/gui/glspectrumgui.cpp
sdrbase/gui/indicator.cpp
@ -200,7 +200,7 @@ set(sdrbase_HEADERS
include/gui/colormapper.h
include/gui/glscope.h
include/gui/glscopegui.h
include/gui/glshadersimplepolyline.h
include/gui/glshadersimple.h
include/gui/glspectrum.h
include/gui/glspectrumgui.h
include/gui/indicator.h

View File

@ -24,17 +24,22 @@ class QOpenGLShaderProgram;
class QMatrix4x4;
class QVector4D;
class GLShaderSimplePolyline
class GLShaderSimple
{
public:
GLShaderSimplePolyline();
~GLShaderSimplePolyline();
GLShaderSimple();
~GLShaderSimple();
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();
private:
void draw(unsigned int mode, const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices);
QOpenGLShaderProgram *m_program;
int m_matrixLoc;
int m_colorLoc;

View File

@ -26,7 +26,7 @@
#include <QMatrix4x4>
#include "dsp/dsptypes.h"
#include "gui/scaleengine.h"
#include "gui/glshadersimplepolyline.h"
#include "gui/glshadersimple.h"
#include "dsp/channelmarker.h"
#include "util/export.h"
@ -153,7 +153,7 @@ private:
int m_histogramStroke;
QRectF m_glHistogramRect;
QMatrix4x4 m_glHistogramMatrix;
GLShaderSimplePolyline m_glShaderSimplePolyline;
GLShaderSimple m_glShaderSimple;
bool m_displayHistogram;
bool m_displayChanged;

View File

@ -21,18 +21,18 @@
#include <QMatrix4x4>
#include <QVector4D>
#include <gui/glshadersimplepolyline.h>
#include "gui/glshadersimple.h"
GLShaderSimplePolyline::GLShaderSimplePolyline() :
GLShaderSimple::GLShaderSimple() :
m_program(0)
{ }
GLShaderSimplePolyline::~GLShaderSimplePolyline()
GLShaderSimple::~GLShaderSimple()
{
cleanup();
}
void GLShaderSimplePolyline::initializeGL()
void GLShaderSimple::initializeGL()
{
m_program = new QOpenGLShaderProgram;
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple);
@ -45,7 +45,27 @@ void GLShaderSimplePolyline::initializeGL()
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();
m_program->bind();
@ -56,12 +76,12 @@ void GLShaderSimplePolyline::draw(const QMatrix4x4& transformMatrix, const QVect
f->glLineWidth(1.0f);
f->glEnableVertexAttribArray(0); // vertex
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);
m_program->release();
}
void GLShaderSimplePolyline::cleanup()
void GLShaderSimple::cleanup()
{
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"
"attribute vec4 vertex;\n"
"void main() {\n"
@ -78,7 +98,7 @@ const QString GLShaderSimplePolyline::m_vertexShaderSourceSimple = QString(
"}\n"
);
const QString GLShaderSimplePolyline::m_fragmentShaderSourceColored = QString(
const QString GLShaderSimple::m_fragmentShaderSourceColored = QString(
"uniform mediump vec4 uColour;\n"
"void main() {\n"
" gl_FragColor = uColour;\n"

View File

@ -23,7 +23,6 @@
#include <QOpenGLShaderProgram>
#include <QOpenGLFunctions>
#include "gui/glspectrum.h"
#include <gui/glshadersimplepolyline.h>
#include <QDebug>
@ -507,7 +506,7 @@ void GLSpectrum::initializeGL()
connect(glCurrentContext, &QOpenGLContext::aboutToBeDestroyed, this, &GLSpectrum::cleanup); // TODO: when migrating to QOpenGLWidget
glDisable(GL_DEPTH_TEST);
m_glShaderSimplePolyline.initializeGL();
m_glShaderSimple.initializeGL();
}
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);
m_glShaderSimplePolyline.draw(m_glHistogramMatrix, color, q3, m_fftSize);
m_glShaderSimple.drawPolyline(m_glHistogramMatrix, color, q3, m_fftSize);
}
#endif
}
@ -1226,7 +1225,7 @@ void GLSpectrum::paintGL()
}
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
}
@ -2081,6 +2080,6 @@ void GLSpectrum::connectTimer(const QTimer& timer)
void GLSpectrum::cleanup()
{
makeCurrent();
m_glShaderSimplePolyline.cleanup();
m_glShaderSimple.cleanup();
doneCurrent();
}