| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 13:31:45 +01:00
										 |  |  |  | // 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>                     //
 | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | // 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/>.          //
 | 
					
						
							|  |  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 13:31:45 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | #ifndef INCLUDE_TVSCREENANALOG_H
 | 
					
						
							|  |  |  |  | #define INCLUDE_TVSCREENANALOG_H
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "export.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  |  | #include <QTimer>
 | 
					
						
							| 
									
										
										
										
											2022-03-18 18:13:08 +01:00
										 |  |  |  | #include <QOpenGLWidget>
 | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | #include <QOpenGLTexture>
 | 
					
						
							|  |  |  |  | #include <QOpenGLFunctions>
 | 
					
						
							|  |  |  |  | #include <QOpenGLShaderProgram>
 | 
					
						
							| 
									
										
										
										
											2022-06-19 23:22:43 +01:00
										 |  |  |  | #include <QOpenGLVertexArrayObject>
 | 
					
						
							|  |  |  |  | #include <QOpenGLBuffer>
 | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 15:54:34 +03:00
										 |  |  |  | class TVScreenAnalogBuffer | 
					
						
							| 
									
										
										
										
											2020-08-04 17:02:06 +03:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-08-10 15:54:34 +03:00
										 |  |  |  | 	TVScreenAnalogBuffer(int width, int height) | 
					
						
							| 
									
										
										
										
											2020-08-04 17:02:06 +03: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); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 15:54:34 +03:00
										 |  |  |  | 	~TVScreenAnalogBuffer() | 
					
						
							| 
									
										
										
										
											2020-08-04 17:02:06 +03: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; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-18 18:13:08 +01:00
										 |  |  |  | class SDRGUI_API TVScreenAnalog : public QOpenGLWidget, protected QOpenGLFunctions | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 15:54:34 +03:00
										 |  |  |  | 	QTimer m_updateTimer; | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	bool m_isDataChanged; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 17:02:06 +03:00
										 |  |  |  | 	int m_textureLoc1; | 
					
						
							|  |  |  |  | 	int m_textureLoc2; | 
					
						
							|  |  |  |  | 	int m_imageWidthLoc; | 
					
						
							|  |  |  |  | 	int m_imageHeightLoc; | 
					
						
							|  |  |  |  | 	int m_texelWidthLoc; | 
					
						
							|  |  |  |  | 	int m_texelHeightLoc; | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 	int m_vertexAttribIndex; | 
					
						
							|  |  |  |  | 	int m_texCoordAttribIndex; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 15:54:34 +03:00
										 |  |  |  | 	QMutex m_buffersMutex; | 
					
						
							| 
									
										
										
										
											2020-12-10 07:28:55 +01:00
										 |  |  |  | 	TVScreenAnalogBuffer *m_frontBuffer; | 
					
						
							|  |  |  |  | 	TVScreenAnalogBuffer *m_backBuffer; | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-10 07:28:55 +01:00
										 |  |  |  | 	QOpenGLShaderProgram *m_shader; | 
					
						
							| 
									
										
										
										
											2022-06-19 23:22:43 +01:00
										 |  |  |  |     QOpenGLVertexArrayObject *m_vao; | 
					
						
							|  |  |  |  |     QOpenGLBuffer *m_verticesBuf; | 
					
						
							|  |  |  |  |     QOpenGLBuffer *m_textureCoordsBuf; | 
					
						
							| 
									
										
										
										
											2020-12-10 07:28:55 +01:00
										 |  |  |  | 	QOpenGLTexture *m_imageTexture; | 
					
						
							|  |  |  |  | 	QOpenGLTexture *m_lineShiftsTexture; | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | public: | 
					
						
							|  |  |  |  | 	TVScreenAnalog(QWidget *parent); | 
					
						
							| 
									
										
										
										
											2020-12-10 07:28:55 +01:00
										 |  |  |  | 	~TVScreenAnalog(); | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-10 07:28:55 +01:00
										 |  |  |  | 	TVScreenAnalogBuffer *getBackBuffer(); | 
					
						
							|  |  |  |  | 	TVScreenAnalogBuffer *swapBuffers(); | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 	void resizeTVScreen(int intCols, int intRows); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-12-10 07:28:55 +01:00
										 |  |  |  | 	void initializeTextures(TVScreenAnalogBuffer *buffer); | 
					
						
							| 
									
										
										
										
											2020-08-03 19:31:47 +03:00
										 |  |  |  | 	void initializeGL() override; | 
					
						
							|  |  |  |  | 	void paintGL() override; | 
					
						
							|  |  |  |  | 	void resizeGL(int width, int height); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | private slots: | 
					
						
							|  |  |  |  | 	void cleanup(); | 
					
						
							|  |  |  |  | 	void tick(); | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #endif // INCLUDE_TVSCREENANALOG_H
 |