diff options
author | wm4 <wm4@nowhere> | 2014-12-09 17:47:02 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-12-09 17:59:04 +0100 |
commit | fb855b86593ad2a9db71cce3aa652ace93af38b5 (patch) | |
tree | ffca8eb74c8cf58dc5e97e0fac2c519b958b7cf7 /video/out/gl_video.c | |
parent | d38bc531cc7ce9c90b74145e2be2e24cb48e501a (diff) | |
download | mpv-fb855b86593ad2a9db71cce3aa652ace93af38b5.tar.bz2 mpv-fb855b86593ad2a9db71cce3aa652ace93af38b5.tar.xz |
client API: expose OpenGL renderer
This adds API to libmpv that lets host applications use the mpv opengl
renderer. This is a more flexible (and possibly more portable) option to
foreign window embedding (via --wid).
This assumes that methods like context sharing and multithreaded OpenGL
rendering are infeasible, and that a way is needed to integrate it with
an application that uses a single thread to render everything.
Add an example that does this with QtQuick/qml. The example is
relatively lazy, but still shows how relatively simple the integration
is. The FBO indirection could probably be avoided, but would require
more work (and would probably lead to worse QtQuick integration, because
it would have to ignore transformations like rotation).
Because this makes mpv directly use the host application's OpenGL
context, there is no platform specific code involved in mpv, except
for hw decoding interop.
main.qml is derived from some Qt example.
The following things are still missing:
- a way to do better video timing
- expose GL renderer options, allow changing them at runtime
- support for color equalizer controls
- support for screenshots
Diffstat (limited to 'video/out/gl_video.c')
-rw-r--r-- | video/out/gl_video.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/video/out/gl_video.c b/video/out/gl_video.c index eef5dfc467..9a762118c3 100644 --- a/video/out/gl_video.c +++ b/video/out/gl_video.c @@ -190,6 +190,7 @@ struct gl_video { struct mp_rect dst_rect; // video rectangle on output window struct mp_osd_res osd_rect; // OSD size/margins int vp_x, vp_y, vp_w, vp_h; // GL viewport + bool vp_vflipped; int frames_rendered; @@ -574,7 +575,10 @@ static void update_uniforms(struct gl_video *p, GLuint program) loc = gl->GetUniformLocation(program, "transform"); if (loc >= 0 && p->vp_w > 0 && p->vp_h > 0) { float matrix[3][3]; - matrix_ortho2d(matrix, 0, p->vp_w, p->vp_h, 0); + int vvp[2] = {p->vp_h, 0}; + if (p->vp_vflipped) + MPSWAP(int, vvp[0], vvp[1]); + matrix_ortho2d(matrix, 0, p->vp_w, vvp[0], vvp[1]); gl->UniformMatrix3fv(loc, 1, GL_FALSE, &matrix[0][0]); } @@ -1786,7 +1790,7 @@ static void check_resize(struct gl_video *p) void gl_video_resize(struct gl_video *p, struct mp_rect *window, struct mp_rect *src, struct mp_rect *dst, - struct mp_osd_res *osd) + struct mp_osd_res *osd, bool vflip) { p->src_rect = *src; p->src_rect_rot = *src; @@ -1803,6 +1807,7 @@ void gl_video_resize(struct gl_video *p, struct mp_rect *window, p->vp_w = window->x1 - window->x0; p->vp_h = window->y1 - window->y0; + p->vp_vflipped = vflip; check_resize(p); } @@ -2188,7 +2193,7 @@ static int init_gl(struct gl_video *p) gl->BindBuffer(GL_ARRAY_BUFFER, 0); - gl->ClearColor(0.0f, 0.0f, 0.0f, 1.0f); + gl_video_set_gl_state(p); debug_check_gl(p, "after init_gl"); @@ -2214,6 +2219,24 @@ void gl_video_uninit(struct gl_video *p) talloc_free(p); } +void gl_video_set_gl_state(struct gl_video *p) +{ + GL *gl = p->gl; + + gl->ClearColor(0.0f, 0.0f, 0.0f, 1.0f); + gl->ActiveTexture(GL_TEXTURE0); +} + +void gl_video_unset_gl_state(struct gl_video *p) +{ + GL *gl = p->gl; + + gl->PixelStorei(GL_PACK_ROW_LENGTH, 0); + gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0); + gl->PixelStorei(GL_PACK_ALIGNMENT, 4); + gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4); +} + // dest = src.<w> (always using 4 components) static void packed_fmt_swizzle(char w[5], const struct packed_fmt_entry *fmt) { |