]> git.sesse.net Git - nageru/blob - glwidget.cpp
Remove some debugging.
[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 <qevent.h>  // Needs to come before egl.h.
7 #include <epoxy/gl.h>
8 #include <epoxy/egl.h>
9 #include <QSurfaceFormat>
10
11 #include "glwidget.h"
12
13 #include <movit/resource_pool.h>
14 #include <stdio.h>
15 #include <functional>
16 #include <mutex>
17
18 #include "context.h"
19 #include "effect_chain.h"
20 #include "flags.h"
21 #include "mainwindow.h"
22 #include "mixer.h"
23 #include "qnamespace.h"
24 #include "ref_counted_gl_sync.h"
25
26 class QMouseEvent;
27 class QWidget;
28
29 #undef Success
30 #include <movit/util.h>
31 #include <string>
32
33 using namespace std;
34
35 GLWidget::GLWidget(QWidget *parent)
36     : QGLWidget(parent, global_share_widget),
37       resource_pool(new movit::ResourcePool)
38 {
39 }
40
41 GLWidget::~GLWidget()
42 {
43 }
44
45 void GLWidget::initializeGL()
46 {
47         static std::once_flag flag;
48         std::call_once(flag, [this]{
49                 global_mixer = new Mixer(QGLFormat::toSurfaceFormat(format()), global_flags.num_cards);
50                 global_mainwindow->mixer_created(global_mixer);
51                 global_mixer->start();
52         });
53         global_mixer->set_frame_ready_callback(output, [this]{
54                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
55                 emit transition_names_updated(global_mixer->get_transition_names());
56         });
57
58         glDisable(GL_BLEND);
59         glDisable(GL_DEPTH_TEST);
60         glDepthMask(GL_FALSE);
61 }
62
63 void GLWidget::resizeGL(int width, int height)
64 {
65         glViewport(0, 0, width, height);
66 }
67
68 void GLWidget::paintGL()
69 {
70         Mixer::DisplayFrame frame;
71         if (!global_mixer->get_display_frame(output, &frame)) {
72                 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
73                 check_error();
74                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
75                 check_error();
76                 return;
77         }
78
79         check_error();
80         glWaitSync(frame.ready_fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
81         check_error();
82         frame.setup_chain();
83         check_error();
84         frame.chain->render_to_screen();
85         check_error();
86 }
87
88 void GLWidget::mousePressEvent(QMouseEvent *event)
89 {
90         emit clicked();
91 }