[PATCH v4l-utils v1 2/4] qv4l2: enable Qt6 compile with Qt OpenGL support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Peter Seiderer <ps.report@xxxxxxx>
---
 utils/qv4l2/capture-win-gl.cpp | 125 ++++++++++++++++++++++++++++++---
 utils/qv4l2/capture-win-gl.h   |  17 +++++
 utils/qv4l2/qv4l2.cpp          |   4 ++
 utils/qv4l2/qv4l2.pro          |   3 +
 4 files changed, 138 insertions(+), 11 deletions(-)

diff --git a/utils/qv4l2/capture-win-gl.cpp b/utils/qv4l2/capture-win-gl.cpp
index 6cbeb426..7e993e3b 100644
--- a/utils/qv4l2/capture-win-gl.cpp
+++ b/utils/qv4l2/capture-win-gl.cpp
@@ -151,7 +151,9 @@ CaptureWinGLEngine::CaptureWinGLEngine() :
 	m_min_filter(GL_NEAREST)
 {
 	makeCurrent();
+#if QT_VERSION < 0x060000
 	m_glfunction.initializeGLFunctions(context());
+#endif
 }
 
 CaptureWinGLEngine::~CaptureWinGLEngine()
@@ -285,6 +287,9 @@ void CaptureWinGLEngine::stop()
 
 void CaptureWinGLEngine::initializeGL()
 {
+#if QT_VERSION >= 0x060000
+	initializeOpenGLFunctions();
+#endif
 	glShadeModel(GL_FLAT);
 	glEnable(GL_TEXTURE_2D);
 	glEnable(GL_BLEND);
@@ -337,7 +342,11 @@ void CaptureWinGLEngine::setFrame(int width, int height, int WCrop, int HCrop,
 	m_frameData = data;
 	m_frameData2 = data2 ? data2 : data;
 	m_frameData3 = data3 ? data3 : data;
+#if QT_VERSION < 0x060000
 	updateGL();
+#else
+	update();
+#endif
 }
 
 void CaptureWinGLEngine::checkError(const char *msg)
@@ -431,8 +440,13 @@ bool CaptureWinGLEngine::hasNativeFormat(__u32 format)
 		0
 	};
 
+#if QT_VERSION < 0x060000
 	if (!m_glfunction.hasOpenGLFeature(QGLFunctions::Shaders))
 		return false;
+#else
+	if (!hasOpenGLFeature(QOpenGLFunctions::Shaders))
+		return false;
+#endif
 
 	for (int i = 0; supported_fmts[i]; i++)
 		if (supported_fmts[i] == format)
@@ -449,7 +463,11 @@ void CaptureWinGLEngine::changeShader()
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
 	glOrtho(0, m_frameWidth, m_frameHeight, 0, 0, 1);
+#if QT_VERSION < 0x060000
 	resizeGL(QGLWidget::width(), QGLWidget::height());
+#else
+	resizeGL(QOpenGLWidget::width(), QOpenGLWidget::height());
+#endif
 	checkError("Render settings.\n");
 
 	switch (m_frameFormat) {
@@ -1010,7 +1028,12 @@ void CaptureWinGLEngine::shader_YUV(__u32 format)
 			   codeSuffix;
 
 	bool src_c = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, codeHead + codeTail);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				codeHead + codeTail);
 
 	if (!src_c)
 		fprintf(stderr, "OpenGL Error: YUV shader compilation failed.\n");
@@ -1053,7 +1076,11 @@ void CaptureWinGLEngine::render_YUV(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1061,7 +1088,11 @@ void CaptureWinGLEngine::render_YUV(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint U = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "utex");
+#else
+	GLint U = glGetUniformLocation(m_shaderProgram.programId(), "utex");
+#endif
 	glUniform1i(U, 1);
 	switch (format) {
 	case V4L2_PIX_FMT_YUV422P:
@@ -1087,7 +1118,11 @@ void CaptureWinGLEngine::render_YUV(__u32 format)
 
 	glActiveTexture(GL_TEXTURE2);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[2]);
+#if QT_VERSION < 0x060000
 	GLint V = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "vtex");
