From 33e2e18c573585de800979f1da74c6e821e135ab Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 8 Dec 2014 21:08:03 -0500 Subject: [PATCH] Unify demod drawing functions --- src/visual/PrimaryGLContext.cpp | 91 +++++++++++++++++++++++++++++++++ src/visual/PrimaryGLContext.h | 7 +++ src/visual/SpectrumCanvas.cpp | 17 ++++-- src/visual/SpectrumContext.cpp | 5 -- src/visual/WaterfallContext.cpp | 86 ------------------------------- src/visual/WaterfallContext.h | 6 +-- 6 files changed, 112 insertions(+), 100 deletions(-) diff --git a/src/visual/PrimaryGLContext.cpp b/src/visual/PrimaryGLContext.cpp index 151dce0..4cabaac 100644 --- a/src/visual/PrimaryGLContext.cpp +++ b/src/visual/PrimaryGLContext.cpp @@ -66,3 +66,94 @@ GLFont *PrimaryGLContext::getFont() { return font; } + + +void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) { + if (!demod) { + return; + } + + float uxPos = (float) (demod->getParams().frequency - (wxGetApp().getFrequency() - SRATE / 2)) / (float) SRATE; + + glDisable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); + glColor4f(r, g, b, 0.6); + + glBegin(GL_LINES); + glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0); + + float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE; + + glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); + + glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0); + + glEnd(); + + glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); + glColor4f(r, g, b, 0.2); + glBegin(GL_QUADS); + glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); + + glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0); + glEnd(); + + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + +} + +void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b) { + DemodulatorInstance *demod = wxGetApp().getDemodTest(); + + if (!demod) { + return; + } + + glDisable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); + glColor4f(r, g, b, 0.6); + + glBegin(GL_LINES); + glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0); + + float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE; + + glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); + + glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0); + glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0); + + glEnd(); + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + +} + +void PrimaryGLContext::BeginDraw() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +void PrimaryGLContext::EndDraw() { + glFlush(); + + CheckGLError(); +} + diff --git a/src/visual/PrimaryGLContext.h b/src/visual/PrimaryGLContext.h index c9a0f91..57ad25d 100644 --- a/src/visual/PrimaryGLContext.h +++ b/src/visual/PrimaryGLContext.h @@ -8,6 +8,7 @@ #include "CubicSDRDefs.h" #include "GLFont.h" +#include "DemodulatorMgr.h" class PrimaryGLContext: public wxGLContext { public: @@ -16,6 +17,12 @@ public: static wxString glGetwxString(GLenum name); static void CheckGLError(); + void BeginDraw(); + void EndDraw(); + + void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1); + void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1); + static GLFont *getFont(); private: diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index d75c705..9e9abe9 100644 --- a/src/visual/SpectrumCanvas.cpp +++ b/src/visual/SpectrumCanvas.cpp @@ -61,8 +61,17 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glContext->SetCurrent(*this); glViewport(0, 0, ClientSize.x, ClientSize.y); + glContext->BeginDraw(); glContext->Draw(spectrum_points); + std::vector &demods = wxGetApp().getDemodMgr().getDemodulators(); + + for (int i = 0, iMax = demods.size(); i < iMax; i++) { + glContext->DrawDemod(demods[i]); + } + + glContext->EndDraw(); + SwapBuffers(); } @@ -73,13 +82,13 @@ void SpectrumCanvas::OnKeyDown(wxKeyEvent& event) { switch (event.GetKeyCode()) { case WXK_RIGHT: freq = wxGetApp().getFrequency(); - freq += SRATE/2; + freq += SRATE / 2; wxGetApp().setFrequency(freq); ((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq)); break; case WXK_LEFT: freq = wxGetApp().getFrequency(); - freq -= SRATE/2; + freq -= SRATE / 2; wxGetApp().setFrequency(freq); ((wxFrame*) parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), freq)); break; @@ -119,12 +128,12 @@ void SpectrumCanvas::setData(std::vector *data) { int n; for (int i = 0, iMax = FFT_SIZE / 2; i < iMax; i++) { - n = (i == 0)?1:i; + n = (i == 0) ? 1 : i; double a = out[n][0]; double b = out[n][1]; double c = sqrt(a * a + b * b); - n = (i == FFT_SIZE/2)?(FFT_SIZE/2+1):i; + n = (i == FFT_SIZE / 2) ? (FFT_SIZE / 2 + 1) : i; double x = out[FFT_SIZE / 2 + n][0]; double y = out[FFT_SIZE / 2 + n][1]; double z = sqrt(x * x + y * y); diff --git a/src/visual/SpectrumContext.cpp b/src/visual/SpectrumContext.cpp index 91eecde..1dd8e97 100644 --- a/src/visual/SpectrumContext.cpp +++ b/src/visual/SpectrumContext.cpp @@ -13,13 +13,8 @@ SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedCont } void SpectrumContext::Draw(std::vector &points) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); glDisable(GL_TEXTURE_2D); - glColor3f(1.0, 1.0, 1.0); if (points.size()) { diff --git a/src/visual/WaterfallContext.cpp b/src/visual/WaterfallContext.cpp index a20118a..f1ceb46 100644 --- a/src/visual/WaterfallContext.cpp +++ b/src/visual/WaterfallContext.cpp @@ -37,12 +37,6 @@ WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedC glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(grad.getBlue())[0]); } -void WaterfallContext::BeginDraw() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} void WaterfallContext::Draw(std::vector &points) { @@ -82,83 +76,3 @@ void WaterfallContext::Draw(std::vector &points) { } -void WaterfallContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) { - if (!demod) { - return; - } - - float uxPos = (float) (demod->getParams().frequency - (wxGetApp().getFrequency() - SRATE / 2)) / (float) SRATE; - - glDisable(GL_DEPTH_TEST); - glDisable(GL_TEXTURE_2D); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); - glColor4f(r, g, b, 0.6); - - glBegin(GL_LINES); - glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0); - - float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE; - - glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); - - glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0); - - glEnd(); - - glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); - glColor4f(r, g, b, 0.2); - glBegin(GL_QUADS); - glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); - - glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0); - glEnd(); - - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - -} - -void WaterfallContext::DrawFreqSelector(float uxPos, float r, float g, float b) { - DemodulatorInstance *demod = wxGetApp().getDemodTest(); - - if (!demod) { - return; - } - - glDisable(GL_DEPTH_TEST); - glDisable(GL_TEXTURE_2D); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); - glColor4f(r, g, b, 0.6); - - glBegin(GL_LINES); - glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0); - - float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE; - - glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); - - glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0); - glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0); - - glEnd(); - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - -} - -void WaterfallContext::EndDraw() { - glFlush(); - - CheckGLError(); -} diff --git a/src/visual/WaterfallContext.h b/src/visual/WaterfallContext.h index bf0a23d..ab5c541 100644 --- a/src/visual/WaterfallContext.h +++ b/src/visual/WaterfallContext.h @@ -2,7 +2,6 @@ #include "PrimaryGLContext.h" #include "Gradient.h" -#include "DemodulatorMgr.h" #define NUM_WATERFALL_LINES 512 @@ -12,11 +11,8 @@ class WaterfallContext: public PrimaryGLContext { public: WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext); - void BeginDraw(); + void Draw(std::vector &points); - void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1); - void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1); - void EndDraw(); private: Gradient grad;