Use glTexSubImage2D when possible, as suggested by https://www.khronos.org/opengl...
authorCarl Hetherington <cth@carlh.net>
Mon, 25 Nov 2019 20:24:03 +0000 (21:24 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 8 Jan 2020 20:56:47 +0000 (21:56 +0100)
src/wx/gl_video_view.cc
src/wx/gl_video_view.h

index a461939a7f537ad4a7a3dafb2094bf45fc93af65..d47ad87f48cdfbe788bd9151d04920c7cd5bb0ac 100644 (file)
@@ -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<const Image> 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);
index 827b12861c5d47ccb5caadadc668fdbb5b5222b2..2f3c8c2a1c40ccb715f1aa296d5f177ce5ed5d29 100644 (file)
@@ -66,6 +66,7 @@ private:
 
        GLuint _id;
        boost::optional<dcp::Size> _size;
+       bool _have_storage;
        bool _vsync_enabled;
        boost::thread* _thread;