opengl: assume the video area is the same as the "original" area

This commit is contained in:
Steve Lhomme 2024-03-06 13:38:43 +01:00
parent 5b65b93eb1
commit 2b6405c7f4
4 changed files with 28 additions and 4 deletions

View File

@ -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

View File

@ -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
*

View File

@ -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;
}

View File

@ -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;