diff --git a/plugins/channelrx/demodatv/atvdemodsink.h b/plugins/channelrx/demodatv/atvdemodsink.h index 1621b59d8..35df12d84 100644 --- a/plugins/channelrx/demodatv/atvdemodsink.h +++ b/plugins/channelrx/demodatv/atvdemodsink.h @@ -113,7 +113,7 @@ private: //*************** ATV PARAMETERS *************** TVScreenAnalog *m_registeredTVScreen; - std::shared_ptr m_tvScreenBuffer; + TVScreenAnalogBuffer *m_tvScreenBuffer; //int m_intNumberSamplePerLine; int m_numberSamplesPerHTop; //!< number of samples per horizontal synchronization pulse (pulse in ultra-black) - integer value diff --git a/sdrgui/gui/tvscreenanalog.cpp b/sdrgui/gui/tvscreenanalog.cpp index 48413fd84..ffe31c2ce 100644 --- a/sdrgui/gui/tvscreenanalog.cpp +++ b/sdrgui/gui/tvscreenanalog.cpp @@ -65,24 +65,47 @@ static const char* fragmentShaderSource = "}\n"; TVScreenAnalog::TVScreenAnalog(QWidget *parent) - : QGLWidget(parent) + : QGLWidget(parent), + m_shader(nullptr), + m_imageTexture(nullptr), + m_lineShiftsTexture(nullptr) { m_isDataChanged = false; - m_frontBuffer = std::make_shared(5, 1); - m_backBuffer = std::make_shared(5, 1); + m_frontBuffer = new TVScreenAnalogBuffer(5, 1); + m_backBuffer = new TVScreenAnalogBuffer(5, 1); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(tick())); m_updateTimer.start(40); // capped at 25 FPS } -void TVScreenAnalog::cleanup() +TVScreenAnalog::~TVScreenAnalog() { - m_shader = nullptr; - m_imageTexture = nullptr; - m_lineShiftsTexture = nullptr; + delete m_backBuffer; + delete m_frontBuffer; } -std::shared_ptr TVScreenAnalog::getBackBuffer() +void TVScreenAnalog::cleanup() +{ + if (m_shader) + { + delete m_shader; + m_shader = nullptr; + } + + if (m_imageTexture) + { + delete m_imageTexture; + m_imageTexture = nullptr; + } + + if (m_lineShiftsTexture) + { + delete m_lineShiftsTexture; + m_lineShiftsTexture = nullptr; + } +} + +TVScreenAnalogBuffer *TVScreenAnalog::getBackBuffer() { return m_backBuffer; } @@ -95,8 +118,10 @@ void TVScreenAnalog::resizeTVScreen(int intCols, int intRows) QMutexLocker lock(&m_buffersMutex); if (m_frontBuffer->getWidth() != colsAdj || m_frontBuffer->getHeight() != intRows) { - m_frontBuffer = std::make_shared(colsAdj, intRows); - m_backBuffer = std::make_shared(colsAdj, intRows); + delete m_backBuffer; + delete m_frontBuffer; + m_frontBuffer = new TVScreenAnalogBuffer(colsAdj, intRows); + m_backBuffer = new TVScreenAnalogBuffer(colsAdj, intRows); } } @@ -112,29 +137,29 @@ void TVScreenAnalog::initializeGL() connect(QOpenGLContext::currentContext(), &QOpenGLContext::aboutToBeDestroyed, this, &TVScreenAnalog::cleanup); // TODO: when migrating to QOpenGLWidget - m_shader = std::make_shared(this); + m_shader = new QOpenGLShaderProgram(this); + if (!m_shader->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource)) { qWarning() << "TVScreenAnalog::initializeGL: error in vertex shader:" << m_shader->log(); - m_shader = nullptr; return; } + if (!m_shader->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource)) { qWarning() << "TVScreenAnalog::initializeGL: error in fragment shader:" << m_shader->log(); - m_shader = nullptr; return; } + if (!m_shader->link()) { qWarning() << "TVScreenAnalog::initializeGL: error linking shader:" << m_shader->log(); - m_shader = nullptr; return; } @@ -148,10 +173,10 @@ void TVScreenAnalog::initializeGL() m_texelHeightLoc = m_shader->uniformLocation("tlh"); } -void TVScreenAnalog::initializeTextures(std::shared_ptr buffer) +void TVScreenAnalog::initializeTextures(TVScreenAnalogBuffer *buffer) { - m_imageTexture = std::make_shared(QOpenGLTexture::Target2D); - m_lineShiftsTexture = std::make_shared(QOpenGLTexture::Target2D); + m_imageTexture = new QOpenGLTexture(QOpenGLTexture::Target2D); + m_lineShiftsTexture = new QOpenGLTexture(QOpenGLTexture::Target2D); m_imageTexture->setSize(buffer->getWidth(), buffer->getHeight()); m_lineShiftsTexture->setSize(1, buffer->getHeight()); m_imageTexture->setFormat(QOpenGLTexture::RGBA8_UNorm); @@ -171,7 +196,7 @@ void TVScreenAnalog::initializeTextures(std::shared_ptr bu m_lineShiftsTexture->setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::ClampToEdge); } -std::shared_ptr TVScreenAnalog::swapBuffers() +TVScreenAnalogBuffer *TVScreenAnalog::swapBuffers() { QMutexLocker lock(&m_buffersMutex); std::swap(m_frontBuffer, m_backBuffer); @@ -198,7 +223,7 @@ void TVScreenAnalog::paintGL() return; } - std::shared_ptr buffer = m_frontBuffer; + TVScreenAnalogBuffer *buffer = m_frontBuffer; if (!m_imageTexture || m_imageTexture->width() != buffer->getWidth() || @@ -256,4 +281,4 @@ void TVScreenAnalog::paintGL() glDisableVertexAttribArray(m_texCoordAttribIndex); m_shader->release(); -} \ No newline at end of file +} diff --git a/sdrgui/gui/tvscreenanalog.h b/sdrgui/gui/tvscreenanalog.h index c85bebd0b..6640d80b0 100644 --- a/sdrgui/gui/tvscreenanalog.h +++ b/sdrgui/gui/tvscreenanalog.h @@ -25,9 +25,6 @@ #include "export.h" -#include -#include - #include #include #include @@ -129,22 +126,23 @@ class SDRGUI_API TVScreenAnalog : public QGLWidget, protected QOpenGLFunctions int m_texCoordAttribIndex; QMutex m_buffersMutex; - std::shared_ptr m_frontBuffer; - std::shared_ptr m_backBuffer; + TVScreenAnalogBuffer *m_frontBuffer; + TVScreenAnalogBuffer *m_backBuffer; - std::shared_ptr m_shader; - std::shared_ptr m_imageTexture; - std::shared_ptr m_lineShiftsTexture; + QOpenGLShaderProgram *m_shader; + QOpenGLTexture *m_imageTexture; + QOpenGLTexture *m_lineShiftsTexture; public: TVScreenAnalog(QWidget *parent); + ~TVScreenAnalog(); - std::shared_ptr getBackBuffer(); - std::shared_ptr swapBuffers(); + TVScreenAnalogBuffer *getBackBuffer(); + TVScreenAnalogBuffer *swapBuffers(); void resizeTVScreen(int intCols, int intRows); private: - void initializeTextures(std::shared_ptr buffer); + void initializeTextures(TVScreenAnalogBuffer *buffer); void initializeGL() override; void paintGL() override; void resizeGL(int width, int height);