1 From 5b4e2d726602b0c92b789fce0dc85a1f0c860bbc Mon Sep 17 00:00:00 2001
2 From: Haihua Hu <jared.hu@nxp.com>
3 Date: Wed, 20 Apr 2016 16:38:31 +0800
4 Subject: [PATCH 3/6] [glplugin] glcolorconvert: fix MRT cannot work in GLES3.0
6 1. Add #ifdefine Marco to avoid redefinition of GL_COLOR_ATTACHMENT(1,2).
7 2. Change to use glBlitFramebuffer for textures copy. glCopyTexImage2D
8 cannot work because we cannot get texture internal format.
10 Upstream-Status: Inappropriate [i.MX specific]
12 Signed-off-by: Haihua Hu <jared.hu@nxp.com>
14 gst-libs/gst/gl/glprototypes/fbo.h | 6 +--
15 gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h | 7 +--
16 gst-libs/gst/gl/gstglcolorconvert.c | 2 +-
17 gst-libs/gst/gl/gstglmemory.c | 54 +++++++++++++++++++++---
18 4 files changed, 55 insertions(+), 14 deletions(-)
20 diff --git a/gst-libs/gst/gl/glprototypes/fbo.h b/gst-libs/gst/gl/glprototypes/fbo.h
21 index d142483..789f289 100644
22 --- a/gst-libs/gst/gl/glprototypes/fbo.h
23 +++ b/gst-libs/gst/gl/glprototypes/fbo.h
24 @@ -102,9 +102,9 @@ GST_GL_EXT_FUNCTION (GLboolean, IsFramebuffer,
27 GST_GL_EXT_BEGIN (offscreen_blit,
30 - 255, 255, /* not in either GLES */
31 + GST_GL_API_OPENGL3 | GST_GL_API_GLES2,
33 + 3, 0,/* enable to avoid using glCopyTexImage2D for texture copying */
36 GST_GL_EXT_FUNCTION (void, BlitFramebuffer,
37 diff --git a/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h b/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h
38 index d282990..1980476 100644
39 --- a/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h
40 +++ b/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h
41 @@ -34,9 +34,10 @@ G_BEGIN_DECLS
46 -#define GL_COLOR_ATTACHMENT1 0
47 -#define GL_COLOR_ATTACHMENT2 0
48 +#ifndef GL_COLOR_ATTACHMENT1
49 +#define GL_COLOR_ATTACHMENT1 0x8CE1
50 +#define GL_COLOR_ATTACHMENT2 0x8CE2
52 #ifndef GL_TEXTURE_ENV
53 #define GL_TEXTURE_ENV 0
55 diff --git a/gst-libs/gst/gl/gstglcolorconvert.c b/gst-libs/gst/gl/gstglcolorconvert.c
56 index 4ed947e..490ec54 100644
57 --- a/gst-libs/gst/gl/gstglcolorconvert.c
58 +++ b/gst-libs/gst/gl/gstglcolorconvert.c
59 @@ -2075,7 +2075,7 @@ _init_convert (GstGLColorConvert * convert)
62 /* Requires reading from a RG/LA framebuffer... */
63 - if (USING_GLES2 (convert->context) &&
64 + if (!USING_GLES3 (convert->context) &&
65 (GST_VIDEO_INFO_FORMAT (&convert->out_info) == GST_VIDEO_FORMAT_YUY2 ||
66 GST_VIDEO_INFO_FORMAT (&convert->out_info) ==
67 GST_VIDEO_FORMAT_UYVY)) {
68 diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c
69 index 402fd4d..f2706ea 100644
70 --- a/gst-libs/gst/gl/gstglmemory.c
71 +++ b/gst-libs/gst/gl/gstglmemory.c
72 @@ -69,6 +69,12 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_GL_MEMORY);
73 #ifndef GL_TEXTURE_EXTERNAL_OES
74 #define GL_TEXTURE_EXTERNAL_OES 0x8D65
76 +#ifndef GL_READ_FRAMEBUFFER
77 +#define GL_READ_FRAMEBUFFER 0x8CA8
79 +#ifndef GL_DRAW_FRAMEBUFFER
80 +#define GL_DRAW_FRAMEBUFFER 0x8CA9
83 G_DEFINE_TYPE (GstGLMemoryAllocator, gst_gl_memory_allocator,
84 GST_TYPE_GL_BASE_MEMORY_ALLOCATOR);
85 @@ -608,7 +614,7 @@ gst_gl_memory_copy_teximage (GstGLMemory * src, guint tex_id,
86 guint out_gl_format, out_tex_target;
92 gl = src->mem.context->gl_vtable;
93 out_tex_target = gst_gl_texture_target_to_gl (out_target);
94 @@ -632,31 +638,65 @@ gst_gl_memory_copy_teximage (GstGLMemory * src, guint tex_id,
96 /* FIXME: try and avoid creating and destroying fbo's every copy... */
97 /* create a framebuffer object */
98 - gl->GenFramebuffers (1, &fbo);
99 - gl->BindFramebuffer (GL_FRAMEBUFFER, fbo);
100 + gl->GenFramebuffers (2, &fbo[0]);
101 + gl->BindFramebuffer (GL_READ_FRAMEBUFFER, fbo[0]);
103 - gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
104 + gl->FramebufferTexture2D (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
105 gst_gl_texture_target_to_gl (src->tex_target), src_tex_id, 0);
107 -// if (!gst_gl_context_check_framebuffer_status (src->context))
109 + if (!gst_gl_context_check_framebuffer_status (src->mem.context))
112 + gl->BindFramebuffer (GL_DRAW_FRAMEBUFFER, fbo[1]);
114 + gl->FramebufferTexture2D (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
115 + gst_gl_texture_target_to_gl (src->tex_target), tex_id, 0);
117 + if (!gst_gl_context_check_framebuffer_status (src->mem.context))
121 gl->BindTexture (out_tex_target, tex_id);
122 gst_gl_query_start_log (GST_GL_BASE_MEMORY_CAST (src)->query,
123 GST_CAT_GL_MEMORY, GST_LEVEL_LOG, NULL, "%s", "CopyTexImage2D took");
124 gl->CopyTexImage2D (out_tex_target, 0, out_gl_format, 0, 0, out_width,
126 gst_gl_query_end (GST_GL_BASE_MEMORY_CAST (src)->query);
130 + * glCopyTexImage2D cannot work without internal_format
131 + * we cannot get the internal_format in this function
132 + * so use glBlitFramebuffer for texture copy
134 + GST_CAT_LOG(GST_CAT_GL_MEMORY,"Use BlitFramebuffer copy texture %d into %d",
135 + src_tex_id, tex_id);
136 + gl->ReadBuffer ( GL_COLOR_ATTACHMENT0 );
137 + gl->BlitFramebuffer ( 0, 0, out_width, out_height,
138 + 0, 0, out_width, out_height,
139 + GL_COLOR_BUFFER_BIT, GL_LINEAR );
141 gl->BindTexture (out_tex_target, 0);
142 gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
144 - gl->DeleteFramebuffers (1, &fbo);
145 + gl->DeleteFramebuffers (2, &fbo[0]);
147 gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);
153 + gl->BindTexture (out_tex_target, 0);
154 + gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
156 + gl->DeleteFramebuffers (2, &fbo[0]);
158 + gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);