From 0c2890cd34d9056e4e2b12b13ef85bdd0b6415c4 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 31 Mar 2016 19:38:12 +1100 Subject: [PATCH] glmemory: add checking the read implementation format/type on gles2 platforms By default, reading GL_RED or GL_RG us unsupported by glReadPixels unless exposed through GL_COLOR_READ_IMPLEMENTATION_FORMAT/TYPE. This allows downloading multiple-planar video frames where possible. --- gst-libs/gst/gl/gstglmemory.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c index 402fd4d..f75a842 100644 --- a/gst-libs/gst/gl/gstglmemory.c +++ b/gst-libs/gst/gl/gstglmemory.c @@ -367,6 +367,26 @@ gst_gl_memory_read_pixels (GstGLMemory * gl_mem, gpointer read_pointer) return FALSE; } + if (USING_GLES2 (context) || USING_GLES3 (context)) { + if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { + /* explicitly supported */ + } else { + gint supported_format, supported_type; + + gl->GetIntegerv (GL_IMPLEMENTATION_COLOR_READ_FORMAT, &supported_format); + gl->GetIntegerv (GL_IMPLEMENTATION_COLOR_READ_TYPE, &supported_type); + + if (supported_format != format || supported_type != type) { + GST_CAT_ERROR (GST_CAT_GL_MEMORY, "cannot read pixels with " + "unsupported format and type. Supported format 0x%x type 0x%x", + supported_format, supported_type); + gl->BindFramebuffer (GL_FRAMEBUFFER, 0); + gl->DeleteFramebuffers (1, &fbo); + return FALSE; + } + } + } + gst_gl_query_start_log (GST_GL_BASE_MEMORY_CAST (gl_mem)->query, GST_CAT_GL_MEMORY, GST_LEVEL_LOG, NULL, "%s", "glReadPixels took"); gl->ReadPixels (0, 0, gl_mem->tex_width, GL_MEM_HEIGHT (gl_mem), format, @@ -374,7 +394,6 @@ gst_gl_memory_read_pixels (GstGLMemory * gl_mem, gpointer read_pointer) gst_gl_query_end (GST_GL_BASE_MEMORY_CAST (gl_mem)->query); gl->BindFramebuffer (GL_FRAMEBUFFER, 0); - gl->DeleteFramebuffers (1, &fbo); return TRUE; -- 2.7.4