summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0008-glplugin-glcolorconvert-fix-MRT-cannot-work-in-GLES3.patch
blob: d4858328f6bf0cf9b0cc13f710a5e6d98130dcc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
From 5b4e2d726602b0c92b789fce0dc85a1f0c860bbc Mon Sep 17 00:00:00 2001
From: Haihua Hu <jared.hu@nxp.com>
Date: Wed, 20 Apr 2016 16:38:31 +0800
Subject: [PATCH 3/6] [glplugin] glcolorconvert: fix MRT cannot work in GLES3.0

1. Add #ifdefine Marco to avoid redefinition of GL_COLOR_ATTACHMENT(1,2).
2. Change to use glBlitFramebuffer for textures copy. glCopyTexImage2D
   cannot work because we cannot get texture internal format.

Upstream-Status: Inappropriate [i.MX specific]

Signed-off-by: Haihua Hu <jared.hu@nxp.com>
---
 gst-libs/gst/gl/glprototypes/fbo.h               |  6 +--
 gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h |  7 +--
 gst-libs/gst/gl/gstglcolorconvert.c              |  2 +-
 gst-libs/gst/gl/gstglmemory.c                    | 54 +++++++++++++++++++++---
 4 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/gst-libs/gst/gl/glprototypes/fbo.h b/gst-libs/gst/gl/glprototypes/fbo.h
