1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 16:38:37 -05:00
sdrangel/sdrgui/gui/tvscreenanalog.h

164 lines
4.5 KiB
C
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2020 Vort <vvort@yandex.ru> //
// Copyright (C) 2022 Jon Beniston, M7RCE <jon@beniston.com> //
// Copyright (C) 2018 F4HKW //
// for F4EXB / SDRAngel //
// //
// OpenGL interface modernization. //
// See: http://doc.qt.io/qt-5/qopenglshaderprogram.html //
// //
// 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 //
// (at your option) any later version. //
// //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_TVSCREENANALOG_H
#define INCLUDE_TVSCREENANALOG_H
#include "export.h"
#include <QMutex>
#include <QTimer>
#include <QOpenGLWidget>
#include <QOpenGLTexture>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
2022-06-19 18:22:43 -04:00
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
class TVScreenAnalogBuffer
2020-08-04 10:02:06 -04:00
{
public:
TVScreenAnalogBuffer(int width, int height)
2020-08-04 10:02:06 -04:00
{
m_width = width;
m_height = height;
m_imageData = new int[width * height];
m_lineShiftData = new int[height];
m_outOfBoundsLine = new int[width];
m_currentLine = m_outOfBoundsLine;
std::fill(m_imageData, m_imageData + width * height, 0);
std::fill(m_lineShiftData, m_lineShiftData + height, 127);
}
~TVScreenAnalogBuffer()
2020-08-04 10:02:06 -04:00
{
delete[] m_imageData;
delete[] m_lineShiftData;
delete[] m_outOfBoundsLine;
}
int getWidth()
{
return m_width;
}
int getHeight()
{
return m_height;
}
const int* getImageData()
{
return m_imageData;
}
const int* getLineShiftData()
{
return m_lineShiftData;
}
void selectRow(int line, float shift)
{
if ((line < m_height) && (line >= 0))
{
m_currentLine = m_imageData + line * m_width;
m_lineShiftData[line] = (1.0f + shift) * 127.5f;
}
else
{
m_currentLine = m_outOfBoundsLine;
}
}
void setSampleValue(int column, int value)
{
if ((column < m_width - 2) && (column >= -2))
{
m_currentLine[column + 2] = value;
}
}
private:
int m_width;
int m_height;
int* m_imageData;
int* m_lineShiftData;
int* m_currentLine;
int* m_outOfBoundsLine;
};
class SDRGUI_API TVScreenAnalog : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
QTimer m_updateTimer;
bool m_isDataChanged;
2020-08-04 10:02:06 -04:00
int m_textureLoc1;
int m_textureLoc2;
int m_imageWidthLoc;
int m_imageHeightLoc;
int m_texelWidthLoc;
int m_texelHeightLoc;
int m_vertexAttribIndex;
int m_texCoordAttribIndex;
QMutex m_buffersMutex;
TVScreenAnalogBuffer *m_frontBuffer;
TVScreenAnalogBuffer *m_backBuffer;
QOpenGLShaderProgram *m_shader;
2022-06-19 18:22:43 -04:00
QOpenGLVertexArrayObject *m_vao;
QOpenGLBuffer *m_verticesBuf;
QOpenGLBuffer *m_textureCoordsBuf;
QOpenGLTexture *m_imageTexture;
QOpenGLTexture *m_lineShiftsTexture;
public:
TVScreenAnalog(QWidget *parent);
~TVScreenAnalog();
TVScreenAnalogBuffer *getBackBuffer();
TVScreenAnalogBuffer *swapBuffers();
void resizeTVScreen(int intCols, int intRows);
private:
void initializeTextures(TVScreenAnalogBuffer *buffer);
void initializeGL() override;
void paintGL() override;
void resizeGL(int width, int height);
private slots:
void cleanup();
void tick();
};
#endif // INCLUDE_TVSCREENANALOG_H