mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
vo_opengl: osd: refactor and simplify
Reduce this to 1 draw call per OSD pass. This removes the need for some annoying special handling regarding 3D video support (we supported duplicating the OSD/subtitles for side-by-side 3D output etc.). Remove the unneeded texture sampler uniform thing.
This commit is contained in:
parent
2378acc3b3
commit
1c81311673
@ -55,6 +55,7 @@ struct mpgl_osd_part {
|
||||
int num_subparts;
|
||||
int prev_num_subparts;
|
||||
struct sub_bitmap *subparts;
|
||||
int num_vertices;
|
||||
struct vertex *vertices;
|
||||
};
|
||||
|
||||
@ -226,14 +227,14 @@ static void write_quad(struct vertex *va, struct gl_transform t,
|
||||
#undef COLOR_INIT
|
||||
}
|
||||
|
||||
static int generate_verts(struct mpgl_osd_part *part, struct gl_transform t)
|
||||
static void generate_verts(struct mpgl_osd_part *part, struct gl_transform t)
|
||||
{
|
||||
int num_vertices = part->num_subparts * 6;
|
||||
MP_TARRAY_GROW(part, part->vertices, num_vertices);
|
||||
MP_TARRAY_GROW(part, part->vertices, part->num_vertices + num_vertices);
|
||||
|
||||
for (int n = 0; n < part->num_subparts; n++) {
|
||||
struct sub_bitmap *b = &part->subparts[n];
|
||||
struct vertex *va = part->vertices;
|
||||
struct vertex *va = &part->vertices[part->num_vertices];
|
||||
|
||||
// NOTE: the blend color is used with SUBBITMAP_LIBASS only, so it
|
||||
// doesn't matter that we upload garbage for the other formats
|
||||
@ -247,28 +248,7 @@ static int generate_verts(struct mpgl_osd_part *part, struct gl_transform t)
|
||||
part->w, part->h, color);
|
||||
}
|
||||
|
||||
return num_vertices;
|
||||
}
|
||||
|
||||
static void draw_part(struct mpgl_osd *ctx, int index, struct gl_transform t)
|
||||
{
|
||||
GL *gl = ctx->gl;
|
||||
struct mpgl_osd_part *part = ctx->parts[index];
|
||||
|
||||
int num_vertices = generate_verts(part, t);
|
||||
if (!num_vertices)
|
||||
return;
|
||||
|
||||
gl->Enable(GL_BLEND);
|
||||
gl->BindTexture(GL_TEXTURE_2D, part->texture);
|
||||
|
||||
const int *factors = &blend_factors[part->format][0];
|
||||
gl->BlendFuncSeparate(factors[0], factors[1], factors[2], factors[3]);
|
||||
|
||||
gl_vao_draw_data(&ctx->vao, GL_TRIANGLES, part->vertices, num_vertices);
|
||||
|
||||
gl->BindTexture(GL_TEXTURE_2D, 0);
|
||||
gl->Disable(GL_BLEND);
|
||||
part->num_vertices += num_vertices;
|
||||
}
|
||||
|
||||
// number of screen divisions per axis (x=0, y=1) for the current 3D mode
|
||||
@ -285,10 +265,13 @@ static void get_3d_side_by_side(int stereo_mode, int div[2])
|
||||
|
||||
void mpgl_osd_draw_part(struct mpgl_osd *ctx, int vp_w, int vp_h, int index)
|
||||
{
|
||||
GL *gl = ctx->gl;
|
||||
struct mpgl_osd_part *part = ctx->parts[index];
|
||||
|
||||
int div[2];
|
||||
get_3d_side_by_side(ctx->stereo_mode, div);
|
||||
|
||||
ctx->gl->Viewport(0, 0, vp_w, abs(vp_h));
|
||||
part->num_vertices = 0;
|
||||
|
||||
for (int x = 0; x < div[0]; x++) {
|
||||
for (int y = 0; y < div[1]; y++) {
|
||||
@ -300,9 +283,24 @@ void mpgl_osd_draw_part(struct mpgl_osd *ctx, int vp_w, int vp_h, int index)
|
||||
t.t[0] += a_x * t.m[0][0] + a_y * t.m[1][0];
|
||||
t.t[1] += a_x * t.m[0][1] + a_y * t.m[1][1];
|
||||
|
||||
draw_part(ctx, index, t);
|
||||
generate_verts(part, t);
|
||||
}
|
||||
}
|
||||
|
||||
if (!part->num_vertices)
|
||||
return;
|
||||
|
||||
gl->Enable(GL_BLEND);
|
||||
|
||||
const int *factors = &blend_factors[part->format][0];
|
||||
gl->BlendFuncSeparate(factors[0], factors[1], factors[2], factors[3]);
|
||||
|
||||
ctx->gl->Viewport(0, 0, vp_w, abs(vp_h));
|
||||
|
||||
gl_vao_draw_data(&ctx->vao, GL_TRIANGLES, part->vertices, part->num_vertices);
|
||||
|
||||
gl->BindTexture(GL_TEXTURE_2D, 0);
|
||||
gl->Disable(GL_BLEND);
|
||||
}
|
||||
|
||||
enum sub_bitmap_format mpgl_osd_get_part_format(struct mpgl_osd *ctx, int index)
|
||||
@ -311,6 +309,12 @@ enum sub_bitmap_format mpgl_osd_get_part_format(struct mpgl_osd *ctx, int index)
|
||||
return ctx->parts[index]->format;
|
||||
}
|
||||
|
||||
GLuint mpgl_osd_get_part_texture(struct mpgl_osd *ctx, int index)
|
||||
{
|
||||
assert(index >= 0 && index < MAX_OSD_PARTS);
|
||||
return ctx->parts[index]->texture;
|
||||
}
|
||||
|
||||
struct gl_vao *mpgl_osd_get_vao(struct mpgl_osd *ctx)
|
||||
{
|
||||
return &ctx->vao;
|
||||
|
@ -16,6 +16,7 @@ void mpgl_osd_generate(struct mpgl_osd *ctx, struct mp_osd_res res, double pts,
|
||||
int stereo_mode, int draw_flags);
|
||||
void mpgl_osd_resize(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mode);
|
||||
enum sub_bitmap_format mpgl_osd_get_part_format(struct mpgl_osd *ctx, int index);
|
||||
GLuint mpgl_osd_get_part_texture(struct mpgl_osd *ctx, int index);
|
||||
struct gl_vao *mpgl_osd_get_vao(struct mpgl_osd *ctx);
|
||||
void mpgl_osd_draw_part(struct mpgl_osd *ctx, int vp_w, int vp_h, int index);
|
||||
int64_t mpgl_get_change_counter(struct mpgl_osd *ctx);
|
||||
|
@ -648,19 +648,6 @@ const char *mp_sampler_type(GLenum texture_target)
|
||||
}
|
||||
}
|
||||
|
||||
// gl_sc_uniform_tex() should be preferred.
|
||||
void gl_sc_uniform_sampler(struct gl_shader_cache *sc, char *name, GLenum target,
|
||||
int unit)
|
||||
{
|
||||
struct sc_uniform *u = find_uniform(sc, name);
|
||||
u->type = UT_i;
|
||||
u->size = 1;
|
||||
u->glsl_type = mp_sampler_type(target);
|
||||
u->v.i[0] = unit;
|
||||
u->tex_target = 0;
|
||||
u->tex_handle = 0;
|
||||
}
|
||||
|
||||
void gl_sc_uniform_tex(struct gl_shader_cache *sc, char *name, GLenum target,
|
||||
GLuint texture)
|
||||
{
|
||||
|
@ -154,8 +154,6 @@ void gl_sc_addf(struct gl_shader_cache *sc, const char *textf, ...);
|
||||
void gl_sc_hadd(struct gl_shader_cache *sc, const char *text);
|
||||
void gl_sc_haddf(struct gl_shader_cache *sc, const char *textf, ...);
|
||||
void gl_sc_hadd_bstr(struct gl_shader_cache *sc, struct bstr text);
|
||||
void gl_sc_uniform_sampler(struct gl_shader_cache *sc, char *name, GLenum target,
|
||||
int unit);
|
||||
void gl_sc_uniform_tex(struct gl_shader_cache *sc, char *name, GLenum target,
|
||||
GLuint texture);
|
||||
void gl_sc_uniform_tex_ui(struct gl_shader_cache *sc, char *name, GLuint texture);
|
||||
|
@ -2411,7 +2411,8 @@ static void pass_draw_osd(struct gl_video *p, int draw_flags, double pts,
|
||||
enum sub_bitmap_format fmt = mpgl_osd_get_part_format(p->osd, n);
|
||||
if (!fmt)
|
||||
continue;
|
||||
gl_sc_uniform_sampler(p->sc, "osdtex", GL_TEXTURE_2D, 0);
|
||||
gl_sc_uniform_tex(p->sc, "osdtex", GL_TEXTURE_2D,
|
||||
mpgl_osd_get_part_texture(p->osd, n));
|
||||
switch (fmt) {
|
||||
case SUBBITMAP_RGBA: {
|
||||
pass_describe(p, "drawing osd (rgba)");
|
||||
|
Loading…
Reference in New Issue
Block a user