]> git.sesse.net Git - nageru/commitdiff
Use QGLWidget instead of QOpenGLWidget, as the latter is too slow.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 4 Oct 2015 16:06:15 +0000 (18:06 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 4 Oct 2015 16:06:15 +0000 (18:06 +0200)
Makefile
context.cpp
context.h
glwidget.cpp
glwidget.h
main.cpp
ui_mainwindow.ui

index 16bd2b532adb77057bda90150b97b2c90417afd3..aa320d4809744f75cc9a599b368aea54b4a386f3 100644 (file)
--- 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
index 72275e9f9ba5db18d039e8c6e577356a6f9aa2b0..946d40dc84ab1b0c5462311f6e4bdf1af3355f10 100644 (file)
@@ -4,6 +4,9 @@
 #include <QOpenGLContext>
 #include <QOffscreenSurface>
 #include <QWindow>
+#include <QGLWidget>
+
+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;
 }
index 5a7576665c6dda60c0781f15c92c70ab5bce7d9b..c670473015054c4156fadc39f6337b6318b17012 100644 (file)
--- 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);
index 17f7832378c67dd59c7e45183bd5bda1d23e2860..6e216a6700d88212a508fe457fb6e889a584c383 100644 (file)
@@ -18,7 +18,7 @@
 #include <movit/util.h>
 
 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;
index d2ff50cb5017ea48ba3698d5febafa8de604252e..bb62940d6d5a16830db12797b837c956fd73b7cb 100644 (file)
@@ -1,13 +1,17 @@
 #ifndef GLWIDGET_H
 #define GLWIDGET_H
 
-#include <QOpenGLWidget>
+#include <QGLWidget>
 
 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:
index b39fafe2c837d285d4ffb294726b710a0f8a06e2..8ebe6d21ca7b790a4968045089519a5e83ba5080 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -3,9 +3,11 @@
 #include <QDesktopWidget>
 #include <QSurfaceFormat>
 #include <QtGui/QOpenGLContext>
+#include <QGLFormat>
 
 #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();
index 8240ecfc542e4cef165afdd28c4eabf3ddba0425..b7091f9231c914978bd3a3cf3a9392c56610b688 100644 (file)
@@ -34,7 +34,7 @@
            <number>0</number>
           </property>
           <item>
-           <widget class="QOpenGLWidget" name="me_preview">
+           <widget class="QGLWidget" name="me_preview">
             <property name="sizePolicy">
              <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
               <horstretch>1</horstretch>
          <number>0</number>
         </property>
         <item>
-         <widget class="QOpenGLWidget" name="preview2">
+         <widget class="QGLWidget" name="preview2">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
             <horstretch>1</horstretch>
          </widget>
         </item>
         <item>
-         <widget class="QOpenGLWidget" name="preview1">
+         <widget class="QGLWidget" name="preview1">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
             <horstretch>1</horstretch>
          </widget>
         </item>
         <item>
-         <widget class="QOpenGLWidget" name="preview3">
+         <widget class="QGLWidget" name="preview3">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
             <horstretch>1</horstretch>
          </widget>
         </item>
         <item>
-         <widget class="QOpenGLWidget" name="preview4">
+         <widget class="QGLWidget" name="preview4">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
             <horstretch>1</horstretch>
  <customwidgets>
   <customwidget>
    <class>GLWidget</class>
-   <extends>QOpenGLWidget</extends>
+   <extends>QGLWidget</extends>
    <header>glwidget.h</header>
   </customwidget>
  </customwidgets>