From 95295bd41bc711bbc450ac6f5ccc68e64fefffa3 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 4 Oct 2015 18:06:15 +0200 Subject: [PATCH] Use QGLWidget instead of QOpenGLWidget, as the latter is too slow. --- Makefile | 4 ++-- context.cpp | 5 ++++- context.h | 2 ++ glwidget.cpp | 16 +++++++++++----- glwidget.h | 9 +++++++-- main.cpp | 6 ++++++ ui_mainwindow.ui | 12 ++++++------ 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 16bd2b5..aa320d4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXX=g++ -CXXFLAGS := -O2 -march=native -g -std=gnu++11 -Wall -Wno-deprecated-declarations -fPIC $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets Qt5OpenGLExtensions libusb-1.0 movit) -pthread -DMOVIT_SHADER_DIR=\"$(shell pkg-config --variable=shaderdir movit)\" -LDFLAGS=$(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets Qt5OpenGLExtensions libusb-1.0 movit) -lEGL -lGL -pthread -lva -lva-drm -lva-x11 -lX11 -lavformat -lavcodec -lavutil +CXXFLAGS := -O2 -march=native -g -std=gnu++11 -Wall -Wno-deprecated-declarations -fPIC $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets Qt5OpenGLExtensions Qt5OpenGL libusb-1.0 movit) -pthread -DMOVIT_SHADER_DIR=\"$(shell pkg-config --variable=shaderdir movit)\" +LDFLAGS=$(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets Qt5OpenGLExtensions Qt5OpenGL libusb-1.0 movit) -lEGL -lGL -pthread -lva -lva-drm -lva-x11 -lX11 -lavformat -lavcodec -lavutil # Qt objects OBJS=glwidget.o main.o mainwindow.o window.o diff --git a/context.cpp b/context.cpp index 72275e9..946d40d 100644 --- a/context.cpp +++ b/context.cpp @@ -4,6 +4,9 @@ #include #include #include +#include + +QGLWidget *global_share_widget = nullptr; QSurface *create_surface(const QSurfaceFormat &format) { @@ -21,7 +24,7 @@ QSurface *create_surface(const QSurfaceFormat &format) QOpenGLContext *create_context() { QOpenGLContext *context = new QOpenGLContext; - context->setShareContext(QOpenGLContext::globalShareContext()); + context->setShareContext(global_share_widget->context()->contextHandle()); context->create(); return context; } diff --git a/context.h b/context.h index 5a75766..c670473 100644 --- a/context.h +++ b/context.h @@ -5,7 +5,9 @@ class QSurface; class QOpenGLContext; class QSurfaceFormat; +class QGLWidget; +extern QGLWidget *global_share_widget; QSurface *create_surface(const QSurfaceFormat &format); QOpenGLContext *create_context(); bool make_current(QOpenGLContext *context, QSurface *surface); diff --git a/glwidget.cpp b/glwidget.cpp index 17f7832..6e216a6 100644 --- a/glwidget.cpp +++ b/glwidget.cpp @@ -18,7 +18,7 @@ #include GLWidget::GLWidget(QWidget *parent) - : QOpenGLWidget(parent), + : QGLWidget(parent, global_share_widget), resource_pool(new movit::ResourcePool) { } @@ -37,10 +37,11 @@ void GLWidget::initializeGL() QMetaObject::invokeMethod(t, "update", Qt::AutoConnection); }); - QSurface *surface = create_surface(format()); - QSurface *surface2 = create_surface(format()); - QSurface *surface3 = create_surface(format()); - QSurface *surface4 = create_surface(format()); + QSurfaceFormat fmt = QGLFormat::toSurfaceFormat(format()); + QSurface *surface = create_surface(fmt); + QSurface *surface2 = create_surface(fmt); + QSurface *surface3 = create_surface(fmt); + QSurface *surface4 = create_surface(fmt); start_mixer(surface, surface2, surface3, surface4); // Prepare the shaders to actually get the texture shown (ick). @@ -89,6 +90,11 @@ void GLWidget::initializeGL() #endif } +void GLWidget::resizeGL(int width, int height) +{ + glViewport(0, 0, width, height); +} + void GLWidget::paintGL() { DisplayFrame frame; diff --git a/glwidget.h b/glwidget.h index d2ff50c..bb62940 100644 --- a/glwidget.h +++ b/glwidget.h @@ -1,13 +1,17 @@ #ifndef GLWIDGET_H #define GLWIDGET_H -#include +#include namespace movit { class ResourcePool; } -class GLWidget : public QOpenGLWidget +// Note: We use the older QGLWidget instead of QOpenGLWidget as it is +// much faster (does not go through a separate offscreen rendering step). +// +// TODO: Consider if QOpenGLWindow could do what we want. +class GLWidget : public QGLWidget { Q_OBJECT @@ -17,6 +21,7 @@ public: protected: void initializeGL() override; + void resizeGL(int width, int height) override; void paintGL() override; private: diff --git a/main.cpp b/main.cpp index b39fafe..8ebe6d2 100644 --- a/main.cpp +++ b/main.cpp @@ -3,9 +3,11 @@ #include #include #include +#include #include "mainwindow.h" #include "mixer.h" +#include "context.h" int main(int argc, char *argv[]) { @@ -22,6 +24,10 @@ int main(int argc, char *argv[]) fmt.setMinorVersion(1); QSurfaceFormat::setDefaultFormat(fmt); + QGLFormat::setDefaultFormat(QGLFormat::fromSurfaceFormat(fmt)); + + global_share_widget = new QGLWidget(); + MainWindow mainWindow; mainWindow.resize(QSize(1280, 720)); mainWindow.show(); diff --git a/ui_mainwindow.ui b/ui_mainwindow.ui index 8240ecf..b7091f9 100644 --- a/ui_mainwindow.ui +++ b/ui_mainwindow.ui @@ -34,7 +34,7 @@ 0 - + 1 @@ -140,7 +140,7 @@ 0 - + 1 @@ -150,7 +150,7 @@ - + 1 @@ -160,7 +160,7 @@ - + 1 @@ -170,7 +170,7 @@ - + 1 @@ -232,7 +232,7 @@ GLWidget - QOpenGLWidget + QGLWidget
glwidget.h
-- 2.39.2