From: Carl Hetherington Date: Mon, 25 Nov 2019 20:24:03 +0000 (+0100) Subject: Use glTexSubImage2D when possible, as suggested by https://www.khronos.org/opengl... X-Git-Tag: v2.15.40^2~4 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=4f0575fcb518d959e8dcf581ec8181609782b4ef Use glTexSubImage2D when possible, as suggested by https://khronos.org/opengl/wiki/Common_Mistakes --- diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index a461939a7..d47ad87f4 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -55,6 +55,7 @@ using boost::optional; GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent) : VideoView (viewer) + , _have_storage (false) , _vsync_enabled (false) , _thread (0) , _playing (false) @@ -264,11 +265,21 @@ GLVideoView::set_image (shared_ptr image) DCPOMATIC_ASSERT (image->pixel_format() == AV_PIX_FMT_RGB24); DCPOMATIC_ASSERT (!image->aligned()); + if (image->size() != _size) { + _have_storage = false; + } + _size = image->size (); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); check_gl_error ("glPixelStorei"); - glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB8, _size->width, _size->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data()[0]); - check_gl_error ("glTexImage2D"); + if (_have_storage) { + glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, _size->width, _size->height, GL_RGB, GL_UNSIGNED_BYTE, image->data()[0]); + check_gl_error ("glTexSubImage2D"); + } else { + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB8, _size->width, _size->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data()[0]); + _have_storage = true; + check_gl_error ("glTexImage2D"); + } glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); diff --git a/src/wx/gl_video_view.h b/src/wx/gl_video_view.h index 827b12861..2f3c8c2a1 100644 --- a/src/wx/gl_video_view.h +++ b/src/wx/gl_video_view.h @@ -66,6 +66,7 @@ private: GLuint _id; boost::optional _size; + bool _have_storage; bool _vsync_enabled; boost::thread* _thread;