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" 34 #include "rendering/framebufferobject.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 52 Effect* gizmos; 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 79 FramebufferObject front_buffer_1; 80 QMutex front_mutex1; 81 82 FramebufferObject front_buffer_2; 83 QMutex front_mutex2; 84 85 bool front_buffer_switcher; 86 87 QWaitCondition wait_cond_; 88 QMutex wait_lock_; 89 90 QWaitCondition main_thread_wait_cond_; 91 QMutex main_thread_lock_; 92 93 QOffscreenSurface surface; 94 QOpenGLContext* share_ctx; 95 QOpenGLContext* ctx; 96 QOpenGLShaderProgram* blend_mode_program; 97 QOpenGLShaderProgram* premultiply_program; 98 99 FramebufferObject back_buffer_1; 100 FramebufferObject back_buffer_2; 101 102 float ocio_lut_data[NUM_3D_ENTRIES]; 103 GLuint ocio_lut_texture; 104 QOpenGLShaderProgram* ocio_shader; 105 106 Sequence* seq; 107 int playback_speed_; 108 int divider; 109 int tex_width; 110 int tex_height; 111 QAtomicInt queued; 112 bool texture_failed; 113 bool running; 114 QString save_fn; 115 GLvoid *pixel_buffer; 116 int pixel_buffer_linesize; 117 }; 118 119 #endif // RENDERTHREAD_H 120