diff --git a/modules/video_output/opengl/sub_renderer.c b/modules/video_output/opengl/sub_renderer.c index 82bc8ae936..fb3550b57d 100644 --- a/modules/video_output/opengl/sub_renderer.c +++ b/modules/video_output/opengl/sub_renderer.c @@ -68,6 +68,7 @@ struct vlc_gl_sub_renderer gl_region_t *regions; unsigned region_count; + unsigned output_width, output_height; GLuint program_id; struct { @@ -130,6 +131,8 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api, sr->api = api; sr->vt = vt; sr->region_count = 0; + sr->output_width = 0; + sr->output_height = 0; sr->regions = NULL; static const char *const VERTEX_SHADER_SRC = @@ -223,12 +226,23 @@ vlc_gl_sub_renderer_Delete(struct vlc_gl_sub_renderer *sr) free(sr); } +void +vlc_gl_sub_renderer_SetOutputSize(struct vlc_gl_sub_renderer *sr, + unsigned width, unsigned height) +{ + sr->output_width = width; + sr->output_height = height; +} + int vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr, const vlc_render_subpicture *subpicture) { GL_ASSERT_NOERROR(sr->vt); + if (unlikely(sr->output_width == 0 || sr->output_height == 0)) + return VLC_EINVAL; + const struct vlc_gl_interop *interop = sr->interop; int last_count = sr->region_count; @@ -261,10 +275,10 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr, glr->tex_height = 1.0; } glr->alpha = (float)r->i_alpha / 255; - glr->left = 2.0 * (r->place.x ) / subpicture->i_original_picture_width - 1.0; - glr->top = -2.0 * (r->place.y ) / subpicture->i_original_picture_height + 1.0; - glr->right = 2.0 * (r->place.x + r->place.width ) / subpicture->i_original_picture_width - 1.0; - glr->bottom = -2.0 * (r->place.y + r->place.height) / subpicture->i_original_picture_height + 1.0; + glr->left = 2.0 * (r->place.x ) / sr->output_width - 1.0; + glr->top = -2.0 * (r->place.y ) / sr->output_height + 1.0; + glr->right = 2.0 * (r->place.x + r->place.width ) / sr->output_width - 1.0; + glr->bottom = -2.0 * (r->place.y + r->place.height) / sr->output_height + 1.0; glr->texture = 0; /* Try to recycle the textures allocated by the previous diff --git a/modules/video_output/opengl/sub_renderer.h b/modules/video_output/opengl/sub_renderer.h index b255b1c1ac..edec795d3e 100644 --- a/modules/video_output/opengl/sub_renderer.h +++ b/modules/video_output/opengl/sub_renderer.h @@ -72,6 +72,13 @@ int vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr, const struct vlc_render_subpicture *subpicture); +/** + * Change the output size + */ +void +vlc_gl_sub_renderer_SetOutputSize(struct vlc_gl_sub_renderer *sr, + unsigned width, unsigned height); + /** * Draw the prepared subpicture * diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c index 354ac7af22..15e2a7c792 100644 --- a/modules/video_output/opengl/vout_helper.c +++ b/modules/video_output/opengl/vout_helper.c @@ -358,6 +358,7 @@ void vout_display_opengl_SetOutputSize(vout_display_opengl_t *vgl, /* The renderer, last filter in the chain, necessarily accepts the new * output size */ assert(ret == VLC_SUCCESS); + vlc_gl_sub_renderer_SetOutputSize(vgl->sub_renderer, width, height); (void) ret; } diff --git a/test/modules/video_output/opengl/sub_renderer.c b/test/modules/video_output/opengl/sub_renderer.c index 89dcd55ebd..5297edaf9b 100644 --- a/test/modules/video_output/opengl/sub_renderer.c +++ b/test/modules/video_output/opengl/sub_renderer.c @@ -173,6 +173,8 @@ static void test_opengl_offscreen( memcpy(&picture->p[0].p_pixels[0 * 4 + picture->p[0].i_pitch], blue, sizeof(blue)); memcpy(&picture->p[0].p_pixels[1 * 4 + picture->p[0].i_pitch], white, sizeof(white)); + vlc_gl_sub_renderer_SetOutputSize(sr, 4, 4); + vlc_render_subpicture *subpicture = vlc_render_subpicture_New(); assert(subpicture != NULL); subpicture->i_original_picture_width = 4;