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