1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-04-04 10:38:45 -04:00

TVScren: removed clanup() call from destructot. Some code cleanup

This commit is contained in:
f4exb 2020-12-12 20:04:18 +01:00
parent dbe3892d52
commit a08e18b505
4 changed files with 50 additions and 51 deletions

View File

@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include <QOpenGLContext>
#include <gui/glshadertvarray.h> #include <gui/glshadertvarray.h>
const QString GLShaderTVArray::m_strVertexShaderSourceArray = QString( const QString GLShaderTVArray::m_strVertexShaderSourceArray = QString(
@ -39,24 +40,24 @@ GLShaderTVArray::GLShaderTVArray(bool blnColor) : m_blnColor(blnColor)
{ {
m_blnAlphaBlend = false; m_blnAlphaBlend = false;
m_blnAlphaReset = false; m_blnAlphaReset = false;
m_objProgram = 0; m_objProgram = nullptr;
m_objImage = 0; m_objImage = nullptr;
m_objTexture = 0; m_objTexture = nullptr;
m_intCols = 0; m_intCols = 0;
m_intRows = 0; m_intRows = 0;
m_blnInitialized = false; m_blnInitialized = false;
m_objCurrentRow = 0; m_objCurrentRow = nullptr;
m_objTextureLoc = 0; m_textureLoc = 0;
m_objMatrixLoc = 0; m_matrixLoc = 0;
} }
GLShaderTVArray::~GLShaderTVArray() GLShaderTVArray::~GLShaderTVArray()
{ {
Cleanup(); cleanup();
} }
void GLShaderTVArray::InitializeGL(int intCols, int intRows) void GLShaderTVArray::initializeGL(int intCols, int intRows)
{ {
QMatrix4x4 objQMatrix; QMatrix4x4 objQMatrix;
@ -65,9 +66,9 @@ void GLShaderTVArray::InitializeGL(int intCols, int intRows)
m_intCols = 0; m_intCols = 0;
m_intRows = 0; m_intRows = 0;
m_objCurrentRow = 0; m_objCurrentRow = nullptr;
if (m_objProgram == 0) if (!m_objProgram)
{ {
m_objProgram = new QOpenGLShaderProgram(); m_objProgram = new QOpenGLShaderProgram();
@ -95,18 +96,18 @@ void GLShaderTVArray::InitializeGL(int intCols, int intRows)
} }
m_objProgram->bind(); m_objProgram->bind();
m_objProgram->setUniformValue(m_objMatrixLoc, objQMatrix); m_objProgram->setUniformValue(m_matrixLoc, objQMatrix);
m_objProgram->setUniformValue(m_objTextureLoc, 0); m_objProgram->setUniformValue(m_textureLoc, 0);
m_objProgram->release(); m_objProgram->release();
} }
m_objMatrixLoc = m_objProgram->uniformLocation("uMatrix"); m_matrixLoc = m_objProgram->uniformLocation("uMatrix");
m_objTextureLoc = m_objProgram->uniformLocation("uTexture"); m_textureLoc = m_objProgram->uniformLocation("uTexture");
if (m_objTexture != 0) if (m_objTexture)
{ {
delete m_objTexture; delete m_objTexture;
m_objTexture = 0; m_objTexture = nullptr;
} }
//Image container //Image container
@ -133,7 +134,7 @@ QRgb * GLShaderTVArray::GetRowBuffer(int intRow)
return 0; return 0;
} }
if (m_objImage == 0) if (!m_objImage)
{ {
return 0; return 0;
} }
@ -170,13 +171,11 @@ void GLShaderTVArray::RenderPixels(unsigned char *chrData)
QRgb *ptrLine; QRgb *ptrLine;
int intVal; int intVal;
if (!m_blnInitialized) if (!m_blnInitialized) {
{
return; return;
} }
if (m_objImage == 0) if (m_objImage) {
{
return; return;
} }
@ -210,18 +209,22 @@ void GLShaderTVArray::RenderPixels(unsigned char *chrData)
m_objProgram->bind(); m_objProgram->bind();
m_objProgram->setUniformValue(m_objMatrixLoc, objQMatrix); m_objProgram->setUniformValue(m_matrixLoc, objQMatrix);
m_objProgram->setUniformValue(m_objTextureLoc, 0); m_objProgram->setUniformValue(m_textureLoc, 0);
if (m_blnAlphaReset) { if (m_blnAlphaReset)
{
ptrF->glClear(GL_COLOR_BUFFER_BIT); ptrF->glClear(GL_COLOR_BUFFER_BIT);
m_blnAlphaReset = false; m_blnAlphaReset = false;
} }
if (m_blnAlphaBlend) { if (m_blnAlphaBlend)
{
ptrF->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ptrF->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ptrF->glEnable(GL_BLEND); ptrF->glEnable(GL_BLEND);
} else { }
else
{
ptrF->glDisable(GL_BLEND); ptrF->glDisable(GL_BLEND);
} }
@ -250,45 +253,43 @@ void GLShaderTVArray::RenderPixels(unsigned char *chrData)
void GLShaderTVArray::ResetPixels() void GLShaderTVArray::ResetPixels()
{ {
if (m_objImage != 0) if (m_objImage) {
{
m_objImage->fill(0); m_objImage->fill(0);
} }
} }
void GLShaderTVArray::ResetPixels(int alpha) void GLShaderTVArray::ResetPixels(int alpha)
{ {
if (m_objImage != 0) if (m_objImage) {
{
m_objImage->fill(qRgba(0, 0, 0, alpha)); m_objImage->fill(qRgba(0, 0, 0, alpha));
} }
} }
void GLShaderTVArray::Cleanup() void GLShaderTVArray::cleanup()
{ {
m_blnInitialized = false; m_blnInitialized = false;
m_intCols = 0; m_intCols = 0;
m_intRows = 0; m_intRows = 0;
m_objCurrentRow = 0; m_objCurrentRow = nullptr;
if (m_objProgram) if (m_objProgram)
{ {
delete m_objProgram; delete m_objProgram;
m_objProgram = 0; m_objProgram = nullptr;
} }
if (m_objTexture != 0) if (m_objTexture)
{ {
delete m_objTexture; delete m_objTexture;
m_objTexture = 0; m_objTexture = nullptr;
} }
if (m_objImage != 0) if (m_objImage)
{ {
delete m_objImage; delete m_objImage;
m_objImage = 0; m_objImage = nullptr;
} }
} }
@ -305,7 +306,7 @@ bool GLShaderTVArray::SelectRow(int intLine)
} }
else else
{ {
m_objCurrentRow = 0; m_objCurrentRow = nullptr;
} }
} }
@ -318,7 +319,7 @@ bool GLShaderTVArray::SetDataColor(int intCol, QRgb objColor)
if (m_blnInitialized) if (m_blnInitialized)
{ {
if ((intCol < m_intCols) && (intCol >= 0) && (m_objCurrentRow != 0)) if ((intCol < m_intCols) && (intCol >= 0) && (m_objCurrentRow))
{ {
m_objCurrentRow[intCol] = objColor; m_objCurrentRow[intCol] = objColor;
blnRslt = true; blnRslt = true;

View File

@ -26,7 +26,6 @@
#include <QOpenGLFunctions_3_0> #include <QOpenGLFunctions_3_0>
#include <QOpenGLTexture> #include <QOpenGLTexture>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QOpenGLContext>
#include <QMatrix4x4> #include <QMatrix4x4>
#include <QVector4D> #include <QVector4D>
#include <QDebug> #include <QDebug>
@ -46,8 +45,8 @@ public:
void setColor(bool blnColor) { m_blnColor = blnColor; } void setColor(bool blnColor) { m_blnColor = blnColor; }
void setAlphaBlend(bool blnAlphaBlend) { m_blnAlphaBlend = blnAlphaBlend; } void setAlphaBlend(bool blnAlphaBlend) { m_blnAlphaBlend = blnAlphaBlend; }
void setAlphaReset() { m_blnAlphaReset = true; } void setAlphaReset() { m_blnAlphaReset = true; }
void InitializeGL(int intCols, int intRows); void initializeGL(int intCols, int intRows);
void Cleanup(); void cleanup();
QRgb *GetRowBuffer(int intRow); QRgb *GetRowBuffer(int intRow);
void RenderPixels(unsigned char *chrData); void RenderPixels(unsigned char *chrData);
void ResetPixels(); void ResetPixels();
@ -60,8 +59,8 @@ public:
protected: protected:
QOpenGLShaderProgram *m_objProgram; QOpenGLShaderProgram *m_objProgram;
int m_objMatrixLoc; int m_matrixLoc;
int m_objTextureLoc; int m_textureLoc;
//int m_objColorLoc; //int m_objColorLoc;
static const QString m_strVertexShaderSourceArray; static const QString m_strVertexShaderSourceArray;
static const QString m_strFragmentShaderSourceColored; static const QString m_strFragmentShaderSourceColored;

View File

@ -36,7 +36,7 @@ TVScreen::TVScreen(bool blnColor, QWidget* parent) :
connect(&m_objTimer, SIGNAL(timeout()), this, SLOT(tick())); connect(&m_objTimer, SIGNAL(timeout()), this, SLOT(tick()));
m_objTimer.start(40); // capped at 25 FPS m_objTimer.start(40); // capped at 25 FPS
m_chrLastData = NULL; m_chrLastData = nullptr;
m_blnConfigChanged = false; m_blnConfigChanged = false;
m_blnDataChanged = false; m_blnDataChanged = false;
m_blnGLContextInitialized = false; m_blnGLContextInitialized = false;
@ -50,7 +50,6 @@ TVScreen::TVScreen(bool blnColor, QWidget* parent) :
TVScreen::~TVScreen() TVScreen::~TVScreen()
{ {
cleanup();
} }
void TVScreen::setColor(bool blnColor) void TVScreen::setColor(bool blnColor)
@ -62,7 +61,7 @@ QRgb* TVScreen::getRowBuffer(int intRow)
{ {
if (!m_blnGLContextInitialized) if (!m_blnGLContextInitialized)
{ {
return NULL; return nullptr;
} }
return m_objGLShaderArray.GetRowBuffer(intRow); return m_objGLShaderArray.GetRowBuffer(intRow);
@ -127,7 +126,7 @@ void TVScreen::initializeGL()
QSurface *objSurface = objGlCurrentContext->surface(); QSurface *objSurface = objGlCurrentContext->surface();
if (objSurface == NULL) if (objSurface == nullptr)
{ {
qCritical() << "TVScreen::initializeGL: no surface attached"; qCritical() << "TVScreen::initializeGL: no surface attached";
return; return;
@ -172,7 +171,7 @@ void TVScreen::paintGL()
if ((m_intAskedCols != 0) && (m_intAskedRows != 0)) if ((m_intAskedCols != 0) && (m_intAskedRows != 0))
{ {
m_objGLShaderArray.InitializeGL(m_intAskedCols, m_intAskedRows); m_objGLShaderArray.initializeGL(m_intAskedCols, m_intAskedRows);
m_intAskedCols = 0; m_intAskedCols = 0;
m_intAskedRows = 0; m_intAskedRows = 0;
} }
@ -206,7 +205,7 @@ void TVScreen::cleanup()
{ {
if (m_blnGLContextInitialized) if (m_blnGLContextInitialized)
{ {
m_objGLShaderArray.Cleanup(); m_objGLShaderArray.cleanup();
} }
} }

View File

@ -112,7 +112,7 @@ TVScreenAnalogBuffer *TVScreenAnalog::getBackBuffer()
void TVScreenAnalog::resizeTVScreen(int intCols, int intRows) void TVScreenAnalog::resizeTVScreen(int intCols, int intRows)
{ {
qDebug("TVScreen::resizeTVScreen: cols: %d, rows: %d", intCols, intRows); qDebug("TVScreenAnalog::resizeTVScreen: cols: %d, rows: %d", intCols, intRows);
int colsAdj = intCols + 4; int colsAdj = intCols + 4;
QMutexLocker lock(&m_buffersMutex); QMutexLocker lock(&m_buffersMutex);