diff options
author | Niklas Haas <git@haasn.xyz> | 2017-09-14 08:04:55 +0200 |
---|---|---|
committer | Niklas Haas <git@haasn.xyz> | 2017-09-21 15:00:55 +0200 |
commit | 65979986a923a8f08019b257c3fe72cd5e8ecf68 (patch) | |
tree | b8f4b8c17d583594aef0ca509064f8b2ff7128d4 /video/out/opengl/utils.h | |
parent | 20f958c9775652c3213588c2a0824f5353276adc (diff) | |
download | mpv-65979986a923a8f08019b257c3fe72cd5e8ecf68.tar.bz2 mpv-65979986a923a8f08019b257c3fe72cd5e8ecf68.tar.xz |
vo_opengl: refactor into vo_gpu
This is done in several steps:
1. refactor MPGLContext -> struct ra_ctx
2. move GL-specific stuff in vo_opengl into opengl/context.c
3. generalize context creation to support other APIs, and add --gpu-api
4. rename all of the --opengl- options that are no longer opengl-specific
5. move all of the stuff from opengl/* that isn't GL-specific into gpu/
(note: opengl/gl_utils.h became opengl/utils.h)
6. rename vo_opengl to vo_gpu
7. to handle window screenshots, the short-term approach was to just add
it to ra_swchain_fns. Long term (and for vulkan) this has to be moved to
ra itself (and vo_gpu altered to compensate), but this was a stop-gap
measure to prevent this commit from getting too big
8. move ra->fns->flush to ra_gl_ctx instead
9. some other minor changes that I've probably already forgotten
Note: This is one half of a major refactor, the other half of which is
provided by rossy's following commit. This commit enables support for
all linux platforms, while his version enables support for all non-linux
platforms.
Note 2: vo_opengl_cb.c also re-uses ra_gl_ctx so it benefits from the
--opengl- options like --opengl-early-flush, --opengl-finish etc. Should
be a strict superset of the old functionality.
Disclaimer: Since I have no way of compiling mpv on all platforms, some
of these ports were done blindly. Specifically, the blind ports included
context_mali_fbdev.c and context_rpi.c. Since they're both based on
egl_helpers, the port should have gone smoothly without any major
changes required. But if somebody complains about a compile error on
those platforms (assuming anybody actually uses them), you know where to
complain.
Diffstat (limited to 'video/out/opengl/utils.h')
-rw-r--r-- | video/out/opengl/utils.h | 151 |
1 files changed, 42 insertions, 109 deletions
diff --git a/video/out/opengl/utils.h b/video/out/opengl/utils.h index 7d00d26cf5..18cab476ed 100644 --- a/video/out/opengl/utils.h +++ b/video/out/opengl/utils.h @@ -1,121 +1,54 @@ -#pragma once +/* + * This file is part of mpv. + * Parts based on MPlayer code by Reimar Döffinger. + * + * 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. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with mpv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MP_GL_UTILS_ +#define MP_GL_UTILS_ -#include <stdbool.h> #include <math.h> -#include "video/out/vo.h" -#include "ra.h" +#include "video/out/gpu/utils.h" +#include "common.h" -// A 3x2 matrix, with the translation part separate. -struct gl_transform { - // row-major, e.g. in mathematical notation: - // | m[0][0] m[0][1] | - // | m[1][0] m[1][1] | - float m[2][2]; - float t[2]; -}; - -static const struct gl_transform identity_trans = { - .m = {{1.0, 0.0}, {0.0, 1.0}}, - .t = {0.0, 0.0}, -}; - -void gl_transform_ortho(struct gl_transform *t, float x0, float x1, - float y0, float y1); - -// This treats m as an affine transformation, in other words m[2][n] gets -// added to the output. -static inline void gl_transform_vec(struct gl_transform t, float *x, float *y) -{ - float vx = *x, vy = *y; - *x = vx * t.m[0][0] + vy * t.m[0][1] + t.t[0]; - *y = vx * t.m[1][0] + vy * t.m[1][1] + t.t[1]; -} +struct mp_log; -struct mp_rect_f { - float x0, y0, x1, y1; -}; - -// Semantic equality (fuzzy comparison) -static inline bool mp_rect_f_seq(struct mp_rect_f a, struct mp_rect_f b) -{ - return fabs(a.x0 - b.x0) < 1e-6 && fabs(a.x1 - b.x1) < 1e-6 && - fabs(a.y0 - b.y0) < 1e-6 && fabs(a.y1 - b.y1) < 1e-6; -} - -static inline void gl_transform_rect(struct gl_transform t, struct mp_rect_f *r) -{ - gl_transform_vec(t, &r->x0, &r->y0); - gl_transform_vec(t, &r->x1, &r->y1); -} +void gl_check_error(GL *gl, struct mp_log *log, const char *info); -static inline bool gl_transform_eq(struct gl_transform a, struct gl_transform b) -{ - for (int x = 0; x < 2; x++) { - for (int y = 0; y < 2; y++) { - if (a.m[x][y] != b.m[x][y]) - return false; - } - } +void gl_upload_tex(GL *gl, GLenum target, GLenum format, GLenum type, + const void *dataptr, int stride, + int x, int y, int w, int h); - return a.t[0] == b.t[0] && a.t[1] == b.t[1]; -} +mp_image_t *gl_read_fbo_contents(GL *gl, int fbo, int w, int h); -void gl_transform_trans(struct gl_transform t, struct gl_transform *x); - -struct fbodst { - struct ra_tex *tex; - bool flip; // mirror vertically +struct gl_vao { + GL *gl; + GLuint vao; // the VAO object, or 0 if unsupported by driver + GLuint buffer; // GL_ARRAY_BUFFER used for the data + int stride; // size of each element (interleaved elements are assumed) + const struct ra_renderpass_input *entries; + int num_entries; }; -void gl_transform_ortho_fbodst(struct gl_transform *t, struct fbodst fbo); - -// A pool of buffers, which can grow as needed -struct ra_buf_pool { - struct ra_buf_params current_params; - struct ra_buf **buffers; - int num_buffers; - int index; -}; - -void ra_buf_pool_uninit(struct ra *ra, struct ra_buf_pool *pool); - -// Note: params->initial_data is *not* supported -struct ra_buf *ra_buf_pool_get(struct ra *ra, struct ra_buf_pool *pool, - const struct ra_buf_params *params); - -// Helper that wraps ra_tex_upload using texture upload buffers to ensure that -// params->buf is always set. This is intended for RA-internal usage. -bool ra_tex_upload_pbo(struct ra *ra, struct ra_buf_pool *pbo, - const struct ra_tex_upload_params *params); - -// Layout rules for GLSL's packing modes -struct ra_layout std140_layout(struct ra_renderpass_input *inp); -struct ra_layout std430_layout(struct ra_renderpass_input *inp); - -struct fbotex { - struct ra *ra; - struct ra_tex *tex; - int lw, lh; // logical (configured) size, <= than texture size - struct fbodst fbo; -}; - -void fbotex_uninit(struct fbotex *fbo); -bool fbotex_change(struct fbotex *fbo, struct ra *ra, struct mp_log *log, - int w, int h, const struct ra_format *fmt, int flags); -#define FBOTEX_FUZZY_W 1 -#define FBOTEX_FUZZY_H 2 -#define FBOTEX_FUZZY (FBOTEX_FUZZY_W | FBOTEX_FUZZY_H) - -// A wrapper around ra_timer that does result pooling, averaging etc. -struct timer_pool; +void gl_vao_init(struct gl_vao *vao, GL *gl, int stride, + const struct ra_renderpass_input *entries, + int num_entries); +void gl_vao_uninit(struct gl_vao *vao); +void gl_vao_draw_data(struct gl_vao *vao, GLenum prim, void *ptr, size_t num); -struct timer_pool *timer_pool_create(struct ra *ra); -void timer_pool_destroy(struct timer_pool *pool); -void timer_pool_start(struct timer_pool *pool); -void timer_pool_stop(struct timer_pool *pool); -struct mp_pass_perf timer_pool_measure(struct timer_pool *pool); +void gl_set_debug_logger(GL *gl, struct mp_log *log); -// print a multi line string with line numbers (e.g. for shader sources) -// log, lev: module and log level, as in mp_msg() -void mp_log_source(struct mp_log *log, int lev, const char *src); +#endif |