Fixed bug 2595 - Padded, non-contiguous YUV does not display correctly using OpenGL ES 2.0 renderer
authorSam Lantinga <slouken@libsdl.org>
Wed, 25 Jun 2014 00:58:40 -0700
changeset 8923b627c37a25e8
parent 8922 dfb6f8611ebe
child 8924 b80cdf666e91
Fixed bug 2595 - Padded, non-contiguous YUV does not display correctly using OpenGL ES 2.0 renderer

Sylvain

Ok, I found out : GLES2_UpdateTexture is just not handling the YUV, I will attach a patch.
src/render/opengles2/SDL_render_gles2.c
     1.1 --- a/src/render/opengles2/SDL_render_gles2.c	Wed Jun 25 00:43:10 2014 -0700
     1.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Wed Jun 25 00:58:40 2014 -0700
     1.3 @@ -592,7 +592,7 @@
     1.4  
     1.5      /* Reformat the texture data into a tightly packed array */
     1.6      src_pitch = width * bpp;
     1.7 -    src = (Uint8 *) pixels;
     1.8 +    src = (Uint8 *)pixels;
     1.9      if (pitch != src_pitch) {
    1.10          blob = (Uint8 *)SDL_malloc(src_pitch * height);
    1.11          if (!blob) {
    1.12 @@ -639,6 +639,40 @@
    1.13                      tdata->pixel_type,
    1.14                      pixels, pitch, SDL_BYTESPERPIXEL(texture->format));
    1.15  
    1.16 +    if (tdata->yuv) {
    1.17 +        /* Skip to the correct offset into the next texture */
    1.18 +        pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
    1.19 +        if (texture->format == SDL_PIXELFORMAT_YV12) {
    1.20 +            data->glBindTexture(tdata->texture_type, tdata->texture_v);
    1.21 +        } else {
    1.22 +            data->glBindTexture(tdata->texture_type, tdata->texture_u);
    1.23 +        }
    1.24 +        GLES2_TexSubImage2D(data, tdata->texture_type,
    1.25 +                rect->x / 2,
    1.26 +                rect->y / 2,
    1.27 +                rect->w / 2,
    1.28 +                rect->h / 2,
    1.29 +                tdata->pixel_format,
    1.30 +                tdata->pixel_type,
    1.31 +                pixels, pitch / 2, 1);
    1.32 +
    1.33 +        /* Skip to the correct offset into the next texture */
    1.34 +        pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4);
    1.35 +        if (texture->format == SDL_PIXELFORMAT_YV12) {
    1.36 +            data->glBindTexture(tdata->texture_type, tdata->texture_u);
    1.37 +        } else {
    1.38 +            data->glBindTexture(tdata->texture_type, tdata->texture_v);
    1.39 +        }
    1.40 +        GLES2_TexSubImage2D(data, tdata->texture_type,
    1.41 +                rect->x / 2,
    1.42 +                rect->y / 2,
    1.43 +                rect->w / 2,
    1.44 +                rect->h / 2,
    1.45 +                tdata->pixel_format,
    1.46 +                tdata->pixel_type,
    1.47 +                pixels, pitch / 2, 1);
    1.48 +    }
    1.49 +
    1.50      return GL_CheckError("glTexSubImage2D()", renderer);
    1.51  }
    1.52  
    1.53 @@ -686,7 +720,7 @@
    1.54                      rect->h,
    1.55                      tdata->pixel_format,
    1.56                      tdata->pixel_type,
    1.57 -                    Vplane, Vpitch, 1);
    1.58 +                    Yplane, Ypitch, 1);
    1.59  
    1.60      return GL_CheckError("glTexSubImage2D()", renderer);
    1.61  }