index d142483..789f289 100644
--- a/gst-libs/gst/gl/glprototypes/fbo.h
+++ b/gst-libs/gst/gl/glprototypes/fbo.h
@@ -102,9 +102,9 @@ GST_GL_EXT_FUNCTION (GLboolean, IsFramebuffer,
 GST_GL_EXT_END ()
 
 GST_GL_EXT_BEGIN (offscreen_blit,
-                  GST_GL_API_NONE,
-                  255, 255,
-                  255, 255, /* not in either GLES */
+		  GST_GL_API_OPENGL3 | GST_GL_API_GLES2,
+		  3, 0,
+		  3, 0,/* enable to avoid using glCopyTexImage2D for texture copying */
                   "EXT\0ANGLE\0",
                   "framebuffer_blit\0")
 GST_GL_EXT_FUNCTION (void, BlitFramebuffer,
diff --git a/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h b/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h
index d282990..1980476 100644
--- a/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h
+++ b/gst-libs/gst/gl/glprototypes/gstgl_gles2compat.h
@@ -34,9 +34,10 @@ G_BEGIN_DECLS
 //END FIXME
 
 /* UNSUPPORTED */
-
-#define GL_COLOR_ATTACHMENT1 0
-#define GL_COLOR_ATTACHMENT2 0
+#ifndef GL_COLOR_ATTACHMENT1
+#define GL_COLOR_ATTACHMENT1 0x8CE1
+#define GL_COLOR_ATTACHMENT2 0x8CE2
+#endif
 #ifndef GL_TEXTURE_ENV
 #define GL_TEXTURE_ENV 0
 #endif
diff --git a/gst-libs/gst/gl/gstglcolorconvert.c b/gst-libs/gst/gl/gstglcolorconvert.c
index 4ed947e..490ec54 100644
--- a/gst-libs/gst/gl/gstglcolorconvert.c
+++ b/gst-libs/gst/gl/gstglcolorconvert.c
@@ -2075,7 +2075,7 @@ _init_convert (GstGLColorConvert * convert)
   }
 
   /* Requires reading from a RG/LA framebuffer... */
-  if (USING_GLES2 (convert->context) &&
+  if (!USING_GLES3 (convert->context) &&
       (GST_VIDEO_INFO_FORMAT (&convert->out_info) == GST_VIDEO_FORMAT_YUY2 ||
           GST_VIDEO_INFO_FORMAT (&convert->out_info) ==
           GST_VIDEO_FORMAT_UYVY)) {
diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c
index 402fd4d..f2706ea 100644
--- a/gst-libs/gst/gl/gstglmemory.c
+++ b/gst-libs/gst/gl/gstglmemory.c
@@ -69,6 +69,12 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_GL_MEMORY);
 #ifndef GL_TEXTURE_EXTERNAL_OES
 #define GL_TEXTURE_EXTERNAL_OES 0x8D65
 #endif
+#ifndef GL_READ_FRAMEBUFFER
+#define GL_READ_FRAMEBUFFER 0x8CA8
+#endif
+#ifndef GL_DRAW_FRAMEBUFFER
+#define GL_DRAW_FRAMEBUFFER 0x8CA9
+#endif
 
 G_DEFINE_TYPE (GstGLMemoryAllocator, gst_gl_memory_allocator,
     GST_TYPE_GL_BASE_MEMORY_ALLOCATOR);
@@ -608,7 +614,7 @@ gst_gl_memory_copy_teximage (GstGLMemory * src, guint tex_id,
   guint out_gl_format, out_tex_target;
   GstMapInfo sinfo;
   guint src_tex_id;
-  guint fbo;
+  guint fbo[2];
 
   gl = src->mem.context->gl_vtable;
   out_tex_target = gst_gl_texture_target_to_gl (out_target);
@@ -632,31 +638,65 @@ gst_gl_memory_copy_teximage (GstGLMemory * src, guint tex_id,
 
   /* FIXME: try and avoid creating and destroying fbo's every copy... */
   /* create a framebuffer object */
-  gl->GenFramebuffers (1, &fbo);
-  gl->BindFramebuffer (GL_FRAMEBUFFER, fbo);
+  gl->GenFramebuffers (2, &fbo[0]);
+  gl->BindFramebuffer (GL_READ_FRAMEBUFFER, fbo[0]);
 
-  gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+  gl->FramebufferTexture2D (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
       gst_gl_texture_target_to_gl (src->tex_target), src_tex_id, 0);
 
-//  if (!gst_gl_context_check_framebuffer_status (src->context))
-//    goto fbo_error;
+  if (!gst_gl_context_check_framebuffer_status (src->mem.context))
+    goto fbo_error;
+
+  gl->BindFramebuffer (GL_DRAW_FRAMEBUFFER, fbo[1]);
+
+  gl->FramebufferTexture2D (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+      gst_gl_texture_target_to_gl (src->tex_target), tex_id, 0);
 
+  if (!gst_gl_context_check_framebuffer_status (src->mem.context))
+    goto fbo_error;
+
+  /*
   gl->BindTexture (out_tex_target, tex_id);
   gst_gl_query_start_log (GST_GL_BASE_MEMORY_CAST (src)->query,
       GST_CAT_GL_MEMORY, GST_LEVEL_LOG, NULL, "%s", "CopyTexImage2D took");
   gl->CopyTexImage2D (out_tex_target, 0, out_gl_format, 0, 0, out_width,
       out_height, 0);
   gst_gl_query_end (GST_GL_BASE_MEMORY_CAST (src)->query);
+   */
+
+  /* 
+   * glCopyTexImage2D cannot work without internal_format
+   * we cannot get the internal_format in this function
+   * so use glBlitFramebuffer for texture copy
+   */
+  GST_CAT_LOG(GST_CAT_GL_MEMORY,"Use BlitFramebuffer copy texture %d into %d",
+      src_tex_id, tex_id);
+  gl->ReadBuffer ( GL_COLOR_ATTACHMENT0 );
+  gl->BlitFramebuffer ( 0, 0, out_width, out_height,
+		        0, 0, out_width, out_height,
+		        GL_COLOR_BUFFER_BIT, GL_LINEAR );
 
   gl->BindTexture (out_tex_target, 0);
   gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
 
-  gl->DeleteFramebuffers (1, &fbo);
+  gl->DeleteFramebuffers (2, &fbo[0]);
 
   gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);
 
   return TRUE;
 
+fbo_error:
+  {
+    gl->BindTexture (out_tex_target, 0);
+    gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
+
+    gl->DeleteFramebuffers (2, &fbo[0]);
+
+    gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);
+    
+    return FALSE;
+  }
+
 error:
   return FALSE;
 }
-- 
1.9.1