]> code.ossystems Code Review - meta-freescale.git/blob
d80d67e13e0d2cbb4c267dd56a4074852c17588c
[meta-freescale.git] /
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
5
6 use glBlitFramebuffer for textures copy if it is available
7
8 Upstream-Status: Inappropriate [i.MX specific]
9
10 Signed-off-by: Haihua Hu <jared.hu@nxp.com>
11 ---
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(-)
15
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,
21  GST_GL_EXT_END ()
22  
23  GST_GL_EXT_BEGIN (offscreen_blit,
24 -                  GST_GL_API_NONE,
25 -                  255, 255,
26 -                  255, 255, /* not in either GLES */
27 +                 GST_GL_API_OPENGL3 | GST_GL_API_GLES2,
28 +                 3, 0,
29 +                 3, 0,/* enable to avoid using glCopyTexImage2D for texture copying */
30                    "EXT\0ANGLE\0",
31                    "framebuffer_blit\0")
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
40  #endif
41 +#ifndef GL_READ_FRAMEBUFFER
42 +#define GL_READ_FRAMEBUFFER 0x8CA8
43 +#endif
44 +#ifndef GL_DRAW_FRAMEBUFFER
45 +#define GL_DRAW_FRAMEBUFFER 0x8CA9
46 +#endif
47  
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;
52    GstMapInfo sinfo;
53    guint src_tex_id;
54 -  guint fbo;
55 +  guint fbo[2];
56  
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,
60  
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]);
67  
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);
71  
72 -//  if (!gst_gl_context_check_framebuffer_status (src->context))
73 -//    goto fbo_error;
74 +  if (!gst_gl_context_check_framebuffer_status (src->mem.context))
75 +    goto fbo_error;
76 +
77 +  gl->BindFramebuffer (GL_DRAW_FRAMEBUFFER, fbo[1]);
78 +
79 +  gl->FramebufferTexture2D (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
80 +      gst_gl_texture_target_to_gl (src->tex_target), tex_id, 0);
81  
82 +  if (!gst_gl_context_check_framebuffer_status (src->mem.context))
83 +    goto fbo_error;
84 +
85 +  /*
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,
90        out_height, 0);
91    gst_gl_query_end (GST_GL_BASE_MEMORY_CAST (src)->query);
92 -
93 +   */
94 +
95 +  /*
96 +   * glCopyTexImage2D cannot work without internal_format
97 +   * we cannot get the internal_format in this function
98 +   * so use glBlitFramebuffer for texture copy
99 +   */
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);
108  
109 -  gl->DeleteFramebuffers (1, &fbo);
110 +  gl->DeleteFramebuffers (2, &fbo[0]);
111  
112    gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);
113  
114    return TRUE;
115  
116 +fbo_error:
117 +  {
118 +    gl->BindTexture (out_tex_target, 0);
119 +    gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
120 +
121 +    gl->DeleteFramebuffers (2, &fbo[0]);
122 +
123 +    gst_memory_unmap (GST_MEMORY_CAST (src), &sinfo);
124 +
125 +    return FALSE;
126 +  }
127  error:
128    return FALSE;
129  }
130 -- 
131 1.9.1
132