diff --git a/include/gui/glspectrum.h b/include/gui/glspectrum.h index 803b39f41..a31398c49 100644 --- a/include/gui/glspectrum.h +++ b/include/gui/glspectrum.h @@ -129,6 +129,8 @@ private: QRectF m_glLeftScaleRect; QRectF m_glFrequencyScaleRect; QRect m_frequencyScaleRect; + QMatrix4x4 m_glFrequencyScaleBoxMatrix; + QMatrix4x4 m_glLeftScaleBoxMatrix; QRgb m_waterfallPalette[240]; QImage* m_waterfallBuffer; @@ -138,6 +140,7 @@ private: int m_waterfallTextureHeight; int m_waterfallTexturePos; QRectF m_glWaterfallRect; + QMatrix4x4 m_glWaterfallBoxMatrix; bool m_displayWaterfall; bool m_ssbSpectrum; @@ -154,13 +157,11 @@ private: QRectF m_glHistogramRect; QMatrix4x4 m_glHistogramSpectrumMatrix; QMatrix4x4 m_glHistogramBoxMatrix; - GLShaderSimple m_glShaderSimple; bool m_displayHistogram; bool m_displayChanged; - //QOpenGLVertexArrayObject m_vao; don't know what to do with this shit - //QOpenGLBuffer m_vbo; + GLShaderSimple m_glShaderSimple; QOpenGLShaderProgram *m_program; int m_matrixLoc; int m_colorLoc; diff --git a/sdrbase/gui/glspectrum.cpp b/sdrbase/gui/glspectrum.cpp index ef1bee903..cb6c63630 100644 --- a/sdrbase/gui/glspectrum.cpp +++ b/sdrbase/gui/glspectrum.cpp @@ -1406,11 +1406,11 @@ void GLSpectrum::paintGL() #endif tickList = &m_frequencyScale.getTickList(); +#ifdef GL_DEPRECATED glPushMatrix(); glTranslatef(m_glHistogramRect.x(), m_glHistogramRect.y(), 0); glScalef(m_glHistogramRect.width(), m_glHistogramRect.height(), 1); -#ifdef GL_DEPRECATED for(int i= 0; i < tickList->count(); i++) { tick = &(*tickList)[i]; if(tick->major) { @@ -1423,14 +1423,21 @@ void GLSpectrum::paintGL() } } } + + glPopMatrix(); #else { GLfloat q3[4*tickList->count()]; int effectiveTicks = 0; - for(int i= 0; i < tickList->count(); i++) { + + for(int i= 0; i < tickList->count(); i++) + { tick = &(*tickList)[i]; - if(tick->major) { - if(tick->textSize > 0) { + + if(tick->major) + { + if(tick->textSize > 0) + { float x = tick->pos / m_frequencyScale.getSize(); q3[4*effectiveTicks] = x; q3[4*effectiveTicks+1] = 0; @@ -1440,24 +1447,14 @@ void GLSpectrum::paintGL() } } } -#ifdef GL_ANDROID - glEnableVertexAttribArray(GL_VERTEX_ARRAY); - glVertexAttribPointer(GL_VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, q3); - glDrawArrays(GL_LINES, 0, 2*effectiveTicks); - glDisableVertexAttribArray(GL_VERTEX_ARRAY); -#else - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, q3); - glDrawArrays(GL_LINES, 0, 2*effectiveTicks); - glDisableClientState(GL_VERTEX_ARRAY); -#endif + + QVector4D color(1.0f, 1.0f, 1.0f, (float) m_displayGridIntensity / 100.0f); + m_glShaderSimple.drawSegments(m_glHistogramBoxMatrix, color, q3, 2*effectiveTicks); } #endif - glPopMatrix(); } glPopMatrix(); - m_mutex.unlock(); } @@ -1493,6 +1490,7 @@ void GLSpectrum::applyChanges() int leftMargin; int rightMargin = fm.width("000"); + // displays both histogram and waterfall if(m_displayWaterfall && (m_displayHistogram | m_displayMaxHold | m_displayCurrent)) { waterfallHeight = height() * m_waterfallShare - 1; @@ -1558,6 +1556,16 @@ void GLSpectrum::applyChanges() (float)waterfallHeight / (float)height() ); + m_glWaterfallBoxMatrix.setToIdentity(); + m_glWaterfallBoxMatrix.translate( + -1.0f + ((float)(2*leftMargin) / (float) width()), + 1.0f - ((float)(2*waterfallTop) / (float) height()) + ); + m_glWaterfallBoxMatrix.scale( + ((float) 2 * (width() - leftMargin - rightMargin)) / (float) width(), + (float) (-2*waterfallHeight) / (float) height() + ); + m_glHistogramRect = QRectF( (float)leftMargin / (float)width(), (float)histogramTop / (float)height(), @@ -1565,16 +1573,6 @@ void GLSpectrum::applyChanges() (float)histogramHeight / (float)height() ); - m_glHistogramSpectrumMatrix.setToIdentity(); - m_glHistogramSpectrumMatrix.translate( - -1.0f + ((float)(2*leftMargin) / (float) width()), - 1.0f - ((float)(2*histogramTop) / (float) height()) - ); - m_glHistogramSpectrumMatrix.scale( - ((float) 2 * (width() - leftMargin - rightMargin)) / ((float) width() * (float)(m_fftSize - 1)), - ((float) 2*histogramHeight / height()) / m_powerRange - ); - m_glHistogramBoxMatrix.setToIdentity(); m_glHistogramBoxMatrix.translate( -1.0f + ((float)(2*leftMargin) / (float) width()), @@ -1585,6 +1583,16 @@ void GLSpectrum::applyChanges() (float) (-2*histogramHeight) / (float) height() ); + m_glHistogramSpectrumMatrix.setToIdentity(); + m_glHistogramSpectrumMatrix.translate( + -1.0f + ((float)(2*leftMargin) / (float) width()), + 1.0f - ((float)(2*histogramTop) / (float) height()) + ); + m_glHistogramSpectrumMatrix.scale( + ((float) 2 * (width() - leftMargin - rightMargin)) / ((float) width() * (float)(m_fftSize - 1)), + ((float) 2*histogramHeight / height()) / m_powerRange + ); + m_frequencyScaleRect = QRect( 0, frequencyScaleTop, @@ -1598,13 +1606,31 @@ void GLSpectrum::applyChanges() (float)frequencyScaleHeight / (float)height() ); + m_glFrequencyScaleBoxMatrix.setToIdentity(); + m_glFrequencyScaleBoxMatrix.translate ( + -1.0f, + 1.0f - ((float) 2*frequencyScaleTop / (float) height()) + ); + m_glFrequencyScaleBoxMatrix.scale ( + 2.0f, + (float) -2*frequencyScaleHeight / (float) height() + ); + m_glLeftScaleRect = QRectF( (float)0, (float)0, (float)(leftMargin - 1) / (float)width(), (float)1 ); + + m_glLeftScaleBoxMatrix.setToIdentity(); + m_glLeftScaleBoxMatrix.translate(-1.0f, 1.0f); + m_glLeftScaleBoxMatrix.scale( + (float)(2*(leftMargin - 1)) / (float) width(), + -2.0f + ); } + // displays waterfall only else if(m_displayWaterfall) { bottomMargin = frequencyScaleHeight; @@ -1653,6 +1679,16 @@ void GLSpectrum::applyChanges() (float)waterfallHeight / (float)height() ); + m_glWaterfallBoxMatrix.setToIdentity(); + m_glWaterfallBoxMatrix.translate( + -1.0f + ((float)(2*leftMargin) / (float) width()), + 1.0f - ((float)(2*topMargin) / (float) height()) + ); + m_glWaterfallBoxMatrix.scale( + ((float) 2 * (width() - leftMargin - rightMargin)) / (float) width(), + (float) (-2*waterfallHeight) / (float) height() + ); + m_frequencyScaleRect = QRect( 0, frequencyScaleTop, @@ -1666,13 +1702,31 @@ void GLSpectrum::applyChanges() (float)frequencyScaleHeight / (float)height() ); + m_glFrequencyScaleBoxMatrix.setToIdentity(); + m_glFrequencyScaleBoxMatrix.translate ( + -1.0f, + 1.0f - ((float) 2*frequencyScaleTop / (float) height()) + ); + m_glFrequencyScaleBoxMatrix.scale ( + 2.0f, + (float) -2*frequencyScaleHeight / (float) height() + ); + m_glLeftScaleRect = QRectF( (float)0, (float)0, (float)(leftMargin - 1) / (float)width(), (float)1 ); + + m_glLeftScaleBoxMatrix.setToIdentity(); + m_glLeftScaleBoxMatrix.translate(-1.0f, 1.0f); + m_glLeftScaleBoxMatrix.scale( + (float)(2*(leftMargin - 1)) / (float) width(), + -2.0f + ); } + // displays histogram only else if(m_displayHistogram || m_displayMaxHold || m_displayCurrent) { bottomMargin = frequencyScaleHeight; @@ -1696,6 +1750,26 @@ void GLSpectrum::applyChanges() (float)(height() - topMargin - frequencyScaleHeight) / (float)height() ); + m_glHistogramSpectrumMatrix.setToIdentity(); + m_glHistogramSpectrumMatrix.translate( + -1.0f + ((float)(2*leftMargin) / (float) width()), + 1.0f - ((float)(2*histogramTop) / (float) height()) + ); + m_glHistogramSpectrumMatrix.scale( + ((float) 2 * (width() - leftMargin - rightMargin)) / ((float) width() * (float)(m_fftSize - 1)), + ((float) 2*(height() - topMargin - frequencyScaleHeight) / height()) / m_powerRange + ); + + m_glHistogramBoxMatrix.setToIdentity(); + m_glHistogramBoxMatrix.translate( + -1.0f + ((float)(2*leftMargin) / (float) width()), + 1.0f - ((float)(2*histogramTop) / (float) height()) + ); + m_glHistogramBoxMatrix.scale( + ((float) 2 * (width() - leftMargin - rightMargin)) / (float) width(), + (float) (-2*(height() - topMargin - frequencyScaleHeight)) / (float) height() + ); + m_frequencyScaleRect = QRect( 0, frequencyScaleTop, @@ -1709,12 +1783,29 @@ void GLSpectrum::applyChanges() (float)frequencyScaleHeight / (float)height() ); + m_glFrequencyScaleBoxMatrix.setToIdentity(); + m_glFrequencyScaleBoxMatrix.translate ( + -1.0f, + 1.0f - ((float) 2*frequencyScaleTop / (float) height()) + ); + m_glFrequencyScaleBoxMatrix.scale ( + 2.0f, + (float) -2*frequencyScaleHeight / (float) height() + ); + m_glLeftScaleRect = QRectF( (float)0, (float)0, (float)(leftMargin - 1) / (float)width(), (float)1 ); + + m_glLeftScaleBoxMatrix.setToIdentity(); + m_glLeftScaleBoxMatrix.translate(-1.0f, 1.0f); + m_glLeftScaleBoxMatrix.scale( + (float)(2*(leftMargin - 1)) / (float) width(), + -2.0f + ); } else {