mirror of https://github.com/f4exb/sdrangel.git
OpenGL modernization: draw the histogram the new way
This commit is contained in:
parent
30c5b5f505
commit
9ea5ee3854
|
@ -22,10 +22,10 @@
|
||||||
#define INCLUDE_GUI_GLSHADERTEXTURED_H_
|
#define INCLUDE_GUI_GLSHADERTEXTURED_H_
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QOpenGLTexture>
|
||||||
|
|
||||||
class QOpenGLShaderProgram;
|
class QOpenGLShaderProgram;
|
||||||
class QMatrix4x4;
|
class QMatrix4x4;
|
||||||
class QOpenGLTexture;
|
|
||||||
class QImage;
|
class QImage;
|
||||||
|
|
||||||
class GLShaderTextured
|
class GLShaderTextured
|
||||||
|
@ -35,7 +35,7 @@ public:
|
||||||
~GLShaderTextured();
|
~GLShaderTextured();
|
||||||
|
|
||||||
void initializeGL();
|
void initializeGL();
|
||||||
void initTexture(const QImage& image);
|
void initTexture(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
||||||
void subTexture(int xOffset, int yOffset, int width, int height, const void *pixels);
|
void subTexture(int xOffset, int yOffset, int width, int height, const void *pixels);
|
||||||
void drawSurface(const QMatrix4x4& transformMatrix, GLfloat* textureCoords, GLfloat *vertices, int nbVertices);
|
void drawSurface(const QMatrix4x4& transformMatrix, GLfloat* textureCoords, GLfloat *vertices, int nbVertices);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
|
@ -166,13 +166,15 @@ private:
|
||||||
QImage* m_histogramBuffer;
|
QImage* m_histogramBuffer;
|
||||||
quint8* m_histogram;
|
quint8* m_histogram;
|
||||||
quint8* m_histogramHoldoff;
|
quint8* m_histogramHoldoff;
|
||||||
|
#ifdef GL_DEPRECATED
|
||||||
bool m_histogramTextureAllocated;
|
bool m_histogramTextureAllocated;
|
||||||
GLuint m_histogramTexture;
|
GLuint m_histogramTexture;
|
||||||
|
QRectF m_glHistogramRect;
|
||||||
|
#endif
|
||||||
int m_histogramHoldoffBase;
|
int m_histogramHoldoffBase;
|
||||||
int m_histogramHoldoffCount;
|
int m_histogramHoldoffCount;
|
||||||
int m_histogramLateHoldoff;
|
int m_histogramLateHoldoff;
|
||||||
int m_histogramStroke;
|
int m_histogramStroke;
|
||||||
QRectF m_glHistogramRect;
|
|
||||||
QMatrix4x4 m_glHistogramSpectrumMatrix;
|
QMatrix4x4 m_glHistogramSpectrumMatrix;
|
||||||
QMatrix4x4 m_glHistogramBoxMatrix;
|
QMatrix4x4 m_glHistogramBoxMatrix;
|
||||||
bool m_displayHistogram;
|
bool m_displayHistogram;
|
||||||
|
@ -183,6 +185,7 @@ private:
|
||||||
GLShaderTextured m_glShaderLeftScale;
|
GLShaderTextured m_glShaderLeftScale;
|
||||||
GLShaderTextured m_glShaderFrequencyScale;
|
GLShaderTextured m_glShaderFrequencyScale;
|
||||||
GLShaderTextured m_glShaderWaterfall;
|
GLShaderTextured m_glShaderWaterfall;
|
||||||
|
GLShaderTextured m_glShaderHistogram;
|
||||||
int m_matrixLoc;
|
int m_matrixLoc;
|
||||||
int m_colorLoc;
|
int m_colorLoc;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
#include <QOpenGLTexture>
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QVector4D>
|
#include <QVector4D>
|
||||||
|
@ -61,7 +60,7 @@ void GLShaderTextured::initializeGL()
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::initTexture(const QImage& image)
|
void GLShaderTextured::initTexture(const QImage& image, QOpenGLTexture::WrapMode wrapMode)
|
||||||
{
|
{
|
||||||
if (m_texture) {
|
if (m_texture) {
|
||||||
delete m_texture;
|
delete m_texture;
|
||||||
|
@ -71,7 +70,7 @@ void GLShaderTextured::initTexture(const QImage& image)
|
||||||
|
|
||||||
m_texture->setMinificationFilter(QOpenGLTexture::Linear);
|
m_texture->setMinificationFilter(QOpenGLTexture::Linear);
|
||||||
m_texture->setMagnificationFilter(QOpenGLTexture::Linear);
|
m_texture->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||||
m_texture->setWrapMode(QOpenGLTexture::Repeat);
|
m_texture->setWrapMode(wrapMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::subTexture(int xOffset, int yOffset, int width, int height, const void *pixels)
|
void GLShaderTextured::subTexture(int xOffset, int yOffset, int width, int height, const void *pixels)
|
||||||
|
|
|
@ -52,6 +52,7 @@ GLSpectrum::GLSpectrum(QWidget* parent) :
|
||||||
m_leftMarginTextureAllocated(false),
|
m_leftMarginTextureAllocated(false),
|
||||||
m_frequencyTextureAllocated(false),
|
m_frequencyTextureAllocated(false),
|
||||||
m_waterfallTextureAllocated(false),
|
m_waterfallTextureAllocated(false),
|
||||||
|
m_histogramTextureAllocated(false),
|
||||||
#endif
|
#endif
|
||||||
m_waterfallBuffer(NULL),
|
m_waterfallBuffer(NULL),
|
||||||
m_waterfallTextureHeight(-1),
|
m_waterfallTextureHeight(-1),
|
||||||
|
@ -60,7 +61,6 @@ GLSpectrum::GLSpectrum(QWidget* parent) :
|
||||||
m_histogramBuffer(NULL),
|
m_histogramBuffer(NULL),
|
||||||
m_histogram(NULL),
|
m_histogram(NULL),
|
||||||
m_histogramHoldoff(NULL),
|
m_histogramHoldoff(NULL),
|
||||||
m_histogramTextureAllocated(false),
|
|
||||||
m_displayHistogram(true),
|
m_displayHistogram(true),
|
||||||
m_displayChanged(false)
|
m_displayChanged(false)
|
||||||
{
|
{
|
||||||
|
@ -147,12 +147,12 @@ GLSpectrum::~GLSpectrum()
|
||||||
delete[] m_histogramHoldoff;
|
delete[] m_histogramHoldoff;
|
||||||
m_histogramHoldoff = NULL;
|
m_histogramHoldoff = NULL;
|
||||||
}
|
}
|
||||||
|
#ifdef GL_DEPRECATED
|
||||||
if(m_histogramTextureAllocated) {
|
if(m_histogramTextureAllocated) {
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
deleteTexture(m_histogramTexture);
|
deleteTexture(m_histogramTexture);
|
||||||
m_histogramTextureAllocated = false;
|
m_histogramTextureAllocated = false;
|
||||||
}
|
}
|
||||||
#ifdef GL_DEPRECATED
|
|
||||||
if(m_leftMarginTextureAllocated) {
|
if(m_leftMarginTextureAllocated) {
|
||||||
deleteTexture(m_leftMarginTexture);
|
deleteTexture(m_leftMarginTexture);
|
||||||
m_leftMarginTextureAllocated = false;
|
m_leftMarginTextureAllocated = false;
|
||||||
|
@ -515,6 +515,7 @@ void GLSpectrum::initializeGL()
|
||||||
m_glShaderLeftScale.initializeGL();
|
m_glShaderLeftScale.initializeGL();
|
||||||
m_glShaderFrequencyScale.initializeGL();
|
m_glShaderFrequencyScale.initializeGL();
|
||||||
m_glShaderWaterfall.initializeGL();
|
m_glShaderWaterfall.initializeGL();
|
||||||
|
m_glShaderHistogram.initializeGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSpectrum::resizeGL(int width, int height)
|
void GLSpectrum::resizeGL(int width, int height)
|
||||||
|
@ -725,12 +726,13 @@ void GLSpectrum::paintGL()
|
||||||
// paint histogram
|
// paint histogram
|
||||||
if(m_displayHistogram || m_displayMaxHold || m_displayCurrent)
|
if(m_displayHistogram || m_displayMaxHold || m_displayCurrent)
|
||||||
{
|
{
|
||||||
|
if(m_displayHistogram)
|
||||||
|
{
|
||||||
|
#ifdef GL_DEPRECATED
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(m_glHistogramRect.x(), m_glHistogramRect.y(), 0);
|
glTranslatef(m_glHistogramRect.x(), m_glHistogramRect.y(), 0);
|
||||||
glScalef(m_glHistogramRect.width(), m_glHistogramRect.height(), 1);
|
glScalef(m_glHistogramRect.width(), m_glHistogramRect.height(), 1);
|
||||||
|
|
||||||
if(m_displayHistogram)
|
|
||||||
{
|
|
||||||
// import new lines into the texture
|
// import new lines into the texture
|
||||||
quint32* pix;
|
quint32* pix;
|
||||||
quint8* bs = m_histogram;
|
quint8* bs = m_histogram;
|
||||||
|
@ -753,7 +755,7 @@ void GLSpectrum::paintGL()
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_fftSize, 100, GL_RGBA, GL_UNSIGNED_BYTE, m_histogramBuffer->scanLine(0));
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_fftSize, 100, GL_RGBA, GL_UNSIGNED_BYTE, m_histogramBuffer->scanLine(0));
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
#ifdef GL_DEPRECATED
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2f(0, 0);
|
glTexCoord2f(0, 0);
|
||||||
glVertex2f(0, 0);
|
glVertex2f(0, 0);
|
||||||
|
@ -764,8 +766,30 @@ void GLSpectrum::paintGL()
|
||||||
glTexCoord2f(0, 1);
|
glTexCoord2f(0, 1);
|
||||||
glVertex2f(0, 1);
|
glVertex2f(0, 1);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glPopMatrix();
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
// import new lines into the texture
|
||||||
|
quint32* pix;
|
||||||
|
quint8* bs = m_histogram;
|
||||||
|
|
||||||
|
for (int y = 0; y < 100; y++)
|
||||||
|
{
|
||||||
|
quint8* b = bs;
|
||||||
|
pix = (quint32*)m_histogramBuffer->scanLine(99 - y);
|
||||||
|
|
||||||
|
for (int x = 0; x < m_fftSize; x++)
|
||||||
|
{
|
||||||
|
*pix = m_histogramPalette[*b];
|
||||||
|
pix++;
|
||||||
|
b += 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
bs++;
|
||||||
|
}
|
||||||
|
|
||||||
GLfloat vtx1[] = {
|
GLfloat vtx1[] = {
|
||||||
0, 0,
|
0, 0,
|
||||||
1, 0,
|
1, 0,
|
||||||
|
@ -778,29 +802,13 @@ void GLSpectrum::paintGL()
|
||||||
1, 1,
|
1, 1,
|
||||||
0, 1
|
0, 1
|
||||||
};
|
};
|
||||||
#ifdef GL_ANDROID
|
|
||||||
glEnableVertexAttribArray(GL_VERTEX_ARRAY);
|
m_glShaderHistogram.subTexture(0, 0, m_fftSize, 100, m_histogramBuffer->scanLine(0));
|
||||||
glEnableVertexAttribArray(GL_TEXTURE_COORD_ARRAY);
|
m_glShaderHistogram.drawSurface(m_glHistogramBoxMatrix, tex1, vtx1, 4);
|
||||||
glVertexAttribPointer(GL_VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, vtx1);
|
|
||||||
glVertexAttribPointer(GL_TEXTURE_COORD_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, tex1);
|
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
||||||
glDisableVertexAttribArray(GL_VERTEX_ARRAY);
|
|
||||||
glDisableVertexAttribArray(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
#else
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glVertexPointer(2, GL_FLOAT, 0, vtx1);
|
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, tex1);
|
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
// paint channels
|
// paint channels
|
||||||
if(m_mouseInside)
|
if(m_mouseInside)
|
||||||
|
@ -1497,14 +1505,14 @@ void GLSpectrum::applyChanges()
|
||||||
((float) 2 * (width() - leftMargin - rightMargin)) / (float) width(),
|
((float) 2 * (width() - leftMargin - rightMargin)) / (float) width(),
|
||||||
(float) (-2*waterfallHeight) / (float) height()
|
(float) (-2*waterfallHeight) / (float) height()
|
||||||
);
|
);
|
||||||
|
#ifdef GL_DEPRACATED
|
||||||
m_glHistogramRect = QRectF(
|
m_glHistogramRect = QRectF(
|
||||||
(float)leftMargin / (float)width(),
|
(float)leftMargin / (float)width(),
|
||||||
(float)histogramTop / (float)height(),
|
(float)histogramTop / (float)height(),
|
||||||
(float)(width() - leftMargin - rightMargin) / (float)width(),
|
(float)(width() - leftMargin - rightMargin) / (float)width(),
|
||||||
(float)histogramHeight / (float)height()
|
(float)histogramHeight / (float)height()
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
m_glHistogramBoxMatrix.setToIdentity();
|
m_glHistogramBoxMatrix.setToIdentity();
|
||||||
m_glHistogramBoxMatrix.translate(
|
m_glHistogramBoxMatrix.translate(
|
||||||
-1.0f + ((float)(2*leftMargin) / (float) width()),
|
-1.0f + ((float)(2*leftMargin) / (float) width()),
|
||||||
|
@ -1680,14 +1688,14 @@ void GLSpectrum::applyChanges()
|
||||||
|
|
||||||
m_frequencyScale.setSize(width() - leftMargin - rightMargin);
|
m_frequencyScale.setSize(width() - leftMargin - rightMargin);
|
||||||
m_frequencyScale.setRange(Unit::Frequency, m_centerFrequency - m_sampleRate / 2, m_centerFrequency + m_sampleRate / 2);
|
m_frequencyScale.setRange(Unit::Frequency, m_centerFrequency - m_sampleRate / 2, m_centerFrequency + m_sampleRate / 2);
|
||||||
|
#ifdef GL_DEPRECATED
|
||||||
m_glHistogramRect = QRectF(
|
m_glHistogramRect = QRectF(
|
||||||
(float)leftMargin / (float)width(),
|
(float)leftMargin / (float)width(),
|
||||||
(float)histogramTop / (float)height(),
|
(float)histogramTop / (float)height(),
|
||||||
(float)(width() - leftMargin - rightMargin) / (float)width(),
|
(float)(width() - leftMargin - rightMargin) / (float)width(),
|
||||||
(float)(height() - topMargin - frequencyScaleHeight) / (float)height()
|
(float)(height() - topMargin - frequencyScaleHeight) / (float)height()
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
m_glHistogramSpectrumMatrix.setToIdentity();
|
m_glHistogramSpectrumMatrix.setToIdentity();
|
||||||
m_glHistogramSpectrumMatrix.translate(
|
m_glHistogramSpectrumMatrix.translate(
|
||||||
-1.0f + ((float)(2*leftMargin) / (float) width()),
|
-1.0f + ((float)(2*leftMargin) / (float) width()),
|
||||||
|
@ -2005,11 +2013,11 @@ void GLSpectrum::applyChanges()
|
||||||
glGenTextures(1, &m_waterfallTexture);
|
glGenTextures(1, &m_waterfallTexture);
|
||||||
m_waterfallTextureAllocated = true;
|
m_waterfallTextureAllocated = true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if(!m_histogramTextureAllocated) {
|
if(!m_histogramTextureAllocated) {
|
||||||
glGenTextures(1, &m_histogramTexture);
|
glGenTextures(1, &m_histogramTexture);
|
||||||
m_histogramTextureAllocated = true;
|
m_histogramTextureAllocated = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool fftSizeChanged = true;
|
bool fftSizeChanged = true;
|
||||||
|
|
||||||
|
@ -2072,9 +2080,14 @@ void GLSpectrum::applyChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_histogramBuffer = new QImage(m_fftSize, 100, QImage::Format_RGB32);
|
m_histogramBuffer = new QImage(m_fftSize, 100, QImage::Format_RGB32);
|
||||||
if(m_histogramBuffer != NULL) {
|
|
||||||
|
if(m_histogramBuffer != NULL)
|
||||||
|
{
|
||||||
m_histogramBuffer->fill(qRgb(0x00, 0x00, 0x00));
|
m_histogramBuffer->fill(qRgb(0x00, 0x00, 0x00));
|
||||||
} else {
|
m_glShaderHistogram.initTexture(*m_histogramBuffer, QOpenGLTexture::ClampToEdge);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_fftSize = 0;
|
m_fftSize = 0;
|
||||||
m_changesPending = true;
|
m_changesPending = true;
|
||||||
return;
|
return;
|
||||||
|
@ -2085,22 +2098,24 @@ void GLSpectrum::applyChanges()
|
||||||
m_histogramHoldoff = new quint8[100 * m_fftSize];
|
m_histogramHoldoff = new quint8[100 * m_fftSize];
|
||||||
memset(m_histogramHoldoff, 0x07, 100 * m_fftSize);
|
memset(m_histogramHoldoff, 0x07, 100 * m_fftSize);
|
||||||
|
|
||||||
|
#ifdef GL_DEPRECATED
|
||||||
quint8* data = new quint8[m_fftSize * 100 * 4];
|
quint8* data = new quint8[m_fftSize * 100 * 4];
|
||||||
memset(data, 0x00, m_fftSize * 100 * 4);
|
memset(data, 0x00, m_fftSize * 100 * 4);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_histogramTexture);
|
glBindTexture(GL_TEXTURE_2D, m_histogramTexture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_fftSize, 100, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_fftSize, 100, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
delete[] data;
|
delete[] data;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fftSizeChanged || windowSizeChanged) {
|
if(fftSizeChanged || windowSizeChanged) {
|
||||||
m_waterfallTextureHeight = waterfallHeight;
|
m_waterfallTextureHeight = waterfallHeight;
|
||||||
|
#ifdef GL_DEPRECATED
|
||||||
quint8* data = new quint8[m_fftSize * m_waterfallTextureHeight * 4];
|
quint8* data = new quint8[m_fftSize * m_waterfallTextureHeight * 4];
|
||||||
memset(data, 0x00, m_fftSize * m_waterfallTextureHeight * 4);
|
memset(data, 0x00, m_fftSize * m_waterfallTextureHeight * 4);
|
||||||
#ifdef GL_DEPRECATED
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_waterfallTexture);
|
glBindTexture(GL_TEXTURE_2D, m_waterfallTexture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_fftSize, m_waterfallTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_fftSize, m_waterfallTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
#endif
|
|
||||||
delete[] data;
|
delete[] data;
|
||||||
|
#endif
|
||||||
m_waterfallTexturePos = 0;
|
m_waterfallTexturePos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue