gl-renderer: fix pixel format used in texture uploads when using R/RG textures
authorArnaud Vrac <avrac@freebox.fr>
Wed, 29 Nov 2017 14:25:34 +0000 (15:25 +0100)
committerDaniel Stone <daniels@collabora.com>
Mon, 11 Dec 2017 09:34:26 +0000 (09:34 +0000)
In glTexImage2D / glTexSubImage2D calls, the only pixel formats allowed
for the GL_R8 and GL_RG internal formats are respectively GL_RED and
GL_RG [1].

Make sure we match this requirement, as some drivers will fail with the
current code.

[1] https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml, Table 2

Signed-off-by: Arnaud Vrac <rawoul@gmail.com>
Fixes: 00a03d2f724 ("gl-renderer: add support of WL_SHM_FORMAT_NV12")
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
libweston/gl-renderer.c

index 6fd3641f2df21e5332ff8916ac77ff0882b5db05..8726c34027a6332a025ba26cd62a594257ad90b5 100644 (file)
@@ -1388,6 +1388,18 @@ gl_renderer_read_pixels(struct weston_output *output,
        return 0;
 }
 
+static GLenum gl_format_from_internal(GLenum internal_format)
+{
+       switch (internal_format) {
+       case GL_R8_EXT:
+               return GL_RED_EXT;
+       case GL_RG8_EXT:
+               return GL_RG_EXT;
+       default:
+               return internal_format;
+       }
+}
+
 static void
 gl_renderer_flush_damage(struct weston_surface *surface)
 {
@@ -1436,7 +1448,7 @@ gl_renderer_flush_damage(struct weston_surface *surface)
                                     gs->pitch / gs->hsub[j],
                                     buffer->height / gs->vsub[j],
                                     0,
-                                    gs->gl_format[j],
+                                    gl_format_from_internal(gs->gl_format[j]),
                                     gs->gl_pixel_type,
                                     data + gs->offset[j]);
                }
@@ -1458,7 +1470,7 @@ gl_renderer_flush_damage(struct weston_surface *surface)
                                     gs->pitch / gs->hsub[j],
                                     buffer->height / gs->vsub[j],
                                     0,
-                                    gs->gl_format[j],
+                                    gl_format_from_internal(gs->gl_format[j]),
                                     gs->gl_pixel_type,
                                     data + gs->offset[j]);
                }
@@ -1486,7 +1498,7 @@ gl_renderer_flush_damage(struct weston_surface *surface)
                                        r.y1 / gs->vsub[j],
                                        (r.x2 - r.x1) / gs->hsub[j],
                                        (r.y2 - r.y1) / gs->vsub[j],
-                                       gs->gl_format[j],
+                                       gl_format_from_internal(gs->gl_format[j]),
                                        gs->gl_pixel_type,
                                        data + gs->offset[j]);
                }