1 From f705c7bbc8274b6824a9063161263cb16af9d15d Mon Sep 17 00:00:00 2001
2 From: Haihua Hu <jared.hu@nxp.com>
3 Date: Mon, 14 Nov 2016 10:53:27 +0800
4 Subject: [PATCH 18/26] glcolorconvert: fix MRT cannot work in GLES3.0
6 use glBlitFramebuffer for textures copy if it is available
8 Upstream-Status: Inappropriate [i.MX specific]
10 Signed-off-by: Haihua Hu <jared.hu@nxp.com>
12 gst-libs/gst/gl/glprototypes/fbo.h | 6 ++---
13 gst-libs/gst/gl/gstglmemory.c | 54 ++++++++++++++++++++++++++++++++------
14 2 files changed, 49 insertions(+), 11 deletions(-)
16 diff --git a/gst-libs/gst/gl/glprototypes/fbo.h b/gst-libs/gst/gl/glprototypes/fbo.h
17 index d142483..789f289 100644
18 --- a/gst-libs/gst/gl/glprototypes/fbo.h
19 +++ b/gst-libs/gst/gl/glprototypes/fbo.h
20 @@ -102,9 +102,9 @@ GST_GL_EXT_FUNCTION (GLboolean, IsFramebuffer,
23 GST_GL_EXT_BEGIN (offscreen_blit,
26 - 255, 255, /* not in either GLES */
27 + GST_GL_API_OPENGL3 | GST_GL_API_GLES2,
29 + 3, 0,/* enable to avoid using glCopyTexImage2D for texture copying */
32 GST_GL_EXT_FUNCTION (void, BlitFramebuffer,
33 diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c
34 index 73c3b59..6f9794f 100644
35 --- a/gst-libs/gst/gl/gstglmemory.c
36 +++ b/gst-libs/gst/gl/gstglmemory.c
37 @@ -69,6 +69,12 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_GL_MEMORY);
38 #ifndef GL_TEXTURE_EXTERNAL_OES
39 #define GL_TEXTURE_EXTERNAL_OES 0x8D65
41 +#ifndef GL_READ_FRAMEBUFFER
42 +#define GL_READ_FRAMEBUFFER 0x8CA8
44 +#ifndef GL_DRAW_FRAMEBUFFER
45 +#define GL_DRAW_FRAMEBUFFER 0x8CA9
48 G_DEFINE_TYPE (GstGLMemoryAllocator, gst_gl_memory_allocator,
49 GST_TYPE_GL_BASE_MEMORY_ALLOCATOR);
50 @@ -626,7 +632,7 @@ gst_gl_memory_copy_teximage (GstGLMemory * src, guint tex_id,
51 guint out_gl_format, out_tex_target;
57 gl = src->mem.context->gl_vtable;
58 out_tex_target = gst_gl_texture_target_to_gl (out_target);
59 @@ -659,31 +665,63 @@ gst_gl_memory_copy_teximage (GstGLMemory * src, guint tex_id,
61 /* FIXME: try and avoid creating and destroying fbo's every copy... */
62 /* create a framebuffer object */
63 - gl->GenFramebuffers (1, &fbo);
64 - gl->BindFramebuffer (GL_FRAMEBUFFER, fbo);
65 + gl->GenFramebuffers (2, &fbo[0]);
66 + gl->BindFramebuffer (GL_READ_FRAMEBUFFER, fbo[0]);
68 - gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
69 + gl->FramebufferTexture2D (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
70 gst_gl_texture_target_to_gl (src->tex_target), src_tex_id, 0);
72 -// if (!gst_gl_context_check_framebuffer_status (src->context))
74 + if (!gst_gl_context_check_framebuffer_status (src->mem.context))
77 + gl->BindFramebuffer (GL_DRAW_FRAMEBUFFER, fbo[1]);
79 + gl->FramebufferTexture2D (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
80 + gst_gl_texture_target_to_gl (src->tex_target), tex_id, 0);
82 + if (!gst_gl_context_check_framebuffer_status (src->mem.context))
86 gl->BindTexture (out_tex_target, tex_id);
87 gst_gl_query_start_log (GST_GL_BASE_MEMORY_CAST (src)->query,
88 GST_CAT_GL_MEMORY, GST_LEVEL_LOG, NULL, "%s", "CopyTexImage2D took");
89 gl->CopyTexImage2D (out_tex_target, 0, out_gl_format, 0, 0, out_width,
91 gst_gl_query_end (GST_GL_BASE_MEMORY_CAST (src)->query);
96 + * glCopyTexImage2D cannot work without internal_format
97 + * we cannot get the internal_format in this function
98 + * so use glBlitFramebuffer for texture copy
100 + GST_CAT_LOG(GST_CAT_GL_MEMORY,"Use BlitFramebuffer copy texture %d into %d",
101 + src_tex_id, tex_id);
102 + gl->ReadBuffer ( GL_COLOR_ATTACHMENT0 );
103 + gl->BlitFramebuffer ( 0, 0, out_width, out_height,
104 + 0, 0, out_width, out_height,
105 + GL_COLOR_BUFFER_BIT, GL_LINEAR );
106 gl->BindTexture (out_tex_target, 0);
107 gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
109 - gl->DeleteFramebuffers (1, &fbo);
110 + gl->DeleteFramebuffers (2, &fbo[0]);
112 gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);
118 + gl->BindTexture (out_tex_target, 0);
119 + gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
121 + gl->DeleteFramebuffers (2, &fbo[0]);
123 + gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);