]> git.sesse.net Git - nageru/blob - glwidget.cpp
Remove more std:: instances.
[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 #include <movit/resource_pool.h>
11
12 #include "glwidget.h"
13
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 {
38 }
39
40 void GLWidget::clean_context()
41 {
42         if (resource_pool != nullptr) {
43                 makeCurrent();
44                 resource_pool->clean_context();
45         }
46 }
47
48 void GLWidget::initializeGL()
49 {
50         static once_flag flag;
51         call_once(flag, [this]{
52                 global_mixer = new Mixer(QGLFormat::toSurfaceFormat(format()), global_flags.num_cards);
53                 global_mainwindow->mixer_created(global_mixer);
54                 global_mixer->start();
55         });
56         global_mixer->set_frame_ready_callback(output, [this]{
57                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
58                 emit transition_names_updated(global_mixer->get_transition_names());
59                 emit resolution_updated(output);
60         });
61
62         glDisable(GL_BLEND);
63         glDisable(GL_DEPTH_TEST);
64         glDepthMask(GL_FALSE);
65 }
66
67 void GLWidget::resizeGL(int width, int height)
68 {
69         glViewport(0, 0, width, height);
70 }
71
72 void GLWidget::paintGL()
73 {
74         Mixer::DisplayFrame frame;
75         if (!global_mixer->get_display_frame(output, &frame)) {
76                 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
77                 check_error();
78                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
79                 check_error();
80                 return;
81         }
82
83         check_error();
84         glWaitSync(frame.ready_fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
85         check_error();
86         frame.setup_chain();
87         check_error();
88         frame.chain->render_to_screen();
89         check_error();
90
91         if (resource_pool == nullptr) {
92                 resource_pool = frame.chain->get_resource_pool();
93         } else {
94                 assert(resource_pool == frame.chain->get_resource_pool());
95         }
96 }
97
98 void GLWidget::mousePressEvent(QMouseEvent *event)
99 {
100         emit clicked();
101 }