summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-11-25 21:24:03 +0100
committerCarl Hetherington <cth@carlh.net>2020-01-08 21:56:47 +0100
commit4f0575fcb518d959e8dcf581ec8181609782b4ef (patch)
treefc716a0373afee31fae9071cb6ffe80378001b10 /src
parent1d796edf59da644e91bd443505fb76e0397a1439 (diff)
Use glTexSubImage2D when possible, as suggested by https://www.khronos.org/opengl/wiki/Common_Mistakes
Diffstat (limited to 'src')
-rw-r--r--src/wx/gl_video_view.cc15
-rw-r--r--src/wx/gl_video_view.h1
2 files changed, 14 insertions, 2 deletions
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<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);
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<dcp::Size> _size;
+ bool _have_storage;
bool _vsync_enabled;
boost::thread* _thread;