Fixed bug 2595 - Padded, non-contiguous YUV does not display correctly using OpenGL ES 2.0 renderer Alvin The new OpenGL ES 2.0 YUV Texture support does not correctly display padded, non-contiguous YUV data. I am using SDL2 95bd3d33482e (as provided by 'hg id --id') from Mercurial. The YUV data I am using is provided by the FFMPEG family of libraries. According to FFMPEG's documentation, "The linesize [pitch] may be larger than the size of usable data -- there may be extra padding present for performance reasons." The dimensions of the video file that I am using are 480x360. What I get from FFMPEG is a Ypitch of 512, and Upitch and Vpitch are both 256. When I pack new Y, U and V buffers with only the "usable" data (Ypitch is 480 and Upitch and Vpitch are both 240), and use those new buffers, the image is display correctly. It appears that the Ypitch, Upitch and Vpitch parameters are not being used by SDL_UpdateYUVTexture(). I use SDL_PIXELFORMAT_YV12 for my YUV texture, however, the same results are seen when I use SDL_PIXELFORMAT_IYUV. Not sure if this is related or not, but when I render the YUV texture (padded and unpadded) to a RGB24 texture, the resulting image is greyscale (or could by just the Y channel). The URL field for this bug entry is set to my email (SDL mailing list archive) which includes an example image of what I see when rendering padded, non-contiguous YUV data.
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
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 0d0131b..d108e9a 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -581,52 +581,61 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
}
static int
-GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
- const void *pixels, int pitch)
+GLES2_TexSubImage2D(GLES2_DriverContext *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp)
{
- GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
- GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
Uint8 *blob = NULL;
Uint8 *src;
- int srcPitch;
+ int src_pitch;
int y;
- GLES2_ActivateRenderer(renderer);
-
- /* Bail out if we're supposed to update an empty rectangle */
- if (rect->w <= 0 || rect->h <= 0)
- return 0;
-
/* Reformat the texture data into a tightly packed array */
- srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
- src = (Uint8 *)pixels;
- if (pitch != srcPitch) {
- blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
+ src_pitch = width * bpp;
+ src = (Uint8 *)data;
+ if (pitch != src_pitch) {
+ blob = (Uint8 *)SDL_malloc(src_pitch * height);
if (!blob) {
return SDL_OutOfMemory();
}
src = blob;
- for (y = 0; y < rect->h; ++y)
+ for (y = 0; y < height; ++y)
{
- SDL_memcpy(src, pixels, srcPitch);
- src += srcPitch;
+ SDL_memcpy(src, pixels, src_pitch);
+ src += src_pitch;
pixels = (Uint8 *)pixels + pitch;
}
src = blob;
}
+ data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src);
+ if (blob) {
+ SDL_free(blob);
+ }
+ return 0;
+}
+
+static int
+GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
+ const void *pixels, int pitch)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+
+ GLES2_ActivateRenderer(renderer);
+
+ /* Bail out if we're supposed to update an empty rectangle */
+ if (rect->w <= 0 || rect->h <= 0)
+ return 0;
+
/* Create a texture subimage with the supplied data */
data->glBindTexture(tdata->texture_type, tdata->texture);
- data->glTexSubImage2D(tdata->texture_type,
- 0,
+ GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w,
rect->h,
tdata->pixel_format,
tdata->pixel_type,
- src);
- SDL_free(blob);
+ pixels, pitch, SDL_BYTESPERPIXEL(texture->format));
return GL_CheckError("glTexSubImage2D()", renderer);
}
@@ -641,39 +650,41 @@ GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+ GLES2_ActivateRenderer(renderer);
+
+ /* Bail out if we're supposed to update an empty rectangle */
+ if (rect->w <= 0 || rect->h <= 0)
+ return 0;
+
data->glBindTexture(tdata->texture_type, tdata->texture_v);
- data->glTexSubImage2D(tdata->texture_type,
- 0,
+ GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w / 2,
rect->h / 2,
tdata->pixel_format,
tdata->pixel_type,
- Vplane);
+ Vplane, Vpitch, 1);
data->glBindTexture(tdata->texture_type, tdata->texture_u);
- data->glTexSubImage2D(tdata->texture_type,
- 0,
+ GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w / 2,
rect->h / 2,
tdata->pixel_format,
tdata->pixel_type,
- Uplane);
+ Uplane, Upitch, 1);
data->glBindTexture(tdata->texture_type, tdata->texture);
- data->glTexSubImage2D(tdata->texture_type,
- 0,
+ GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w,
rect->h,
tdata->pixel_format,
tdata->pixel_type,
- Yplane);
-
+ Vplane, Vpitch, 1);
return GL_CheckError("glTexSubImage2D()", renderer);
}