From 1dbd387ea6b9393f783d3134de7d1c5f80e9c621 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 5 Mar 2016 23:18:26 +0100 Subject: [PATCH] OpenGL modernization: GLScope modernization #1 --- include/gui/glscope.h | 5 +++ sdrbase/gui/glscope.cpp | 87 +++++++++++++++++++++-------------------- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/include/gui/glscope.h b/include/gui/glscope.h index f53374aabe..bd7624acf9 100644 --- a/include/gui/glscope.h +++ b/include/gui/glscope.h @@ -27,6 +27,8 @@ #include "dsp/dsptypes.h" #include "dsp/scopevis.h" #include "gui/scaleengine.h" +#include "gui/glshadersimple.h" +#include "gui/glshadertextured.h" #include "util/export.h" #include "util/bitfieldindex.h" @@ -181,6 +183,9 @@ class SDRANGEL_API GLScope: public QGLWidget { QFont m_powerOverlayFont; + GLShaderSimple m_glShaderSimple; + GLShaderTextured m_glShaderLeft1Scale; + void initializeGL(); void resizeGL(int width, int height); void paintGL(); diff --git a/sdrbase/gui/glscope.cpp b/sdrbase/gui/glscope.cpp index 31004c17b9..655bb6227d 100644 --- a/sdrbase/gui/glscope.cpp +++ b/sdrbase/gui/glscope.cpp @@ -217,6 +217,7 @@ void GLScope::newTrace(const std::vector& trace, int sampleRate) void GLScope::initializeGL() { glDisable(GL_DEPTH_TEST); + m_glShaderSimple.initializeGL(); } void GLScope::resizeGL(int width, int height) @@ -252,6 +253,7 @@ void GLScope::paintGL() if ((m_displays == DisplayBoth) || (m_displays == DisplayFirstOnly)) { // draw rect around +#ifdef GL_DEPRECATED glPushMatrix(); glTranslatef(m_glScopeRect1.x(), m_glScopeRect1.y(), 0); glScalef(m_glScopeRect1.width(), m_glScopeRect1.height(), 1); @@ -261,13 +263,15 @@ void GLScope::paintGL() glLineWidth(1.0f); glColor4f(1, 1, 1, 0.5); -#ifdef GL_DEPRECATED glBegin(GL_LINE_LOOP); glVertex2f(1, 1); glVertex2f(0, 1); glVertex2f(0, 0); glVertex2f(1, 0); glEnd(); + + glDisable(GL_BLEND); + glPopMatrix(); #else { GLfloat q3[] { @@ -277,23 +281,24 @@ void GLScope::paintGL() 1, 0 }; - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, q3); - glDrawArrays(GL_LINE_LOOP, 0, 4); - glDisableClientState(GL_VERTEX_ARRAY); + QVector4D color(1.0f, 1.0f, 1.0f, 0.5f); + m_glShaderSimple.drawContour(m_glScopeMatrix1, color, q3, 4); + } #endif - glDisable(GL_BLEND); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(m_glScopeRect1.x(), m_glScopeRect1.y(), 0); - glScalef(m_glScopeRect1.width(), m_glScopeRect1.height(), 1); // paint grid const ScaleEngine::TickList* tickList; const ScaleEngine::Tick* tick; + // Horizontal Y1 + tickList = &m_y1Scale.getTickList(); + +#ifdef GL_DEPRECATED + glPushMatrix(); + glTranslatef(m_glScopeRect1.x(), m_glScopeRect1.y(), 0); + glScalef(m_glScopeRect1.width(), m_glScopeRect1.height(), 1); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(1.0f); @@ -303,10 +308,7 @@ void GLScope::paintGL() } else { glColor4f(1, 1, 1, m_displayGridIntensity / 100.0); } - // Horizontal Y1 - tickList = &m_y1Scale.getTickList(); -#ifdef GL_DEPRECATED for(int i= 0; i < tickList->count(); i++) { tick = &(*tickList)[i]; if(tick->major) { @@ -319,14 +321,21 @@ void GLScope::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 y = 1 - (tick->pos / m_y1Scale.getSize()); q3[4*effectiveTicks] = 0; q3[4*effectiveTicks+1] = y; @@ -336,21 +345,20 @@ void GLScope::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 + + if (m_mode == ModeIQPolar) { + QVector4D color(1.0f, 1.0f, 1.0f, (float) m_displayGridIntensity / 100.0f); + m_glShaderSimple.drawSegments(m_glScopeMatrix1, color, q3, 2*effectiveTicks); + } + else + { + QVector4D color(1.0f, 1.0f, 1.0f, (float) m_displayGridIntensity / 100.0f); + m_glShaderSimple.drawSegments(m_glScopeMatrix1, color, q3, 2*effectiveTicks); + } } #endif - glPopMatrix(); +#ifdef GL_DEPRECATED glPushMatrix(); glTranslatef(m_glScopeRect1.x(), m_glScopeRect1.y(), 0); glScalef(m_glScopeRect1.width(), m_glScopeRect1.height(), 1); @@ -359,7 +367,6 @@ void GLScope::paintGL() glColor4f(1, 1, 1, m_displayGridIntensity / 100.0); tickList = &m_x1Scale.getTickList(); -#ifdef GL_DEPRECATED for(int i= 0; i < tickList->count(); i++) { tick = &(*tickList)[i]; if(tick->major) { @@ -372,8 +379,13 @@ void GLScope::paintGL() } } } + + glPopMatrix(); #else { + // Vertical X1 + tickList = &m_x1Scale.getTickList(); + GLfloat q3[4*tickList->count()]; int effectiveTicks = 0; for(int i= 0; i < tickList->count(); i++) { @@ -389,20 +401,11 @@ void GLScope::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_glScopeMatrix1, color, q3, 2*effectiveTicks); } #endif - glPopMatrix(); // paint left #1 scale glPushMatrix();