diff options
Diffstat (limited to 'video/out/gl_osd.c')
-rw-r--r-- | video/out/gl_osd.c | 103 |
1 files changed, 3 insertions, 100 deletions
diff --git a/video/out/gl_osd.c b/video/out/gl_osd.c index 5477b24197..8a92d3ee8c 100644 --- a/video/out/gl_osd.c +++ b/video/out/gl_osd.c @@ -52,13 +52,7 @@ static const struct osd_fmt_entry osd_to_gl2_formats[SUBBITMAP_COUNT] = { [SUBBITMAP_RGBA] = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, }; -static const struct osd_fmt_entry osd_to_gl_legacy_formats[SUBBITMAP_COUNT] = { - [SUBBITMAP_LIBASS] = {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE}, - [SUBBITMAP_RGBA] = {GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE}, -}; - -struct mpgl_osd *mpgl_osd_init(GL *gl, struct mp_log *log, struct osd_state *osd, - bool legacy) +struct mpgl_osd *mpgl_osd_init(GL *gl, struct mp_log *log, struct osd_state *osd) { GLint max_texture_size; gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); @@ -72,9 +66,7 @@ struct mpgl_osd *mpgl_osd_init(GL *gl, struct mp_log *log, struct osd_state *osd .scratch = talloc_zero_size(ctx, 1), }; - if (legacy) { - ctx->fmt_table = osd_to_gl_legacy_formats; - } else if (gl->es >= 300) { + if (gl->es >= 300) { ctx->fmt_table = osd_to_gles3_formats; } else if (!(gl->mpgl_caps & MPGL_CAP_TEX_RG)) { ctx->fmt_table = osd_to_gl2_formats; @@ -257,11 +249,7 @@ void mpgl_osd_set_gl_state(struct mpgl_osd *ctx, struct mpgl_osd_part *p) gl->Enable(GL_BLEND); const int *factors = &blend_factors[p->format][0]; - if (gl->BlendFuncSeparate) { - gl->BlendFuncSeparate(factors[0], factors[1], factors[2], factors[3]); - } else { - gl->BlendFunc(factors[0], factors[1]); - } + gl->BlendFuncSeparate(factors[0], factors[1], factors[2], factors[3]); } void mpgl_osd_unset_gl_state(struct mpgl_osd *ctx, struct mpgl_osd_part *p) @@ -271,88 +259,3 @@ void mpgl_osd_unset_gl_state(struct mpgl_osd *ctx, struct mpgl_osd_part *p) gl->Disable(GL_BLEND); gl->BindTexture(GL_TEXTURE_2D, 0); } - -struct vertex { - float position[2]; - uint8_t color[4]; - float texcoord[2]; -}; - -static void draw_legacy_cb(void *pctx, struct sub_bitmaps *imgs) -{ - struct mpgl_osd *ctx = pctx; - struct mpgl_osd_part *osd = mpgl_osd_generate(ctx, imgs); - if (!osd) - return; - - if (!osd->num_vertices) { - // 2 triangles primitives per quad = 6 vertices per quad - // not using GL_QUADS, as it is deprecated in OpenGL 3.x and later - osd->vertices = talloc_realloc(osd, osd->vertices, struct vertex, - osd->packer->count * 6); - - struct vertex *va = osd->vertices; - float tex_w = osd->w; - float tex_h = osd->h; - - for (int n = 0; n < osd->packer->count; n++) { - struct sub_bitmap *b = &imgs->parts[n]; - struct pos p = osd->packer->result[n]; - - uint32_t c = imgs->format == SUBBITMAP_LIBASS - ? b->libass.color : 0xFFFFFF00; - uint8_t color[4] = { c >> 24, (c >> 16) & 0xff, - (c >> 8) & 0xff, 255 - (c & 0xff) }; - - float x0 = b->x; - float y0 = b->y; - float x1 = b->x + b->dw; - float y1 = b->y + b->dh; - float tx0 = p.x / tex_w; - float ty0 = p.y / tex_h; - float tx1 = (p.x + b->w) / tex_w; - float ty1 = (p.y + b->h) / tex_h; - -#define COLOR_INIT {color[0], color[1], color[2], color[3]} - struct vertex *v = &va[osd->num_vertices]; - v[0] = (struct vertex) { {x0, y0}, COLOR_INIT, {tx0, ty0} }; - v[1] = (struct vertex) { {x0, y1}, COLOR_INIT, {tx0, ty1} }; - v[2] = (struct vertex) { {x1, y0}, COLOR_INIT, {tx1, ty0} }; - v[3] = (struct vertex) { {x1, y1}, COLOR_INIT, {tx1, ty1} }; - v[4] = v[2]; - v[5] = v[1]; -#undef COLOR_INIT - osd->num_vertices += 6; - } - } - - GL *gl = ctx->gl; - - struct vertex *va = osd->vertices; - size_t stride = sizeof(va[0]); - - gl->VertexPointer(2, GL_FLOAT, stride, &va[0].position[0]); - gl->ColorPointer(4, GL_UNSIGNED_BYTE, stride, &va[0].color[0]); - gl->TexCoordPointer(2, GL_FLOAT, stride, &va[0].texcoord[0]); - - gl->EnableClientState(GL_VERTEX_ARRAY); - gl->EnableClientState(GL_TEXTURE_COORD_ARRAY); - gl->EnableClientState(GL_COLOR_ARRAY); - - mpgl_osd_set_gl_state(ctx, osd); - gl->DrawArrays(GL_TRIANGLES, 0, osd->num_vertices); - mpgl_osd_unset_gl_state(ctx, osd); - - gl->DisableClientState(GL_VERTEX_ARRAY); - gl->DisableClientState(GL_TEXTURE_COORD_ARRAY); - gl->DisableClientState(GL_COLOR_ARRAY); -} - -void mpgl_osd_draw_legacy(struct mpgl_osd *ctx, double pts, - struct mp_osd_res res) -{ - ctx->fmt_table = osd_to_gl_legacy_formats; - for (int n = 0; n < SUBBITMAP_COUNT; n++) - ctx->formats[n] = ctx->fmt_table[n].type != 0; - osd_draw(ctx->osd, res, pts, 0, ctx->formats, draw_legacy_cb, ctx); -} |