Olive
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
renderthread.h
Go to the documentation of this file.
1 /***
2 
3  Olive - Non-Linear Video Editor
4  Copyright (C) 2019 Olive Team
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 ***/
20 
21 #ifndef RENDERTHREAD_H
22 #define RENDERTHREAD_H
23 
24 #include <QThread>
25 #include <QMutex>
26 #include <QWaitCondition>
27 #include <QOffscreenSurface>
28 #include <QOpenGLContext>
29 #include <QOpenGLFramebufferObject>
30 #include <QOpenGLShaderProgram>
31 
32 #include "timeline/sequence.h"
33 #include "effects/effect.h"
35 
36 // copied from source code to OCIODisplay
37 const int LUT3D_EDGE_SIZE = 32;
38 
39 // copied from source code to OCIODisplay, expanded from 3*LUT3D_EDGE_SIZE*LUT3D_EDGE_SIZE*LUT3D_EDGE_SIZE
40 const int NUM_3D_ENTRIES = 98304;
41 
42 class RenderThread : public QThread {
43  Q_OBJECT
44 public:
45  RenderThread();
46  ~RenderThread();
47  void run();
48 
49  QMutex* get_texture_mutex();
50  const GLuint& get_texture();
51 
53  void paint();
54  void start_render(QOpenGLContext* share,
55  Sequence *s,
56  int playback_speed,
57  const QString &save = nullptr,
58  GLvoid *pixels = nullptr,
59  int pixel_linesize = 0,
60  int idivider = 0,
61  bool wait = false);
62  bool did_texture_fail();
63  void cancel();
64  void wait_until_paused();
65 
66 public slots:
67  // cleanup functions
68  void delete_ctx();
69 signals:
70  void ready();
71 private:
72  // cleanup functions
73  void delete_buffers();
74  void delete_shaders();
75 
76  void set_up_ocio();
77  void destroy_ocio();
78 
80  QMutex front_mutex1;
81 
83  QMutex front_mutex2;
84 
86 
87  QWaitCondition wait_cond_;
88  QMutex wait_lock_;
89 
90  QWaitCondition main_thread_wait_cond_;
92 
93  QOffscreenSurface surface;
94  QOpenGLContext* share_ctx;
95  QOpenGLContext* ctx;
96  QOpenGLShaderProgram* blend_mode_program;
97  QOpenGLShaderProgram* premultiply_program;
98 
101 
104  QOpenGLShaderProgram* ocio_shader;
105 
108  int divider;
111  QAtomicInt queued;
113  bool running;
114  QString save_fn;
115  GLvoid *pixel_buffer;
117 };
118 
119 #endif // RENDERTHREAD_H
QMutex wait_lock_
Definition: renderthread.h:88
void start_render(QOpenGLContext *share, Sequence *s, int playback_speed, const QString &save=nullptr, GLvoid *pixels=nullptr, int pixel_linesize=0, int idivider=0, bool wait=false)
Definition: renderthread.cpp:231
QOpenGLShaderProgram * blend_mode_program
Definition: renderthread.h:96
QWaitCondition main_thread_wait_cond_
Definition: renderthread.h:90
GLuint ocio_lut_texture
Definition: renderthread.h:103
QOpenGLContext * share_ctx
Definition: renderthread.h:94
int tex_width
Definition: renderthread.h:109
QWaitCondition wait_cond_
Definition: renderthread.h:87
QOpenGLShaderProgram * premultiply_program
Definition: renderthread.h:97
int tex_height
Definition: renderthread.h:110
FramebufferObject front_buffer_2
Definition: renderthread.h:82
QMutex front_mutex1
Definition: renderthread.h:80
QMutex front_mutex2
Definition: renderthread.h:83
int divider
Definition: renderthread.h:108
QString save_fn
Definition: renderthread.h:114
FramebufferObject back_buffer_2
Definition: renderthread.h:100
void delete_shaders()
Definition: renderthread.cpp:308
QOffscreenSurface surface
Definition: renderthread.h:93
QMutex * get_texture_mutex()
Definition: renderthread.cpp:126
void cancel()
Definition: renderthread.cpp:279
GLvoid * pixel_buffer
Definition: renderthread.h:115
RenderThread()
Definition: renderthread.cpp:36
int pixel_buffer_linesize
Definition: renderthread.h:116
bool did_texture_fail()
Definition: renderthread.cpp:275
int playback_speed_
Definition: renderthread.h:107
const GLuint & get_texture()
Definition: renderthread.cpp:132
float ocio_lut_data[NUM_3D_ENTRIES]
Definition: renderthread.h:102
void set_up_ocio()
Definition: renderthread.cpp:138
Definition: renderthread.h:42
FramebufferObject back_buffer_1
Definition: renderthread.h:99
void destroy_ocio()
QOpenGLShaderProgram * ocio_shader
Definition: renderthread.h:104
QAtomicInt queued
Definition: renderthread.h:111
~RenderThread()
Definition: renderthread.cpp:53
void wait_until_paused()
Definition: renderthread.cpp:285
void delete_ctx()
Definition: renderthread.cpp:316
QMutex main_thread_lock_
Definition: renderthread.h:91
bool running
Definition: renderthread.h:113
bool front_buffer_switcher
Definition: renderthread.h:85
const int NUM_3D_ENTRIES
Definition: renderthread.h:40
FramebufferObject front_buffer_1
Definition: renderthread.h:79
Effect * gizmos
Definition: renderthread.h:52
const int LUT3D_EDGE_SIZE
Definition: renderthread.h:37
Sequence * seq
Definition: renderthread.h:106
void delete_buffers()
Definition: renderthread.cpp:301
Definition: sequence.h:31
void run()
Definition: renderthread.cpp:57
bool texture_failed
Definition: renderthread.h:112
Definition: framebufferobject.h:6
Definition: effect.h:136
void paint()
Definition: renderthread.cpp:142
QOpenGLContext * ctx
Definition: renderthread.h:95