From 8c7f9dc1a89e90e44b2b7dfb13fa899ad52352ee Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 3 Jul 2016 16:09:26 +0200 Subject: vo_opengl: support inconsistent negative strides per plane GL generally does not support flipping the image on upload, meaning negative strides are not supported. vo_opengl handles this by flipping rendering if the stride is inverted, and gl_pbo_upload() "ignores" negative strides by uploading without flipping the image. If individual planes had strides with different signs, this broke. The flipping affected the entire image, and only the sign of the first plane was respected. This is just a crazy corner case that will never happen, but it turns out this is quite simple to support, and actually improves the code somewhat. --- video/out/opengl/video.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'video/out') diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 271725aaeb..bd1eb893af 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -97,12 +97,12 @@ struct texplane { GLenum gl_type; GLuint gl_texture; char swizzle[5]; + bool flipped; struct gl_pbo_upload pbo; }; struct video_image { struct texplane planes[4]; - bool image_flipped; struct mp_image *mpi; // original input image bool hwdec_mapped; }; @@ -675,7 +675,7 @@ static int pass_bind(struct gl_video *p, struct img_tex tex) } // Rotation by 90° and flipping. -static void get_plane_source_transform(struct gl_video *p, int w, int h, +static void get_plane_source_transform(struct gl_video *p, struct texplane *t, struct gl_transform *out_tr) { struct gl_transform tr = identity_trans; @@ -688,11 +688,11 @@ static void get_plane_source_transform(struct gl_video *p, int w, int h, // basically, recenter to keep the whole image in view float b[2] = {1, 1}; gl_transform_vec(rot, &b[0], &b[1]); - tr.t[0] += b[0] < 0 ? w : 0; - tr.t[1] += b[1] < 0 ? h : 0; + tr.t[0] += b[0] < 0 ? t->w : 0; + tr.t[1] += b[1] < 0 ? t->h : 0; - if (p->image.image_flipped) { - struct gl_transform flip = {{{1, 0}, {0, -1}}, {0, h}}; + if (t->flipped) { + struct gl_transform flip = {{{1, 0}, {0, -1}}, {0, t->h}}; gl_transform_trans(flip, &tr); } @@ -763,7 +763,7 @@ static void pass_get_img_tex(struct gl_video *p, struct video_image *vimg, .components = p->image_desc.components[n], }; snprintf(tex[n].swizzle, sizeof(tex[n].swizzle), "%s", t->swizzle); - get_plane_source_transform(p, t->w, t->h, &tex[n].transform); + get_plane_source_transform(p, t, &tex[n].transform); if (p->image_params.rotate % 180 == 90) MPSWAP(int, tex[n].w, tex[n].h); @@ -2986,10 +2986,12 @@ static bool gl_video_upload_image(struct gl_video *p, struct mp_image *mpi) gl_timer_start(p->upload_timer); - vimg->image_flipped = mpi->stride[0] < 0; + for (int n = 0; n < p->plane_count; n++) { struct texplane *plane = &vimg->planes[n]; + plane->flipped = mpi->stride[0] < 0; + gl->BindTexture(plane->gl_target, plane->gl_texture); gl_pbo_upload_tex(&plane->pbo, gl, p->opts.pbo, plane->gl_target, plane->gl_format, plane->gl_type, plane->w, plane->h, -- cgit v1.2.3