2012-10-03 16:25:41 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2012-10-03 16:25:41 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-10-03 16:25:41 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2012-10-03 16:25:41 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2016-01-19 17:36:34 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2015-06-08 20:13:00 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2012-10-03 16:25:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
2012-10-03 16:25:41 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2017-08-11 18:11:21 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "video/csputils.h"
|
|
|
|
#include "video/mp_image.h"
|
2015-08-29 02:12:56 +00:00
|
|
|
#include "osd.h"
|
2012-10-03 16:25:41 +00:00
|
|
|
|
2017-07-22 19:53:50 +00:00
|
|
|
#define GLSL(x) gl_sc_add(sc, #x "\n");
|
|
|
|
|
vo_opengl: fix alpha values written to the framebuffer
When blending OSD and subtitles onto the video, we write bogus alpha
values. This doesn't normally matter, because these values are normally
unused and discarded. But at least on Wayland, the alpha values are used
by the compositor and leads to transparent windows even with opaque
video on places where the OSD happens to use transparency.
(Also see github issue #338.)
Until now, the alpha basically contained garbage. The source factor
GL_SRC_ALPHA meant that alpha was multiplied with itself. Use GL_ONE
instead (which is why we have to use glBlendFuncSeparate()). This should
give correct results, even with video that has alpha. (Or at least it's
something close to correct, I haven't thought too hard how the
compositor will blend it, and in fact I couldn't manage to test it.)
If glBlendFuncSeparate() is not available, fall back to glBlendFunc(),
which does the same as the code did before this commit. Technically, we
support GL 1.1, but glBlendFuncSeparate is 1.4, and I guess we should
try not to crash if vo_opengl_old runs on a system with GL 1.1 drivers
only.
2013-11-10 02:14:13 +00:00
|
|
|
// glBlendFuncSeparate() arguments
|
|
|
|
static const int blend_factors[SUBBITMAP_COUNT][4] = {
|
2017-08-05 12:20:14 +00:00
|
|
|
[SUBBITMAP_LIBASS] = {RA_BLEND_SRC_ALPHA, RA_BLEND_ONE_MINUS_SRC_ALPHA,
|
|
|
|
RA_BLEND_ONE, RA_BLEND_ONE_MINUS_SRC_ALPHA},
|
|
|
|
[SUBBITMAP_RGBA] = {RA_BLEND_ONE, RA_BLEND_ONE_MINUS_SRC_ALPHA,
|
|
|
|
RA_BLEND_ONE, RA_BLEND_ONE_MINUS_SRC_ALPHA},
|
2012-10-03 16:25:41 +00:00
|
|
|
};
|
|
|
|
|
2015-01-29 17:29:28 +00:00
|
|
|
struct vertex {
|
|
|
|
float position[2];
|
|
|
|
float texcoord[2];
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
uint8_t ass_color[4];
|
2015-01-29 17:29:28 +00:00
|
|
|
};
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
static const struct ra_renderpass_input vertex_vao[] = {
|
|
|
|
{"position", RA_VARTYPE_FLOAT, 2, 1, offsetof(struct vertex, position)},
|
|
|
|
{"texcoord" , RA_VARTYPE_FLOAT, 2, 1, offsetof(struct vertex, texcoord)},
|
|
|
|
{"ass_color", RA_VARTYPE_BYTE_UNORM, 4, 1, offsetof(struct vertex, ass_color)},
|
2015-01-29 17:29:28 +00:00
|
|
|
};
|
|
|
|
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
struct mpgl_osd_part {
|
|
|
|
enum sub_bitmap_format format;
|
2015-03-18 11:33:14 +00:00
|
|
|
int change_id;
|
2017-08-05 11:39:20 +00:00
|
|
|
struct ra_tex *texture;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
int w, h;
|
|
|
|
int num_subparts;
|
2015-08-18 20:59:22 +00:00
|
|
|
int prev_num_subparts;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
struct sub_bitmap *subparts;
|
2017-07-22 19:46:59 +00:00
|
|
|
int num_vertices;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
struct vertex *vertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mpgl_osd {
|
|
|
|
struct mp_log *log;
|
|
|
|
struct osd_state *osd;
|
2017-08-05 11:39:20 +00:00
|
|
|
struct ra *ra;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
struct mpgl_osd_part *parts[MAX_OSD_PARTS];
|
2017-08-05 11:39:20 +00:00
|
|
|
const struct ra_format *fmt_table[SUBBITMAP_COUNT];
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
bool formats[SUBBITMAP_COUNT];
|
2017-08-11 11:02:13 +00:00
|
|
|
bool change_flag; // for reporting to API user only
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
// temporary
|
|
|
|
int stereo_mode;
|
2016-03-21 21:23:41 +00:00
|
|
|
struct mp_osd_res osd_res;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
void *scratch;
|
|
|
|
};
|
|
|
|
|
2017-08-05 11:39:20 +00:00
|
|
|
struct mpgl_osd *mpgl_osd_init(struct ra *ra, struct mp_log *log,
|
2017-08-19 02:33:40 +00:00
|
|
|
struct osd_state *osd)
|
2012-10-03 16:25:41 +00:00
|
|
|
{
|
|
|
|
struct mpgl_osd *ctx = talloc_ptrtype(NULL, ctx);
|
|
|
|
*ctx = (struct mpgl_osd) {
|
2013-09-11 23:33:33 +00:00
|
|
|
.log = log,
|
2014-06-15 18:46:57 +00:00
|
|
|
.osd = osd,
|
2017-08-05 11:39:20 +00:00
|
|
|
.ra = ra,
|
2017-08-11 11:02:13 +00:00
|
|
|
.change_flag = true,
|
2012-10-03 16:25:41 +00:00
|
|
|
.scratch = talloc_zero_size(ctx, 1),
|
|
|
|
};
|
|
|
|
|
2017-08-05 11:39:20 +00:00
|
|
|
ctx->fmt_table[SUBBITMAP_LIBASS] = ra_find_unorm_format(ra, 1, 1);
|
|
|
|
ctx->fmt_table[SUBBITMAP_RGBA] = ra_find_unorm_format(ra, 1, 4);
|
2014-12-16 17:55:02 +00:00
|
|
|
|
2016-07-01 17:47:31 +00:00
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++)
|
|
|
|
ctx->parts[n] = talloc_zero(ctx, struct mpgl_osd_part);
|
2012-10-03 16:25:41 +00:00
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
for (int n = 0; n < SUBBITMAP_COUNT; n++)
|
2016-05-12 18:08:49 +00:00
|
|
|
ctx->formats[n] = !!ctx->fmt_table[n];
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
|
2012-10-03 16:25:41 +00:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mpgl_osd_destroy(struct mpgl_osd *ctx)
|
|
|
|
{
|
2014-06-15 18:46:57 +00:00
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
|
2012-10-03 16:25:41 +00:00
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++) {
|
|
|
|
struct mpgl_osd_part *p = ctx->parts[n];
|
2017-08-05 11:39:20 +00:00
|
|
|
ra_tex_free(ctx->ra, &p->texture);
|
2012-10-03 16:25:41 +00:00
|
|
|
}
|
|
|
|
talloc_free(ctx);
|
|
|
|
}
|
|
|
|
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
static int next_pow2(int v)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < 30; x++) {
|
|
|
|
if ((1 << x) >= v)
|
|
|
|
return 1 << x;
|
|
|
|
}
|
|
|
|
return INT_MAX;
|
|
|
|
}
|
|
|
|
|
2012-10-03 16:25:41 +00:00
|
|
|
static bool upload_osd(struct mpgl_osd *ctx, struct mpgl_osd_part *osd,
|
|
|
|
struct sub_bitmaps *imgs)
|
|
|
|
{
|
2017-08-05 11:39:20 +00:00
|
|
|
struct ra *ra = ctx->ra;
|
2016-07-03 15:33:59 +00:00
|
|
|
bool ok = false;
|
2012-10-03 16:25:41 +00:00
|
|
|
|
2016-07-01 17:47:31 +00:00
|
|
|
assert(imgs->packed);
|
|
|
|
|
|
|
|
int req_w = next_pow2(imgs->packed_w);
|
|
|
|
int req_h = next_pow2(imgs->packed_h);
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
|
2017-08-05 11:39:20 +00:00
|
|
|
const struct ra_format *fmt = ctx->fmt_table[imgs->format];
|
2016-05-12 18:08:49 +00:00
|
|
|
assert(fmt);
|
2012-10-03 16:25:41 +00:00
|
|
|
|
2017-08-05 11:39:20 +00:00
|
|
|
if (!osd->texture || req_w > osd->w || req_h > osd->h ||
|
|
|
|
osd->format != imgs->format)
|
|
|
|
{
|
|
|
|
ra_tex_free(ra, &osd->texture);
|
2012-10-03 16:25:41 +00:00
|
|
|
|
|
|
|
osd->format = imgs->format;
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
osd->w = FFMAX(32, req_w);
|
|
|
|
osd->h = FFMAX(32, req_h);
|
2012-10-03 16:25:41 +00:00
|
|
|
|
2016-07-03 15:33:59 +00:00
|
|
|
MP_VERBOSE(ctx, "Reallocating OSD texture to %dx%d.\n", osd->w, osd->h);
|
|
|
|
|
2017-08-05 11:39:20 +00:00
|
|
|
if (osd->w > ra->max_texture_wh || osd->h > ra->max_texture_wh) {
|
2016-07-03 15:33:59 +00:00
|
|
|
MP_ERR(ctx, "OSD bitmaps do not fit on a surface with the maximum "
|
2017-08-05 11:39:20 +00:00
|
|
|
"supported size %dx%d.\n", ra->max_texture_wh,
|
|
|
|
ra->max_texture_wh);
|
2016-07-03 15:33:59 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2017-08-05 11:39:20 +00:00
|
|
|
struct ra_tex_params params = {
|
|
|
|
.dimensions = 2,
|
|
|
|
.w = osd->w,
|
|
|
|
.h = osd->h,
|
|
|
|
.d = 1,
|
|
|
|
.format = fmt,
|
|
|
|
.render_src = true,
|
|
|
|
.src_linear = true,
|
2017-08-16 20:13:51 +00:00
|
|
|
.host_mutable = true,
|
2017-08-05 11:39:20 +00:00
|
|
|
};
|
|
|
|
osd->texture = ra_tex_create(ra, ¶ms);
|
|
|
|
if (!osd->texture)
|
|
|
|
goto done;
|
2012-10-03 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 20:13:51 +00:00
|
|
|
struct ra_tex_upload_params params = {
|
|
|
|
.tex = osd->texture,
|
|
|
|
.src = imgs->packed->planes[0],
|
|
|
|
.invalidate = true,
|
|
|
|
.rc = &(struct mp_rect){0, 0, imgs->packed_w, imgs->packed_h},
|
|
|
|
.stride = imgs->packed->stride[0],
|
|
|
|
};
|
2017-08-05 11:39:20 +00:00
|
|
|
|
2017-08-19 02:33:40 +00:00
|
|
|
ok = ra->fns->tex_upload(ra, ¶ms);
|
2012-10-03 16:25:41 +00:00
|
|
|
|
2016-07-03 15:33:59 +00:00
|
|
|
done:
|
|
|
|
return ok;
|
2012-10-03 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
static void gen_osd_cb(void *pctx, struct sub_bitmaps *imgs)
|
2012-10-03 16:25:41 +00:00
|
|
|
{
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
struct mpgl_osd *ctx = pctx;
|
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
if (imgs->num_parts == 0 || !ctx->formats[imgs->format])
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
return;
|
2012-10-03 16:25:41 +00:00
|
|
|
|
|
|
|
struct mpgl_osd_part *osd = ctx->parts[imgs->render_index];
|
|
|
|
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
bool ok = true;
|
2015-03-18 11:33:14 +00:00
|
|
|
if (imgs->change_id != osd->change_id) {
|
|
|
|
if (!upload_osd(ctx, osd, imgs))
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
ok = false;
|
2012-10-03 16:25:41 +00:00
|
|
|
|
2015-03-18 11:33:14 +00:00
|
|
|
osd->change_id = imgs->change_id;
|
2017-08-11 11:02:13 +00:00
|
|
|
ctx->change_flag = true;
|
2012-10-03 16:25:41 +00:00
|
|
|
}
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
osd->num_subparts = ok ? imgs->num_parts : 0;
|
2012-10-03 16:25:41 +00:00
|
|
|
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
MP_TARRAY_GROW(osd, osd->subparts, osd->num_subparts);
|
|
|
|
memcpy(osd->subparts, imgs->parts,
|
|
|
|
osd->num_subparts * sizeof(osd->subparts[0]));
|
2012-10-03 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 19:53:50 +00:00
|
|
|
bool mpgl_osd_draw_prepare(struct mpgl_osd *ctx, int index,
|
|
|
|
struct gl_shader_cache *sc)
|
|
|
|
{
|
|
|
|
assert(index >= 0 && index < MAX_OSD_PARTS);
|
|
|
|
struct mpgl_osd_part *part = ctx->parts[index];
|
|
|
|
|
|
|
|
enum sub_bitmap_format fmt = part->format;
|
2018-11-17 16:12:42 +00:00
|
|
|
if (!fmt || !part->num_subparts || !part->texture)
|
2017-07-22 19:53:50 +00:00
|
|
|
return false;
|
|
|
|
|
2017-08-05 11:39:20 +00:00
|
|
|
gl_sc_uniform_texture(sc, "osdtex", part->texture);
|
2017-07-22 19:53:50 +00:00
|
|
|
switch (fmt) {
|
|
|
|
case SUBBITMAP_RGBA: {
|
|
|
|
GLSL(color = texture(osdtex, texcoord).bgra;)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SUBBITMAP_LIBASS: {
|
|
|
|
GLSL(color =
|
|
|
|
vec4(ass_color.rgb, ass_color.a * texture(osdtex, texcoord).r);)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-13 20:14:18 +00:00
|
|
|
static void write_quad(struct vertex *va, struct gl_transform t,
|
2015-01-29 17:29:28 +00:00
|
|
|
float x0, float y0, float x1, float y1,
|
|
|
|
float tx0, float ty0, float tx1, float ty1,
|
2015-01-30 13:02:09 +00:00
|
|
|
float tex_w, float tex_h, const uint8_t color[4])
|
2012-10-03 16:25:41 +00:00
|
|
|
{
|
2015-03-13 20:14:18 +00:00
|
|
|
gl_transform_vec(t, &x0, &y0);
|
|
|
|
gl_transform_vec(t, &x1, &y1);
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
|
2015-01-29 17:29:28 +00:00
|
|
|
#define COLOR_INIT {color[0], color[1], color[2], color[3]}
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
va[0] = (struct vertex){ {x0, y0}, {tx0 / tex_w, ty0 / tex_h}, COLOR_INIT };
|
|
|
|
va[1] = (struct vertex){ {x0, y1}, {tx0 / tex_w, ty1 / tex_h}, COLOR_INIT };
|
|
|
|
va[2] = (struct vertex){ {x1, y0}, {tx1 / tex_w, ty0 / tex_h}, COLOR_INIT };
|
|
|
|
va[3] = (struct vertex){ {x1, y1}, {tx1 / tex_w, ty1 / tex_h}, COLOR_INIT };
|
2015-01-29 17:29:28 +00:00
|
|
|
va[4] = va[2];
|
|
|
|
va[5] = va[1];
|
|
|
|
#undef COLOR_INIT
|
|
|
|
}
|
|
|
|
|
2017-07-22 19:46:59 +00:00
|
|
|
static void generate_verts(struct mpgl_osd_part *part, struct gl_transform t)
|
2015-01-29 17:29:28 +00:00
|
|
|
{
|
2017-10-27 12:19:57 +00:00
|
|
|
MP_TARRAY_GROW(part, part->vertices,
|
|
|
|
part->num_vertices + part->num_subparts * 6);
|
2012-10-03 16:25:41 +00:00
|
|
|
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
for (int n = 0; n < part->num_subparts; n++) {
|
|
|
|
struct sub_bitmap *b = &part->subparts[n];
|
2017-07-22 19:46:59 +00:00
|
|
|
struct vertex *va = &part->vertices[part->num_vertices];
|
2015-01-29 17:29:28 +00:00
|
|
|
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
// NOTE: the blend color is used with SUBBITMAP_LIBASS only, so it
|
|
|
|
// doesn't matter that we upload garbage for the other formats
|
|
|
|
uint32_t c = b->libass.color;
|
|
|
|
uint8_t color[4] = { c >> 24, (c >> 16) & 0xff,
|
|
|
|
(c >> 8) & 0xff, 255 - (c & 0xff) };
|
2015-01-29 17:29:28 +00:00
|
|
|
|
2017-10-27 12:19:57 +00:00
|
|
|
write_quad(va, t,
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
b->x, b->y, b->x + b->dw, b->y + b->dh,
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
b->src_x, b->src_y, b->src_x + b->w, b->src_y + b->h,
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
part->w, part->h, color);
|
2015-01-29 17:29:28 +00:00
|
|
|
|
2017-10-27 12:19:57 +00:00
|
|
|
part->num_vertices += 6;
|
|
|
|
}
|
2015-01-29 17:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// number of screen divisions per axis (x=0, y=1) for the current 3D mode
|
|
|
|
static void get_3d_side_by_side(int stereo_mode, int div[2])
|
|
|
|
{
|
|
|
|
div[0] = div[1] = 1;
|
|
|
|
switch (stereo_mode) {
|
|
|
|
case MP_STEREO3D_SBS2L:
|
|
|
|
case MP_STEREO3D_SBS2R: div[0] = 2; break;
|
|
|
|
case MP_STEREO3D_AB2R:
|
|
|
|
case MP_STEREO3D_AB2L: div[1] = 2; break;
|
|
|
|
}
|
2012-10-03 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-07 14:44:15 +00:00
|
|
|
void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
|
2017-09-20 08:45:33 +00:00
|
|
|
struct gl_shader_cache *sc, struct ra_fbo fbo)
|
2012-10-03 16:25:41 +00:00
|
|
|
{
|
2017-07-22 19:46:59 +00:00
|
|
|
struct mpgl_osd_part *part = ctx->parts[index];
|
|
|
|
|
2015-01-29 17:29:28 +00:00
|
|
|
int div[2];
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
get_3d_side_by_side(ctx->stereo_mode, div);
|
2015-01-29 17:29:28 +00:00
|
|
|
|
2017-07-22 19:46:59 +00:00
|
|
|
part->num_vertices = 0;
|
2015-03-16 19:10:48 +00:00
|
|
|
|
2015-01-29 17:29:28 +00:00
|
|
|
for (int x = 0; x < div[0]; x++) {
|
|
|
|
for (int y = 0; y < div[1]; y++) {
|
2015-03-13 20:14:18 +00:00
|
|
|
struct gl_transform t;
|
2017-09-20 08:45:33 +00:00
|
|
|
gl_transform_ortho_fbo(&t, fbo);
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
float a_x = ctx->osd_res.w * x;
|
|
|
|
float a_y = ctx->osd_res.h * y;
|
2015-03-13 20:14:18 +00:00
|
|
|
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];
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
|
2017-07-22 19:46:59 +00:00
|
|
|
generate_verts(part, t);
|
2015-01-29 17:29:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-22 19:46:59 +00:00
|
|
|
|
|
|
|
const int *factors = &blend_factors[part->format][0];
|
2017-08-05 12:20:14 +00:00
|
|
|
gl_sc_blend(sc, factors[0], factors[1], factors[2], factors[3]);
|
2017-07-22 19:46:59 +00:00
|
|
|
|
2017-08-18 00:31:58 +00:00
|
|
|
gl_sc_dispatch_draw(sc, fbo.tex, false, vertex_vao, MP_ARRAY_SIZE(vertex_vao),
|
2017-09-27 22:07:42 +00:00
|
|
|
sizeof(struct vertex), part->vertices, part->num_vertices);
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
}
|
2015-01-29 17:29:28 +00:00
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
static void set_res(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mode)
|
|
|
|
{
|
|
|
|
int div[2];
|
|
|
|
get_3d_side_by_side(stereo_mode, div);
|
|
|
|
|
|
|
|
res.w /= div[0];
|
|
|
|
res.h /= div[1];
|
|
|
|
ctx->osd_res = res;
|
|
|
|
}
|
|
|
|
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
void mpgl_osd_generate(struct mpgl_osd *ctx, struct mp_osd_res res, double pts,
|
2015-03-23 01:42:19 +00:00
|
|
|
int stereo_mode, int draw_flags)
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
{
|
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++)
|
|
|
|
ctx->parts[n]->num_subparts = 0;
|
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
set_res(ctx, res, stereo_mode);
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
osd_draw(ctx->osd, ctx->osd_res, pts, draw_flags, ctx->formats, gen_osd_cb, ctx);
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
ctx->stereo_mode = stereo_mode;
|
2015-08-18 20:59:22 +00:00
|
|
|
|
|
|
|
// Parts going away does not necessarily result in gen_osd_cb() being called
|
|
|
|
// (not even with num_parts==0), so check this separately.
|
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++) {
|
|
|
|
struct mpgl_osd_part *part = ctx->parts[n];
|
|
|
|
if (part->num_subparts != part->prev_num_subparts)
|
2017-08-11 11:02:13 +00:00
|
|
|
ctx->change_flag = true;
|
2015-08-18 20:59:22 +00:00
|
|
|
part->prev_num_subparts = part->num_subparts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
// See osd_resize() for remarks. This function is an optional optimization too.
|
|
|
|
void mpgl_osd_resize(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mode)
|
|
|
|
{
|
|
|
|
set_res(ctx, res, stereo_mode);
|
|
|
|
osd_resize(ctx->osd, ctx->osd_res);
|
|
|
|
}
|
|
|
|
|
2017-08-11 11:02:13 +00:00
|
|
|
bool mpgl_osd_check_change(struct mpgl_osd *ctx, struct mp_osd_res *res,
|
|
|
|
double pts)
|
2015-08-18 20:59:22 +00:00
|
|
|
{
|
2017-08-15 17:12:39 +00:00
|
|
|
ctx->change_flag = false;
|
2017-08-11 11:02:13 +00:00
|
|
|
mpgl_osd_generate(ctx, *res, pts, 0, 0);
|
|
|
|
return ctx->change_flag;
|
2012-10-03 16:25:41 +00:00
|
|
|
}
|