When the player is used in OpenGL mode, pass unscaled XYZ data through to the shader...
[dcpomatic.git] / src / wx / gl_video_view.h
1 /*
2     Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "video_view.h"
22 #include "lib/signaller.h"
23 #include "lib/position.h"
24 #include "lib/warnings.h"
25 DCPOMATIC_DISABLE_WARNINGS
26 #include <wx/glcanvas.h>
27 #include <wx/wx.h>
28 DCPOMATIC_ENABLE_WARNINGS
29 #include <dcp/util.h>
30 #include <boost/atomic.hpp>
31 #include <boost/thread.hpp>
32 #include <boost/thread/condition.hpp>
33 #undef None
34 #undef Success
35 #undef Status
36
37 class GLVideoView : public VideoView
38 {
39 public:
40         GLVideoView (FilmViewer* viewer, wxWindow* parent);
41         ~GLVideoView ();
42
43         wxWindow* get () const override {
44                 return _canvas;
45         }
46         void update () override;
47         void start () override;
48         void stop () override;
49
50         NextFrameResult display_next_frame (bool) override;
51
52         bool vsync_enabled () const {
53                 return _vsync_enabled;
54         }
55
56         std::map<GLenum, std::string> information () const {
57                 return _information;
58         }
59
60 private:
61         void set_image (std::shared_ptr<const PlayerVideo> pv);
62         void set_image_and_draw ();
63         void draw (Position<int> inter_position, dcp::Size inter_size);
64         void thread ();
65         void thread_playing ();
66         void request_one_shot ();
67         void check_for_butler_errors ();
68         void ensure_context ();
69         void size_changed (wxSizeEvent const &);
70         void setup_shaders ();
71         void set_border_colour (GLuint program);
72
73         wxGLCanvas* _canvas;
74         wxGLContext* _context;
75
76         boost::atomic<wxSize> _canvas_size;
77         GLuint _texture;
78         boost::optional<dcp::Size> _size;
79         bool _have_storage;
80         bool _vsync_enabled;
81         boost::thread _thread;
82
83         boost::mutex _playing_mutex;
84         boost::condition _thread_work_condition;
85         boost::atomic<bool> _playing;
86         boost::atomic<bool> _one_shot;
87
88         GLuint _vao;
89         GLint _fragment_type;
90         bool _setup_shaders_done = false;
91
92         std::shared_ptr<wxTimer> _timer;
93
94         std::map<GLenum, std::string> _information;
95 };