From: Carl Hetherington Date: Sun, 12 Sep 2021 23:13:30 +0000 (+0200) Subject: Add basic Texture wrapper for a GL texture. X-Git-Tag: v2.15.163~1^2~15 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=56e0452ce0f436e7c54a49c68b272797f92a7ffe;p=dcpomatic.git Add basic Texture wrapper for a GL texture. --- diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index 035d337e5..7fb387f53 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -114,8 +114,6 @@ GLVideoView::~GLVideoView () _thread.interrupt (); _thread.join (); } catch (...) {} - - glDeleteTextures (1, &_video_texture); } void @@ -464,7 +462,6 @@ GLVideoView::draw (Position, 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"); +} + diff --git a/src/wx/gl_video_view.h b/src/wx/gl_video_view.h index 8f3f2dcb4..272198591 100644 --- a/src/wx/gl_video_view.h +++ b/src/wx/gl_video_view.h @@ -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 _canvas_size; - GLuint _video_texture; + std::unique_ptr _video_texture; boost::optional _video_size; bool _have_storage; bool _vsync_enabled;