diff --git a/plugins/channelrx/demodatv/CMakeLists.txt b/plugins/channelrx/demodatv/CMakeLists.txt index e92bc546e..83ac99570 100644 --- a/plugins/channelrx/demodatv/CMakeLists.txt +++ b/plugins/channelrx/demodatv/CMakeLists.txt @@ -6,7 +6,6 @@ set(atv_SOURCES atvdemodgui.cpp atvdemodplugin.cpp atvscreen.cpp - glshaderarray.cpp ) set(atv_HEADERS @@ -16,7 +15,6 @@ set(atv_HEADERS atvdemodplugin.h atvscreen.h atvscreeninterface.h - glshaderarray.h ) set(atv_FORMS diff --git a/plugins/channelrx/demodatv/atvscreen.cpp b/plugins/channelrx/demodatv/atvscreen.cpp index bba4aaf3d..359a623ef 100644 --- a/plugins/channelrx/demodatv/atvscreen.cpp +++ b/plugins/channelrx/demodatv/atvscreen.cpp @@ -28,7 +28,7 @@ #include ATVScreen::ATVScreen(QWidget* parent) : - QGLWidget(parent), ATVScreenInterface(), m_objMutex(QMutex::NonRecursive) + QGLWidget(parent), ATVScreenInterface(), m_objMutex(QMutex::NonRecursive), m_objGLShaderArray(false) { setAttribute(Qt::WA_OpaquePaintEvent); connect(&m_objTimer, SIGNAL(timeout()), this, SLOT(tick())); diff --git a/plugins/channelrx/demodatv/atvscreen.h b/plugins/channelrx/demodatv/atvscreen.h index f2cf82c88..26c6a5bcd 100644 --- a/plugins/channelrx/demodatv/atvscreen.h +++ b/plugins/channelrx/demodatv/atvscreen.h @@ -28,7 +28,7 @@ #include #include #include "dsp/dsptypes.h" -#include "glshaderarray.h" +#include "gui/glshadertvarray.h" #include "gui/glshadertextured.h" #include "util/export.h" #include "util/bitfieldindex.h" @@ -69,7 +69,7 @@ private: bool m_blnDataChanged; bool m_blnConfigChanged; - GLShaderArray m_objGLShaderArray; + GLShaderTVArray m_objGLShaderArray; unsigned char *m_chrLastData; diff --git a/plugins/channelrx/demodatv/demodatv.pro b/plugins/channelrx/demodatv/demodatv.pro index 7ed97aae2..6d9f6d146 100644 --- a/plugins/channelrx/demodatv/demodatv.pro +++ b/plugins/channelrx/demodatv/demodatv.pro @@ -32,15 +32,13 @@ CONFIG(macx):INCLUDEPATH += "../../../../../boost_1_64_0" SOURCES += atvdemod.cpp\ atvdemodgui.cpp\ atvdemodplugin.cpp\ - atvscreen.cpp\ - glshaderarray.cpp + atvscreen.cpp HEADERS += atvdemod.h\ atvdemodgui.h\ atvdemodplugin.h\ atvscreen.h\ - atvscreeninterface.h\ - glshaderarray.h + atvscreeninterface.h FORMS += atvdemodgui.ui diff --git a/plugins/channelrx/demoddatv/CMakeLists.txt b/plugins/channelrx/demoddatv/CMakeLists.txt index cb123e52f..ca4229347 100644 --- a/plugins/channelrx/demoddatv/CMakeLists.txt +++ b/plugins/channelrx/demoddatv/CMakeLists.txt @@ -5,7 +5,6 @@ set(datv_SOURCES datvdemodgui.cpp datvdemodplugin.cpp datvscreen.cpp - glshaderarray.cpp datvideostream.cpp datvideorender.cpp ) @@ -15,7 +14,6 @@ set(datv_HEADERS datvdemodgui.h datvdemodplugin.h datvscreen.h - glshaderarray.h datvideostream.h datvideorender.h ) diff --git a/plugins/channelrx/demoddatv/datvscreen.cpp b/plugins/channelrx/demoddatv/datvscreen.cpp index 754539294..d7965f57c 100644 --- a/plugins/channelrx/demoddatv/datvscreen.cpp +++ b/plugins/channelrx/demoddatv/datvscreen.cpp @@ -28,7 +28,7 @@ #include DATVScreen::DATVScreen(QWidget* parent) : - QGLWidget(parent), m_objMutex(QMutex::NonRecursive) + QGLWidget(parent), m_objMutex(QMutex::NonRecursive), m_objGLShaderArray(true) { setAttribute(Qt::WA_OpaquePaintEvent); connect(&m_objTimer, SIGNAL(timeout()), this, SLOT(tick())); diff --git a/plugins/channelrx/demoddatv/datvscreen.h b/plugins/channelrx/demoddatv/datvscreen.h index 3f9042b52..545703394 100644 --- a/plugins/channelrx/demoddatv/datvscreen.h +++ b/plugins/channelrx/demoddatv/datvscreen.h @@ -28,8 +28,8 @@ #include #include #include "dsp/dsptypes.h" -#include "glshaderarray.h" #include "gui/glshadertextured.h" +#include "gui/glshadertvarray.h" #include "util/export.h" #include "util/bitfieldindex.h" @@ -74,7 +74,7 @@ private: bool m_blnDataChanged; bool m_blnConfigChanged; - GLShaderArray m_objGLShaderArray; + GLShaderTVArray m_objGLShaderArray; void initializeGL(); void resizeGL(int width, int height); diff --git a/plugins/channelrx/demoddatv/demoddatv.pro b/plugins/channelrx/demoddatv/demoddatv.pro index a0b3cd352..b38c59fcd 100644 --- a/plugins/channelrx/demoddatv/demoddatv.pro +++ b/plugins/channelrx/demoddatv/demoddatv.pro @@ -31,15 +31,14 @@ CONFIG(macx):INCLUDEPATH += "../../../../../boost_1_64_0" SOURCES += datvdemod.cpp\ datvdemodgui.cpp\ datvdemodplugin.cpp\ - datvscreen.cpp \ - glshaderarray.cpp \ + datvscreen.cpp \ datvideostream.cpp \ datvideorender.cpp HEADERS += datvdemod.h\ datvdemodgui.h\ datvdemodplugin.h\ - datvscreen.h \ + datvscreen.h \ leansdr/convolutional.h \ leansdr/dsp.h \ leansdr/dvb.h \ @@ -53,7 +52,6 @@ HEADERS += datvdemod.h\ leansdr/sdr.h \ leansdr/viterbi.h \ datvconstellation.h \ - glshaderarray.h \ datvvideoplayer.h \ datvideostream.h \ datvideorender.h diff --git a/plugins/channelrx/demoddatv/glshaderarray.cpp b/plugins/channelrx/demoddatv/glshaderarray.cpp deleted file mode 100644 index 6e09c57bb..000000000 --- a/plugins/channelrx/demoddatv/glshaderarray.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////// -// Copyright (C) 2017 F4HKW // -// for F4EXB / SDRAngel // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation as version 3 of the License, or // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License V3 for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program. If not, see . // -/////////////////////////////////////////////////////////////////////////////////// - -#include "glshaderarray.h" - -const QString GLShaderArray::m_strVertexShaderSourceArray = QString( - "uniform highp mat4 uMatrix;\n" - "attribute highp vec4 vertex;\n" - "attribute highp vec2 texCoord;\n" - "varying mediump vec2 texCoordVar;\n" - "void main() {\n" - " gl_Position = uMatrix * vertex;\n" - " texCoordVar = texCoord;\n" - "}\n"); - -const QString GLShaderArray::m_strFragmentShaderSourceColored = QString( - "uniform lowp sampler2D uTexture;\n" - "varying mediump vec2 texCoordVar;\n" - "void main() {\n" - " gl_FragColor = texture2D(uTexture, texCoordVar);\n" - "}\n"); - -GLShaderArray::GLShaderArray() -{ - m_objProgram = 0; - m_objImage = 0; - m_objTexture = 0; - m_intCols = 0; - m_intRows = 0; - m_blnInitialized = false; - m_objCurrentRow = 0; - - m_objTextureLoc = 0; - m_objColorLoc = 0; - m_objMatrixLoc = 0; -} - -GLShaderArray::~GLShaderArray() -{ - Cleanup(); -} - -void GLShaderArray::InitializeGL(int intCols, int intRows) -{ - QMatrix4x4 objQMatrix; - - m_blnInitialized = false; - - m_intCols = 0; - m_intRows = 0; - - m_objCurrentRow = 0; - - if (m_objProgram == 0) - { - m_objProgram = new QOpenGLShaderProgram(); - - if (!m_objProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, - m_strVertexShaderSourceArray)) - { - qDebug() << "GLShaderArray::initializeGL: error in vertex shader: " - << m_objProgram->log(); - } - - if (!m_objProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, - m_strFragmentShaderSourceColored)) - { - qDebug() - << "GLShaderArray::initializeGL: error in fragment shader: " - << m_objProgram->log(); - } - - m_objProgram->bindAttributeLocation("vertex", 0); - - if (!m_objProgram->link()) - { - qDebug() << "GLShaderArray::initializeGL: error linking shader: " - << m_objProgram->log(); - } - - m_objProgram->bind(); - m_objProgram->setUniformValue(m_objMatrixLoc, objQMatrix); - m_objProgram->setUniformValue(m_objTextureLoc, 0); - m_objProgram->release(); - } - - m_objMatrixLoc = m_objProgram->uniformLocation("uMatrix"); - m_objTextureLoc = m_objProgram->uniformLocation("uTexture"); - m_objColorLoc = m_objProgram->uniformLocation("uColour"); - - if (m_objTexture != 0) - { - delete m_objTexture; - m_objTexture = 0; - } - - //Image container - m_objImage = new QImage(intCols, intRows, QImage::Format_RGBA8888); - m_objImage->fill(QColor(0, 0, 0)); - - m_objTexture = new QOpenGLTexture(*m_objImage); - m_objTexture->setMinificationFilter(QOpenGLTexture::Linear); - m_objTexture->setMagnificationFilter(QOpenGLTexture::Linear); - m_objTexture->setWrapMode(QOpenGLTexture::ClampToEdge); - - m_intCols = intCols; - m_intRows = intRows; - - m_blnInitialized = true; - -} - -QRgb * GLShaderArray::GetRowBuffer(int intRow) -{ - if (!m_blnInitialized) - { - return 0; - } - - if (m_objImage == 0) - { - return 0; - } - - if (intRow > m_intRows) - { - return 0; - } - - return (QRgb *) m_objImage->scanLine(intRow); -} - -void GLShaderArray::RenderPixels(unsigned char *chrData) -{ - QOpenGLFunctions *ptrF; - int intI; - int intJ; - int intNbVertices = 6; - - QMatrix4x4 objQMatrix; - - GLfloat arrVertices[] = - // 2 3 - // 1 4 - //1 2 3 3 4 1 - { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f }; - - GLfloat arrTextureCoords[] = - // 1 4 - // 2 3 - //1 2 3 3 4 1 - { 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; - - QRgb *ptrLine; - - if (!m_blnInitialized) - { - return; - } - - if (m_objImage == 0) - { - return; - } - - if (chrData != 0) - { - for (intJ = 0; intJ < m_intRows; intJ++) - { - ptrLine = (QRgb *) m_objImage->scanLine(intJ); - - for (intI = 0; intI < m_intCols; intI++) - { - - *ptrLine = qRgb((int) (*(chrData+2)), (int) (*(chrData+1)), (int) (*chrData)); - ptrLine++; - - chrData+=3; - } - } - } - - //Affichage - ptrF = QOpenGLContext::currentContext()->functions(); - - m_objProgram->bind(); - - m_objProgram->setUniformValue(m_objMatrixLoc, objQMatrix); - m_objProgram->setUniformValue(m_objTextureLoc, 0); - - m_objTexture->bind(); - - ptrF->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_intCols, m_intRows, GL_RGBA, - GL_UNSIGNED_BYTE, m_objImage->bits()); - - ptrF->glEnableVertexAttribArray(0); // vertex - ptrF->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, arrVertices); - - ptrF->glEnableVertexAttribArray(1); // texture coordinates - ptrF->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, arrTextureCoords); - - ptrF->glDrawArrays(GL_TRIANGLES, 0, intNbVertices); - - //cleanup - ptrF->glDisableVertexAttribArray(0); - ptrF->glDisableVertexAttribArray(1); - - //*********************// - - m_objTexture->release(); - m_objProgram->release(); -} - -void GLShaderArray::ResetPixels() -{ - if (m_objImage != 0) - { - m_objImage->fill(0); - } -} - -void GLShaderArray::Cleanup() -{ - m_blnInitialized = false; - - m_intCols = 0; - m_intRows = 0; - - m_objCurrentRow = 0; - - if (m_objProgram) - { - delete m_objProgram; - m_objProgram = 0; - } - - if (m_objTexture != 0) - { - delete m_objTexture; - m_objTexture = 0; - } - - if (m_objImage != 0) - { - delete m_objImage; - m_objImage = 0; - } -} - -bool GLShaderArray::SelectRow(int intLine) -{ - bool blnRslt = false; - - if (m_blnInitialized) - { - if ((intLine < m_intRows) && (intLine >= 0)) - { - m_objCurrentRow = (QRgb *) m_objImage->scanLine(intLine); - blnRslt = true; - } - else - { - m_objCurrentRow = 0; - } - } - - return blnRslt; -} - -bool GLShaderArray::SetDataColor(int intCol, QRgb objColor) -{ - bool blnRslt = false; - - if (m_blnInitialized) - { - if ((intCol < m_intCols) && (intCol >= 0) && (m_objCurrentRow != 0)) - { - m_objCurrentRow[intCol] = objColor; - blnRslt = true; - } - } - - return blnRslt; -} - diff --git a/plugins/channelrx/demoddatv/glshaderarray.h b/plugins/channelrx/demoddatv/glshaderarray.h deleted file mode 100644 index 4c34969f3..000000000 --- a/plugins/channelrx/demoddatv/glshaderarray.h +++ /dev/null @@ -1,76 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////// -// Copyright (C) 2017 F4HKW // -// for F4EXB / SDRAngel // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation as version 3 of the License, or // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License V3 for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program. If not, see . // -/////////////////////////////////////////////////////////////////////////////////// - -#ifndef INCLUDE_GUI_GLSHADERARRAY_H_ -#define INCLUDE_GUI_GLSHADERARRAY_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class QOpenGLShaderProgram; -class QMatrix4x4; -class QVector4D; - -class GLShaderArray -{ -public: - GLShaderArray(); - ~GLShaderArray(); - - void InitializeGL(int intCols, int intRows); - void ResizeContainer(int intCols, int intRows); - void Cleanup(); - QRgb *GetRowBuffer(int intRow); - void RenderPixels(unsigned char *chrData); - void ResetPixels(); - - bool SelectRow(int intLine); - bool SetDataColor(int intCol,QRgb objColor); - - -protected: - - QOpenGLShaderProgram *m_objProgram; - int m_objMatrixLoc; - int m_objTextureLoc; - int m_objColorLoc; - static const QString m_strVertexShaderSourceArray; - static const QString m_strFragmentShaderSourceColored; - - QImage *m_objImage=NULL; - QOpenGLTexture *m_objTexture=NULL; - - int m_intCols; - int m_intRows; - - QRgb * m_objCurrentRow; - - bool m_blnInitialized; -}; - -#endif /* INCLUDE_GUI_GLSHADERARRAY_H_ */ diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 32a4aa078..cd9ead1fd 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -24,6 +24,7 @@ set(sdrgui_SOURCES gui/glscopemultigui.cpp gui/glshadersimple.cpp gui/glshadertextured.cpp + gui/glshadertvarray.cpp gui/glspectrum.cpp gui/glspectrumgui.cpp gui/indicator.cpp @@ -77,6 +78,7 @@ set(sdrgui_HEADERS gui/glscopenggui.h gui/glscopemultigui.h gui/glshadersimple.h + gui/glshadertvarray.h gui/glshadertextured.h gui/glspectrum.h gui/glspectrumgui.h diff --git a/plugins/channelrx/demodatv/glshaderarray.cpp b/sdrgui/gui/glshadertvarray.cpp similarity index 87% rename from plugins/channelrx/demodatv/glshaderarray.cpp rename to sdrgui/gui/glshadertvarray.cpp index f54041dc9..b0a45c190 100644 --- a/plugins/channelrx/demodatv/glshaderarray.cpp +++ b/sdrgui/gui/glshadertvarray.cpp @@ -15,9 +15,9 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include "glshaderarray.h" +#include -const QString GLShaderArray::m_strVertexShaderSourceArray = QString( +const QString GLShaderTVArray::m_strVertexShaderSourceArray = QString( "uniform highp mat4 uMatrix;\n" "attribute highp vec4 vertex;\n" "attribute highp vec2 texCoord;\n" @@ -27,14 +27,14 @@ const QString GLShaderArray::m_strVertexShaderSourceArray = QString( " texCoordVar = texCoord;\n" "}\n"); -const QString GLShaderArray::m_strFragmentShaderSourceColored = QString( +const QString GLShaderTVArray::m_strFragmentShaderSourceColored = QString( "uniform lowp sampler2D uTexture;\n" "varying mediump vec2 texCoordVar;\n" "void main() {\n" " gl_FragColor = texture2D(uTexture, texCoordVar);\n" "}\n"); -GLShaderArray::GLShaderArray() +GLShaderTVArray::GLShaderTVArray(bool blnColor) : m_blnColor(blnColor) { m_objProgram = 0; m_objImage = 0; @@ -49,12 +49,12 @@ GLShaderArray::GLShaderArray() m_objMatrixLoc = 0; } -GLShaderArray::~GLShaderArray() +GLShaderTVArray::~GLShaderTVArray() { Cleanup(); } -void GLShaderArray::InitializeGL(int intCols, int intRows) +void GLShaderTVArray::InitializeGL(int intCols, int intRows) { QMatrix4x4 objQMatrix; @@ -124,7 +124,7 @@ void GLShaderArray::InitializeGL(int intCols, int intRows) } -QRgb * GLShaderArray::GetRowBuffer(int intRow) +QRgb * GLShaderTVArray::GetRowBuffer(int intRow) { if (!m_blnInitialized) { @@ -144,7 +144,7 @@ QRgb * GLShaderArray::GetRowBuffer(int intRow) return (QRgb *) m_objImage->scanLine(intRow); } -void GLShaderArray::RenderPixels(unsigned char *chrData) +void GLShaderTVArray::RenderPixels(unsigned char *chrData) { QOpenGLFunctions *ptrF; int intI; @@ -186,12 +186,19 @@ void GLShaderArray::RenderPixels(unsigned char *chrData) for (intI = 0; intI < m_intCols; intI++) { + if (m_blnColor) + { + *ptrLine = qRgb((int) (*(chrData+2)), (int) (*(chrData+1)), (int) (*chrData)); + chrData+=3; + } + else + { + intVal = (int) (*chrData); + *ptrLine = qRgb(intVal, intVal, intVal); + chrData++; + } - intVal = (int) (*chrData); - *ptrLine = qRgb(intVal, intVal, intVal); ptrLine++; - - chrData++; } } } @@ -227,7 +234,7 @@ void GLShaderArray::RenderPixels(unsigned char *chrData) m_objProgram->release(); } -void GLShaderArray::ResetPixels() +void GLShaderTVArray::ResetPixels() { if (m_objImage != 0) { @@ -235,7 +242,7 @@ void GLShaderArray::ResetPixels() } } -void GLShaderArray::Cleanup() +void GLShaderTVArray::Cleanup() { m_blnInitialized = false; @@ -263,7 +270,7 @@ void GLShaderArray::Cleanup() } } -bool GLShaderArray::SelectRow(int intLine) +bool GLShaderTVArray::SelectRow(int intLine) { bool blnRslt = false; @@ -283,7 +290,7 @@ bool GLShaderArray::SelectRow(int intLine) return blnRslt; } -bool GLShaderArray::SetDataColor(int intCol, QRgb objColor) +bool GLShaderTVArray::SetDataColor(int intCol, QRgb objColor) { bool blnRslt = false; diff --git a/plugins/channelrx/demodatv/glshaderarray.h b/sdrgui/gui/glshadertvarray.h similarity index 90% rename from plugins/channelrx/demodatv/glshaderarray.h rename to sdrgui/gui/glshadertvarray.h index 4c34969f3..b9804c547 100644 --- a/plugins/channelrx/demodatv/glshaderarray.h +++ b/sdrgui/gui/glshadertvarray.h @@ -15,8 +15,8 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#ifndef INCLUDE_GUI_GLSHADERARRAY_H_ -#define INCLUDE_GUI_GLSHADERARRAY_H_ +#ifndef INCLUDE_GUI_GLTVSHADERARRAY_H_ +#define INCLUDE_GUI_GLTVSHADERARRAY_H_ #include #include @@ -36,11 +36,11 @@ class QOpenGLShaderProgram; class QMatrix4x4; class QVector4D; -class GLShaderArray +class GLShaderTVArray { public: - GLShaderArray(); - ~GLShaderArray(); + GLShaderTVArray(bool blnColor); + ~GLShaderTVArray(); void InitializeGL(int intCols, int intRows); void ResizeContainer(int intCols, int intRows); @@ -62,7 +62,7 @@ protected: static const QString m_strVertexShaderSourceArray; static const QString m_strFragmentShaderSourceColored; - QImage *m_objImage=NULL; + QImage *m_objImage=NULL; QOpenGLTexture *m_objTexture=NULL; int m_intCols; @@ -71,6 +71,7 @@ protected: QRgb * m_objCurrentRow; bool m_blnInitialized; + bool m_blnColor; }; -#endif /* INCLUDE_GUI_GLSHADERARRAY_H_ */ +#endif /* INCLUDE_GUI_GLTVSHADERARRAY_H_ */ diff --git a/sdrgui/sdrgui.pro b/sdrgui/sdrgui.pro index 194d7b396..2810484c8 100644 --- a/sdrgui/sdrgui.pro +++ b/sdrgui/sdrgui.pro @@ -64,6 +64,7 @@ SOURCES += mainwindow.cpp\ gui/glscopenggui.cpp\ gui/glshadersimple.cpp\ gui/glshadertextured.cpp\ + gui/glshadertvarray.cpp\ gui/glspectrum.cpp\ gui/glspectrumgui.cpp\ gui/indicator.cpp\ @@ -114,6 +115,7 @@ HEADERS += mainwindow.h\ gui/glscopenggui.h\ gui/glshadersimple.h\ gui/glshadertextured.h\ + gui/glshadertvarray.h\ gui/glspectrum.h\ gui/glspectrumgui.h\ gui/indicator.h\