]> git.sesse.net Git - nageru/blob - glwidget.cpp
Wire the transition names through to the UI.
[nageru] / glwidget.cpp
1 #include <qmetatype.h>  // Needs to come before egl.h.
2 #include <qdatastream.h>  // Needs to come before egl.h.
3 #include <qtextstream.h>  // Needs to come before egl.h.
4 #include <qcursor.h>  // Needs to come before egl.h.
5 #include <qcoreevent.h>  // Needs to come before egl.h.
6 #include <epoxy/gl.h>
7 #include <epoxy/egl.h>
8 #include <QSurfaceFormat>
9
10 #include "glwidget.h"
11 #include "mainwindow.h"
12
13 #include <movit/resource_pool.h>
14 #include <stdio.h>
15 #include <mutex>
16
17 #include "context.h"
18 #include "mixer.h"
19 #include "ref_counted_gl_sync.h"
20
21 class MainWindow;
22 class QSurface;
23 class QWidget;
24
25 #undef Success
26 #include <movit/util.h>
27 #include <string>
28
29 using namespace std;
30
31 GLWidget::GLWidget(QWidget *parent)
32     : QGLWidget(parent, global_share_widget),
33       resource_pool(new movit::ResourcePool)
34 {
35 }
36
37 GLWidget::~GLWidget()
38 {
39 }
40
41 void GLWidget::initializeGL()
42 {
43         printf("egl context=%p\n", eglGetCurrentContext());
44         //printf("threads: %p %p\n", QThread::currentThread(), qGuiApp->thread());
45
46         static std::once_flag flag;
47         std::call_once(flag, [this]{
48                 global_mixer = new Mixer(QGLFormat::toSurfaceFormat(format()));
49                 global_mixer->start();
50         });
51         global_mixer->set_frame_ready_callback(output, [this]{
52                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
53                 emit transition_names_updated(global_mixer->get_transition_names());
54         });
55
56         glDisable(GL_BLEND);
57         glDisable(GL_DEPTH_TEST);
58         glDepthMask(GL_FALSE);
59 }
60
61 void GLWidget::resizeGL(int width, int height)
62 {
63         glViewport(0, 0, width, height);
64 }
65
66 void GLWidget::paintGL()
67 {
68         Mixer::DisplayFrame frame;
69         if (!global_mixer->get_display_frame(output, &frame)) {
70                 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
71                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
72                 return;
73         }
74
75         glWaitSync(frame.ready_fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
76         frame.setup_chain();
77         frame.chain->render_to_screen();
78         check_error();
79 }
80
81 void GLWidget::mousePressEvent(QMouseEvent *event)
82 {
83         emit clicked();
84 }