1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00

OpenGL modernization: draw waterfall grid frequency lines the new way

This commit is contained in:
f4exb 2016-03-03 22:45:43 +01:00
parent 6c48fbb6ac
commit 5bc899f9c6

View File

@ -549,7 +549,8 @@ void GLSpectrum::paintGL()
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
// paint waterfall // paint waterfall
if(m_displayWaterfall) { if (m_displayWaterfall)
{
glPushMatrix(); glPushMatrix();
glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0); glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1); glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
@ -559,14 +560,18 @@ void GLSpectrum::paintGL()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
for(int i = 0; i < m_waterfallBufferPos; i++) { for(int i = 0; i < m_waterfallBufferPos; i++) {
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_waterfallTexturePos, m_fftSize, 1, GL_RGBA, GL_UNSIGNED_BYTE, m_waterfallBuffer->scanLine(i)); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_waterfallTexturePos, m_fftSize, 1, GL_RGBA, GL_UNSIGNED_BYTE, m_waterfallBuffer->scanLine(i));
m_waterfallTexturePos = (m_waterfallTexturePos + 1) % m_waterfallTextureHeight; m_waterfallTexturePos = (m_waterfallTexturePos + 1) % m_waterfallTextureHeight;
} }
m_waterfallBufferPos = 0; m_waterfallBufferPos = 0;
float prop_y = m_waterfallTexturePos / (m_waterfallTextureHeight - 1.0); float prop_y = m_waterfallTexturePos / (m_waterfallTextureHeight - 1.0);
float off = 1.0 / (m_waterfallTextureHeight - 1.0); float off = 1.0 / (m_waterfallTextureHeight - 1.0);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
#ifdef GL_DEPRECATED #ifdef GL_DEPRECATED
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, prop_y + 1 - off); glTexCoord2f(0, prop_y + 1 - off);
@ -613,11 +618,20 @@ void GLSpectrum::paintGL()
} }
#endif #endif
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
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)
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];
if(dv->m_channelMarker->getVisible()) { if (dv->m_channelMarker->getVisible())
{
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);
@ -659,6 +673,12 @@ void GLSpectrum::paintGL()
} }
} }
glPopMatrix();
glPushMatrix();
glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
// draw rect around // draw rect around
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -699,11 +719,14 @@ void GLSpectrum::paintGL()
} }
// paint histogram // paint histogram
if(m_displayHistogram || m_displayMaxHold || m_displayCurrent) { if(m_displayHistogram || m_displayMaxHold || m_displayCurrent)
{
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) {
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;
@ -773,12 +796,21 @@ void GLSpectrum::paintGL()
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} }
glPopMatrix();
glPushMatrix();
glTranslatef(m_glHistogramRect.x(), m_glHistogramRect.y(), 0);
glScalef(m_glHistogramRect.width(), m_glHistogramRect.height(), 1);
// paint channels // paint channels
if(m_mouseInside) { if(m_mouseInside)
{
// Effective BW overlays // Effective BW 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];
if(dv->m_channelMarker->getVisible()) { if(dv->m_channelMarker->getVisible())
{
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);
@ -819,9 +851,11 @@ void GLSpectrum::paintGL()
} }
// Center line overlays based on DSB enveloppe // Center line overlays based on DSB enveloppe
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];
if(dv->m_channelMarker->getVisible()) { if(dv->m_channelMarker->getVisible())
{
glPushMatrix(); glPushMatrix();
glTranslatef(dv->m_glRectDsb.x(), dv->m_glRectDsb.y(), 0); glTranslatef(dv->m_glRectDsb.x(), dv->m_glRectDsb.y(), 0);
glScalef(dv->m_glRectDsb.width(), dv->m_glRectDsb.height(), 1); glScalef(dv->m_glRectDsb.width(), dv->m_glRectDsb.height(), 1);
@ -891,7 +925,8 @@ void GLSpectrum::paintGL()
} }
// paint left scales (time and power) // paint left scales (time and power)
if(m_displayWaterfall || m_displayMaxHold || m_displayCurrent || m_displayHistogram ) { if (m_displayWaterfall || m_displayMaxHold || m_displayCurrent || m_displayHistogram )
{
glPushMatrix(); glPushMatrix();
glTranslatef(m_glLeftScaleRect.x(), m_glLeftScaleRect.y(), 0); glTranslatef(m_glLeftScaleRect.x(), m_glLeftScaleRect.y(), 0);
glScalef(m_glLeftScaleRect.width(), m_glLeftScaleRect.height(), 1); glScalef(m_glLeftScaleRect.width(), m_glLeftScaleRect.height(), 1);
@ -952,7 +987,8 @@ void GLSpectrum::paintGL()
} }
// paint frequency scale // paint frequency scale
if(m_displayWaterfall || m_displayMaxHold || m_displayCurrent || m_displayHistogram ) { if (m_displayWaterfall || m_displayMaxHold || m_displayCurrent || m_displayHistogram )
{
glPushMatrix(); glPushMatrix();
glTranslatef(m_glFrequencyScaleRect.x(), m_glFrequencyScaleRect.y(), 0); glTranslatef(m_glFrequencyScaleRect.x(), m_glFrequencyScaleRect.y(), 0);
glScalef(m_glFrequencyScaleRect.width(), m_glFrequencyScaleRect.height(), 1); glScalef(m_glFrequencyScaleRect.width(), m_glFrequencyScaleRect.height(), 1);
@ -1019,9 +1055,11 @@ void GLSpectrum::paintGL()
glScalef(m_glWaterfallRect.width(), m_glFrequencyScaleRect.height(), 1); glScalef(m_glWaterfallRect.width(), m_glFrequencyScaleRect.height(), 1);
// Effective bandwidth overlays // Effective bandwidth 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];
if(dv->m_channelMarker->getVisible()) { if(dv->m_channelMarker->getVisible())
{
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);
@ -1062,10 +1100,13 @@ void GLSpectrum::paintGL()
} }
// Center frequency mark on highlighted channels based on DSB enveloppe // Center frequency mark on highlighted channels based on DSB enveloppe
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];
if(dv->m_channelMarker->getVisible()) { if(dv->m_channelMarker->getVisible())
if (dv->m_channelMarker->getHighlighted()) { {
if (dv->m_channelMarker->getHighlighted())
{
glPushMatrix(); glPushMatrix();
glTranslatef(dv->m_glRectDsb.x(), dv->m_glRectDsb.y(), 0); glTranslatef(dv->m_glRectDsb.x(), dv->m_glRectDsb.y(), 0);
glScalef(dv->m_glRectDsb.width(), dv->m_glRectDsb.height(), 1); glScalef(dv->m_glRectDsb.width(), dv->m_glRectDsb.height(), 1);
@ -1103,10 +1144,13 @@ void GLSpectrum::paintGL()
} }
// paint max hold lines on top of histogram // paint max hold lines on top of histogram
if(m_displayMaxHold) { if (m_displayMaxHold)
if(m_maxHold.size() < (uint)m_fftSize) {
if (m_maxHold.size() < (uint)m_fftSize)
m_maxHold.resize(m_fftSize); m_maxHold.resize(m_fftSize);
for(int i = 0; i < m_fftSize; i++) {
for(int i = 0; i < m_fftSize; i++)
{
int j; int j;
quint8* bs = m_histogram + i * 100; quint8* bs = m_histogram + i * 100;
for(j = 99; j > 1; j--) { for(j = 99; j > 1; j--) {
@ -1228,7 +1272,13 @@ void GLSpectrum::paintGL()
} }
// paint waterfall grid // paint waterfall grid
if(m_displayWaterfall && m_displayGrid) { if(m_displayWaterfall && m_displayGrid)
{
const ScaleEngine::TickList* tickList;
const ScaleEngine::Tick* tick;
tickList = &m_timeScale.getTickList();
#ifdef GL_DEPRECATED
glPushMatrix(); glPushMatrix();
glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0); glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1); glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
@ -1236,14 +1286,8 @@ void GLSpectrum::paintGL()
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(1.0f); glLineWidth(1.0f);
//glColor4f(1, 1, 1, 0.05f);
glColor4f(1, 1, 1, m_displayGridIntensity / 100.0); glColor4f(1, 1, 1, m_displayGridIntensity / 100.0);
const ScaleEngine::TickList* tickList;
const ScaleEngine::Tick* tick;
tickList = &m_timeScale.getTickList();
#ifdef GL_DEPRECATED
for(int i= 0; i < tickList->count(); i++) { for(int i= 0; i < tickList->count(); i++) {
tick = &(*tickList)[i]; tick = &(*tickList)[i];
if(tick->major) { if(tick->major) {
@ -1256,14 +1300,20 @@ void GLSpectrum::paintGL()
} }
} }
} }
glPopMatrix();
#else #else
{ {
GLfloat q3[4*tickList->count()]; GLfloat q3[4*tickList->count()];
int effectiveTicks = 0; int effectiveTicks = 0;
for(int i= 0; i < tickList->count(); i++) {
for (int i= 0; i < tickList->count(); i++)
{
tick = &(*tickList)[i]; tick = &(*tickList)[i];
if(tick->major) { if (tick->major)
if(tick->textSize > 0) { {
if(tick->textSize > 0)
{
float y = tick->pos / m_timeScale.getSize(); float y = tick->pos / m_timeScale.getSize();
q3[4*effectiveTicks] = 0; q3[4*effectiveTicks] = 0;
q3[4*effectiveTicks+1] = y; q3[4*effectiveTicks+1] = y;
@ -1273,21 +1323,31 @@ void GLSpectrum::paintGL()
} }
} }
} }
#ifdef GL_ANDROID
glEnableVertexAttribArray(GL_VERTEX_ARRAY); glPushMatrix();
glVertexAttribPointer(GL_VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, q3); glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glDrawArrays(GL_LINES, 0, 2*effectiveTicks); glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
glDisableVertexAttribArray(GL_VERTEX_ARRAY);
#else glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(1.0f);
glColor4f(1, 1, 1, m_displayGridIntensity / 100.0);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, q3); glVertexPointer(2, GL_FLOAT, 0, q3);
glDrawArrays(GL_LINES, 0, 2*effectiveTicks); glDrawArrays(GL_LINES, 0, 2*effectiveTicks);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
#endif
glPopMatrix();
} }
#endif #endif
tickList = &m_frequencyScale.getTickList(); tickList = &m_frequencyScale.getTickList();
#ifdef GL_DEPRECATED #ifdef GL_DEPRECATED
glPushMatrix();
glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
for(int i= 0; i < tickList->count(); i++) { for(int i= 0; i < tickList->count(); i++) {
tick = &(*tickList)[i]; tick = &(*tickList)[i];
if(tick->major) { if(tick->major) {
@ -1300,14 +1360,20 @@ void GLSpectrum::paintGL()
} }
} }
} }
glPopMatrix();
#else #else
{ {
GLfloat q3[4*tickList->count()]; GLfloat q3[4*tickList->count()];
int effectiveTicks = 0; int effectiveTicks = 0;
for(int i= 0; i < tickList->count(); i++) {
for (int i= 0; i < tickList->count(); i++)
{
tick = &(*tickList)[i]; tick = &(*tickList)[i];
if(tick->major) { if (tick->major)
if(tick->textSize > 0) { {
if (tick->textSize > 0)
{
float x = tick->pos / m_frequencyScale.getSize(); float x = tick->pos / m_frequencyScale.getSize();
q3[4*effectiveTicks] = x; q3[4*effectiveTicks] = x;
q3[4*effectiveTicks+1] = 0; q3[4*effectiveTicks+1] = 0;
@ -1317,21 +1383,22 @@ void GLSpectrum::paintGL()
} }
} }
} }
#ifdef GL_ANDROID
glEnableVertexAttribArray(GL_VERTEX_ARRAY); QVector4D color(1.0f, 1.0f, 1.0f, (float) m_displayGridIntensity / 100.0f);
glVertexAttribPointer(GL_VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, q3); m_glShaderSimple.drawSegments(m_glWaterfallBoxMatrix, color, q3, 2*effectiveTicks);
glDrawArrays(GL_LINES, 0, 2*effectiveTicks);
glDisableVertexAttribArray(GL_VERTEX_ARRAY); // glPushMatrix();
#else // glTranslatef(m_glWaterfallRect.x(), m_glWaterfallRect.y(), 0);
glEnableClientState(GL_VERTEX_ARRAY); // glScalef(m_glWaterfallRect.width(), m_glWaterfallRect.height(), 1);
glVertexPointer(2, GL_FLOAT, 0, q3); //
glDrawArrays(GL_LINES, 0, 2*effectiveTicks); // glEnableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY); // glVertexPointer(2, GL_FLOAT, 0, q3);
#endif // glDrawArrays(GL_LINES, 0, 2*effectiveTicks);
// glDisableClientState(GL_VERTEX_ARRAY);
//
// glPopMatrix();
} }
#endif #endif
glPopMatrix();
} }
// paint histogram grid // paint histogram grid
@ -1369,16 +1436,6 @@ void GLSpectrum::paintGL()
glPopMatrix(); glPopMatrix();
#else #else
for (int i= 0; i < tickList->count(); i++)
{
tick = &(*tickList)[i];
if(tick->major) {
if(tick->textSize > 0) {
float y = tick->pos / m_powerScale.getSize();
}
}
}
{ {
GLfloat q3[4*tickList->count()]; GLfloat q3[4*tickList->count()];
int effectiveTicks = 0; int effectiveTicks = 0;