Add basic Texture wrapper for a GL texture.
authorCarl Hetherington <cth@carlh.net>
Sun, 12 Sep 2021 23:13:30 +0000 (01:13 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 27 Sep 2021 11:41:46 +0000 (13:41 +0200)
src/wx/gl_video_view.cc
src/wx/gl_video_view.h

index 035d337e5e51ebc9d9d5742c38a8df9eca8a87b1..7fb387f53132d2368dabcb960d38d0b39dcf332b 100644 (file)
@@ -114,8 +114,6 @@ GLVideoView::~GLVideoView ()
                _thread.interrupt ();
                _thread.join ();
        } catch (...) {}
-
-       glDeleteTextures (1, &_video_texture);
 }
 
 void
@@ -464,7 +462,6 @@ GLVideoView::draw (Position<int>, dcp::Size)
        glViewport (0, 0, width, height);
        check_gl_error ("glViewport");
 
-       glBindTexture(GL_TEXTURE_2D, _video_texture);
        glBindVertexArray(_vao);
        check_gl_error ("glBindVertexArray");
        glUniform1i(_fragment_type, _optimise_for_j2k ? 1 : 2);
@@ -668,10 +665,8 @@ try
        _vsync_enabled = true;
 #endif
 
-       glGenTextures (1, &_video_texture);
-       check_gl_error ("glGenTextures");
-       glBindTexture (GL_TEXTURE_2D, _video_texture);
-       check_gl_error ("glBindTexture");
+       _video_texture.reset(new Texture());
+       _video_texture->bind();
 
        while (true) {
                boost::mutex::scoped_lock lm (_playing_mutex);
@@ -718,3 +713,24 @@ GLVideoView::request_one_shot ()
        _thread_work_condition.notify_all ();
 }
 
+
+Texture::Texture ()
+{
+       glGenTextures (1, &_name);
+       check_gl_error ("glGenTextures");
+}
+
+
+Texture::~Texture ()
+{
+       glDeleteTextures (1, &_name);
+}
+
+
+void
+Texture::bind ()
+{
+       glBindTexture(GL_TEXTURE_2D, _name);
+       check_gl_error ("glBindTexture");
+}
+
index 8f3f2dcb47994a9bbe8f51eb5a9932c47f956e69..272198591c3e05f92ba1148570863b4fef1f1658 100644 (file)
@@ -34,6 +34,23 @@ DCPOMATIC_ENABLE_WARNINGS
 #undef Success
 #undef Status
 
+
+class Texture
+{
+public:
+       Texture ();
+       ~Texture ();
+
+       Texture (Texture const&) = delete;
+       Texture& operator= (Texture const&) = delete;
+
+       void bind ();
+
+private:
+       GLuint _name;
+};
+
+
 class GLVideoView : public VideoView
 {
 public:
@@ -74,7 +91,7 @@ private:
        wxGLContext* _context;
 
        boost::atomic<wxSize> _canvas_size;
-       GLuint _video_texture;
+       std::unique_ptr<Texture> _video_texture;
        boost::optional<dcp::Size> _video_size;
        bool _have_storage;
        bool _vsync_enabled;