1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -05:00

OpenGL modernization: draw waterfall channel overlays the new way

This commit is contained in:
f4exb 2016-03-04 01:30:29 +01:00
parent a33eb6555f
commit a3627dffd9
2 changed files with 84 additions and 29 deletions

View File

@ -71,6 +71,8 @@ private:
ChannelMarker* m_channelMarker; ChannelMarker* m_channelMarker;
QRectF m_glRect; QRectF m_glRect;
QRectF m_glRectDsb; QRectF m_glRectDsb;
QMatrix4x4 m_glMatrixWaterfall;
QMatrix4x4 m_glMatrixDsbWaterfall;
QRect m_rect; QRect m_rect;
ChannelMarkerState(ChannelMarker* channelMarker) : ChannelMarkerState(ChannelMarker* channelMarker) :

View File

@ -620,10 +620,6 @@ void GLSpectrum::paintGL()
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glPopMatrix(); glPopMatrix();
glPushMatrix();
glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
// paint channels // paint channels
if (m_mouseInside) if (m_mouseInside)
{ {
@ -632,19 +628,28 @@ void GLSpectrum::paintGL()
ChannelMarkerState* dv = m_channelMarkerStates[i]; ChannelMarkerState* dv = m_channelMarkerStates[i];
if (dv->m_channelMarker->getVisible()) if (dv->m_channelMarker->getVisible())
{ {
#ifdef GL_DEPRECATED
glPushMatrix();
glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
glPushMatrix(); glPushMatrix();
glTranslatef(dv->m_glRect.x(), dv->m_glRect.y(), 0); glTranslatef(dv->m_glRect.x(), dv->m_glRect.y(), 0);
glScalef(dv->m_glRect.width(), dv->m_glRect.height(), 1); glScalef(dv->m_glRect.width(), dv->m_glRect.height(), 1);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.3f); glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.3f);
#ifdef GL_DEPRECATED
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(0, 0); glVertex2f(0, 0);
glVertex2f(1, 0); glVertex2f(1, 0);
glVertex2f(1, 1); glVertex2f(1, 1);
glVertex2f(0, 1); glVertex2f(0, 1);
glEnd(); glEnd();
glDisable(GL_BLEND);
glPopMatrix();
glPopMatrix();
#else #else
{ {
GLfloat q3[] { GLfloat q3[] {
@ -654,27 +659,32 @@ void GLSpectrum::paintGL()
0, 1 0, 1
}; };
#ifdef GL_ANDROID QVector4D color(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.3f);
glEnableVertexAttribArray(GL_VERTEX_ARRAY); m_glShaderSimple.drawSurface(dv->m_glMatrixWaterfall, color, q3, 4);
glVertexAttribPointer(GL_VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, q3);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); // glPushMatrix();
glDisableVertexAttribArray(GL_VERTEX_ARRAY); // glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
#else // glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
glEnableClientState(GL_VERTEX_ARRAY); // glPushMatrix();
glVertexPointer(2, GL_FLOAT, 0, q3); // glTranslatef(dv->m_glRect.x(), dv->m_glRect.y(), 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); // glScalef(dv->m_glRect.width(), dv->m_glRect.height(), 1);
glDisableClientState(GL_VERTEX_ARRAY); // glEnable(GL_BLEND);
#endif // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.3f);
//
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(2, GL_FLOAT, 0, q3);
// glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glDisable(GL_BLEND);
// glPopMatrix();
// glPopMatrix();
} }
#endif #endif
glDisable(GL_BLEND);
glPopMatrix();
} }
} }
} }
glPopMatrix();
// draw rect around // draw rect around
#ifdef GL_DEPRECATED #ifdef GL_DEPRECATED
glPushMatrix(); glPushMatrix();
@ -707,7 +717,6 @@ void GLSpectrum::paintGL()
m_glShaderSimple.drawContour(m_glWaterfallBoxMatrix, color, q3, 4); m_glShaderSimple.drawContour(m_glWaterfallBoxMatrix, color, q3, 4);
} }
#endif #endif
} }
// paint histogram // paint histogram
@ -1839,7 +1848,8 @@ void GLSpectrum::applyChanges()
} }
// channel overlays // channel overlays
for(int i = 0; i < m_channelMarkerStates.size(); ++i) { for(int i = 0; i < m_channelMarkerStates.size(); ++i)
{
ChannelMarkerState* dv = m_channelMarkerStates[i]; ChannelMarkerState* dv = m_channelMarkerStates[i];
qreal xc, pw, nw, dsbw; qreal xc, pw, nw, dsbw;
@ -1859,6 +1869,13 @@ void GLSpectrum::applyChanges()
} }
// draw the effective BW rectangle
dv->m_glRect.setRect(
m_frequencyScale.getPosFromValue(xc + nw) / (float)(width() - leftMargin - rightMargin),
0,
(pw-nw) / (float)m_sampleRate,
1);
// draw the DSB rectangle // draw the DSB rectangle
dv->m_glRectDsb.setRect( dv->m_glRectDsb.setRect(
m_frequencyScale.getPosFromValue(xc - (dsbw/2)) / (float)(width() - leftMargin - rightMargin), m_frequencyScale.getPosFromValue(xc - (dsbw/2)) / (float)(width() - leftMargin - rightMargin),
@ -1866,12 +1883,47 @@ void GLSpectrum::applyChanges()
dsbw / (float)m_sampleRate, dsbw / (float)m_sampleRate,
1); 1);
// draw the effective BW rectangle QMatrix4x4 glMatrixDsb;
dv->m_glRect.setRect( glMatrixDsb.setToIdentity();
m_frequencyScale.getPosFromValue(xc + nw) / (float)(width() - leftMargin - rightMargin), glMatrixDsb.translate(
0, -1.0f + 2.0f * ((leftMargin + m_frequencyScale.getPosFromValue(xc - (dsbw/2)) / (float) width())),
(pw-nw) / (float)m_sampleRate, 1.0f
1); );
glMatrixDsb.scale(
2.0f * (dsbw / (float)m_sampleRate),
-2.0f
);
dv->m_glMatrixDsbWaterfall = glMatrixDsb;
dv->m_glMatrixDsbWaterfall.translate(
0.0f,
(float) waterfallTop / (float) height()
);
dv->m_glMatrixDsbWaterfall.scale(
(float) (width() - leftMargin - rightMargin) / (float) width(),
(float) waterfallHeight / (float) height()
);
QMatrix4x4 glMatrix;
glMatrix.setToIdentity();
glMatrix.translate(
-1.0f + 2.0f * ((leftMargin + m_frequencyScale.getPosFromValue(xc + nw)) / (float) width()),
1.0f
);
glMatrix.scale(
2.0f * ((pw-nw) / (float)m_sampleRate),
-2.0f
);
dv->m_glMatrixWaterfall = glMatrix;
dv->m_glMatrixWaterfall.translate(
0.0f,
(float) waterfallTop / (float) height()
);
dv->m_glMatrixWaterfall.scale(
(float) (width() - leftMargin - rightMargin) / (float) width(),
(float) waterfallHeight / (float) height()
);
/* /*
dv->m_glRect.setRect( dv->m_glRect.setRect(
@ -1881,7 +1933,8 @@ void GLSpectrum::applyChanges()
1); 1);
*/ */
if(m_displayHistogram || m_displayMaxHold || m_displayCurrent || m_displayWaterfall) { if(m_displayHistogram || m_displayMaxHold || m_displayCurrent || m_displayWaterfall)
{
dv->m_rect.setRect(m_frequencyScale.getPosFromValue(xc) + leftMargin - 1, dv->m_rect.setRect(m_frequencyScale.getPosFromValue(xc) + leftMargin - 1,
topMargin, topMargin,
5, 5,