+#else
+	GLint V = glGetUniformLocation(m_shaderProgram.programId(), "vtex");
+#endif
 	glUniform1i(V, 2);
 	switch (format) {
 	case V4L2_PIX_FMT_YUV422P:
@@ -1189,7 +1224,11 @@ void CaptureWinGLEngine::shader_NV12(__u32 format)
 			   codeSuffix;
 
 	bool src_c = m_shaderProgram.addShaderFromSourceCode(
+#if QT_VERSION < 0x060000
 				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
 				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_c)
@@ -1211,7 +1250,11 @@ void CaptureWinGLEngine::render_NV12(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1219,7 +1262,11 @@ void CaptureWinGLEngine::render_NV12(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint U = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#else
+	GLint U = glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#endif
 	glUniform1i(U, 1);
 	switch (format) {
 	case V4L2_PIX_FMT_NV12:
@@ -1307,7 +1354,11 @@ void CaptureWinGLEngine::shader_NV24(__u32 format)
 			   codeSuffix;
 
 	bool src_c = m_shaderProgram.addShaderFromSourceCode(
+#if QT_VERSION < 0x060000
 				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
 				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_c)
@@ -1327,7 +1378,11 @@ void CaptureWinGLEngine::render_NV24(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1335,7 +1390,11 @@ void CaptureWinGLEngine::render_NV24(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint U = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#else
+	GLint U = glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#endif
 	glUniform1i(U, 1);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRedGreen, GL_UNSIGNED_BYTE,
@@ -1419,8 +1478,12 @@ void CaptureWinGLEngine::shader_NV16(__u32 format)
 			   codeSuffix;
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2%3").arg(codeHead, codeBody, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: NV16 shader compilation failed.\n");
@@ -1440,7 +1503,11 @@ void CaptureWinGLEngine::render_NV16(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1448,7 +1515,11 @@ void CaptureWinGLEngine::render_NV16(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint UV = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#else
+	GLint UV = glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#endif
 	glUniform1i(UV, 1);
 	switch (format) {
 	case V4L2_PIX_FMT_NV16:
@@ -1559,8 +1630,12 @@ void CaptureWinGLEngine::shader_YUY2(__u32 format)
 			   codeSuffix;
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2%3").arg(codeHead, codeBody, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: YUY2 shader compilation failed.\n");
@@ -1580,7 +1655,11 @@ void CaptureWinGLEngine::render_YUY2(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth / 2, m_frameHeight,
 			GL_RGBA, GL_UNSIGNED_BYTE, m_frameData);
@@ -1785,8 +1864,12 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
 		    (hasAlpha ? codeSuffixWithAlpha : codeSuffix);
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2").arg(codeHead, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2").arg(codeHead, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: RGB shader compilation failed.\n");
@@ -1798,7 +1881,11 @@ void CaptureWinGLEngine::render_RGB(__u32 format)
 {
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	int idx = glGetUniformLocation(m_shaderProgram.programId(), "tex_h"); // Texture height
 	glUniform1f(idx, m_frameHeight);
@@ -2016,8 +2103,12 @@ void CaptureWinGLEngine::shader_Bayer(__u32 format)
 		    codeSuffix;
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2").arg(codeHead, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2").arg(codeHead, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: Bayer shader compilation failed.\n");
@@ -2029,7 +2120,11 @@ void CaptureWinGLEngine::render_Bayer(__u32 format)
 {
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	int idx = glGetUniformLocation(m_shaderProgram.programId(), "tex_h"); // Texture height
 	glUniform1f(idx, m_frameHeight);
@@ -2146,8 +2241,12 @@ void CaptureWinGLEngine::shader_YUV_packed(__u32 format)
 			   (hasAlpha ? codeSuffixWithAlpha : codeSuffix);
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2").arg(codeHead, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2").arg(codeHead, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: Packed YUV shader compilation failed.\n");
@@ -2159,7 +2258,11 @@ void CaptureWinGLEngine::render_YUV_packed(__u32 format)
 {
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	int idx = glGetUniformLocation(m_shaderProgram.programId(), "tex_h"); // Texture height
 	glUniform1f(idx, m_frameHeight);
diff --git a/utils/qv4l2/capture-win-gl.h b/utils/qv4l2/capture-win-gl.h
index e27b2b3f..96376934 100644
--- a/utils/qv4l2/capture-win-gl.h
+++ b/utils/qv4l2/capture-win-gl.h
@@ -10,10 +10,17 @@
 #define GL_GLEXT_PROTOTYPES
 #define QT_NO_OPENGL_ES_2
 
+#include <QtCore>
+#if QT_VERSION < 0x060000
 #include <QGLWidget>
 #include <QGLShader>
 #include <QGLShaderProgram>
 #include <QGLFunctions>
+#else
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions>
+#include <QOpenGLShaderProgram>
+#endif
 #endif
 
 #include "qv4l2.h"
@@ -26,7 +33,11 @@
 // This must be equal to the max number of textures that any shader uses
 #define MAX_TEXTURES_NEEDED 3
 
+#if QT_VERSION < 0x060000
 class CaptureWinGLEngine : public QGLWidget
+#else
+class CaptureWinGLEngine : public QOpenGLWidget, protected QOpenGLFunctions
+#endif
 {
 public:
 	CaptureWinGLEngine();
@@ -102,11 +113,17 @@ private:
 	bool m_formatChange;
 	__u32 m_frameFormat;
 	GLuint m_screenTexture[MAX_TEXTURES_NEEDED];
+#if QT_VERSION < 0x060000
 	QGLFunctions m_glfunction;
+#endif
 	unsigned char *m_frameData;
 	unsigned char *m_frameData2;
 	unsigned char *m_frameData3;
+#if QT_VERSION < 0x060000
 	QGLShaderProgram m_shaderProgram;
+#else
+	QOpenGLShaderProgram m_shaderProgram;
+#endif
 	bool m_haveFramebufferSRGB;
 	bool m_hasGLRed;
 	unsigned m_glRed;
diff --git a/utils/qv4l2/qv4l2.cpp b/utils/qv4l2/qv4l2.cpp
index e37ee87f..534bedb2 100644
--- a/utils/qv4l2/qv4l2.cpp
+++ b/utils/qv4l2/qv4l2.cpp
@@ -401,7 +401,11 @@ void ApplicationWindow::setDevice(const QString &device, bool rawOpen)
 {
 	closeDevice();
 	m_sigMapper = new QSignalMapper(this);
+#if QT_VERSION < 0x060000
 	connect(m_sigMapper, SIGNAL(mapped(int)), this, SLOT(ctrlAction(int)));
+#else
+	connect(m_sigMapper, &QSignalMapper::mappedInt, this, &ApplicationWindow::ctrlAction);
+#endif
 
 	s_direct(rawOpen);
 
diff --git a/utils/qv4l2/qv4l2.pro b/utils/qv4l2/qv4l2.pro
index 1ea07374..a9343c89 100644
--- a/utils/qv4l2/qv4l2.pro
+++ b/utils/qv4l2/qv4l2.pro
@@ -8,6 +8,9 @@ CONFIG += debug
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
+# opengl: to disable opengl suppport on Qt6 comment out the
+# following line
+greaterThan(QT_MAJOR_VERSION, 5): QT += openglwidgets
 
 # adjust to your local meson build path
 MESON_BUILD_PATH = $$PWD/build-meson
-- 
2.42.1


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux