2013-03-01 20:19:20 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* You can alternatively redistribute this file 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2013-03-30 03:01:17 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <libavutil/common.h>
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
#include "gl_video.h"
|
2013-03-30 03:01:17 +00:00
|
|
|
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2013-03-01 20:19:20 +00:00
|
|
|
#include "gl_common.h"
|
2015-01-28 18:40:46 +00:00
|
|
|
#include "gl_utils.h"
|
2014-12-03 20:54:04 +00:00
|
|
|
#include "gl_hwdec.h"
|
2013-03-01 20:19:20 +00:00
|
|
|
#include "gl_osd.h"
|
|
|
|
#include "filter_kernels.h"
|
|
|
|
#include "aspect.h"
|
|
|
|
#include "video/memcpy_pic.h"
|
|
|
|
#include "bitmap_packer.h"
|
2013-05-25 23:48:39 +00:00
|
|
|
#include "dither.h"
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
static const char vo_opengl_shaders[] =
|
|
|
|
// Generated from gl_video_shaders.glsl
|
2013-07-16 11:28:28 +00:00
|
|
|
#include "video/out/gl_video_shaders.h"
|
2013-03-01 20:19:20 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
// Pixel width of 1D lookup textures.
|
|
|
|
#define LOOKUP_TEXTURE_SIZE 256
|
|
|
|
|
2013-11-04 18:46:15 +00:00
|
|
|
// Texture units 0-3 are used by the video, with unit 0 for free use.
|
|
|
|
// Units 4-5 are used for scaler LUTs.
|
|
|
|
#define TEXUNIT_SCALERS 4
|
|
|
|
#define TEXUNIT_3DLUT 6
|
|
|
|
#define TEXUNIT_DITHER 7
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-20 20:46:19 +00:00
|
|
|
// scale/cscale arguments that map directly to shader filter routines.
|
2013-03-01 20:19:20 +00:00
|
|
|
// Note that the convolution filters are not included in this list.
|
2014-06-10 21:56:05 +00:00
|
|
|
static const char *const fixed_scale_filters[] = {
|
2013-03-01 20:19:20 +00:00
|
|
|
"bilinear",
|
|
|
|
"bicubic_fast",
|
|
|
|
"sharpen3",
|
|
|
|
"sharpen5",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
// must be sorted, and terminated with 0
|
2014-12-08 16:08:26 +00:00
|
|
|
// 2 & 6 are special-cased, the rest can be generated with WEIGHTS_N().
|
|
|
|
int filter_sizes[] =
|
|
|
|
{2, 4, 6, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 0};
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
struct vertex {
|
|
|
|
float position[2];
|
|
|
|
float texcoord[2];
|
|
|
|
};
|
|
|
|
|
2015-01-28 21:22:29 +00:00
|
|
|
static const struct gl_vao_entry vertex_vao[] = {
|
|
|
|
{"vertex_position", 2, GL_FLOAT, false, offsetof(struct vertex, position)},
|
|
|
|
{"vertex_texcoord", 2, GL_FLOAT, false, offsetof(struct vertex, texcoord)},
|
|
|
|
{0}
|
|
|
|
};
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
struct texplane {
|
2013-03-28 19:40:19 +00:00
|
|
|
int w, h;
|
|
|
|
int tex_w, tex_h;
|
2013-03-28 19:48:53 +00:00
|
|
|
GLint gl_internal_format;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2013-03-01 20:19:20 +00:00
|
|
|
GLuint gl_texture;
|
|
|
|
int gl_buffer;
|
|
|
|
int buffer_size;
|
|
|
|
void *buffer_ptr;
|
|
|
|
};
|
|
|
|
|
2013-03-28 19:40:19 +00:00
|
|
|
struct video_image {
|
2013-03-28 20:02:53 +00:00
|
|
|
struct texplane planes[4];
|
2013-03-28 19:40:19 +00:00
|
|
|
bool image_flipped;
|
2015-01-22 17:29:37 +00:00
|
|
|
struct mp_image *mpi; // original input image
|
2013-03-28 19:40:19 +00:00
|
|
|
};
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
struct scaler {
|
|
|
|
int index;
|
|
|
|
const char *name;
|
|
|
|
float params[2];
|
2015-01-18 17:57:12 +00:00
|
|
|
float antiring;
|
2013-03-01 20:19:20 +00:00
|
|
|
struct filter_kernel *kernel;
|
|
|
|
GLuint gl_lut;
|
|
|
|
const char *lut_name;
|
2014-11-28 22:57:06 +00:00
|
|
|
bool insufficient;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
// kernel points here
|
|
|
|
struct filter_kernel kernel_storage;
|
|
|
|
};
|
|
|
|
|
2014-11-23 19:06:05 +00:00
|
|
|
struct fbosurface {
|
|
|
|
struct fbotex fbotex;
|
|
|
|
int64_t pts;
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
bool valid;
|
2014-11-23 19:06:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define FBOSURFACES_MAX 2
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
struct gl_video {
|
|
|
|
GL *gl;
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
struct mp_log *log;
|
2013-03-01 20:19:20 +00:00
|
|
|
struct gl_video_opts opts;
|
|
|
|
bool gl_debug;
|
|
|
|
|
|
|
|
int depth_g;
|
2014-12-24 15:54:47 +00:00
|
|
|
int texture_16bit_depth; // actual bits available in 16 bit textures
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2013-12-01 22:39:13 +00:00
|
|
|
GLenum gl_target; // texture target (GL_TEXTURE_2D, ...) for video and FBOs
|
|
|
|
|
2015-01-28 21:22:29 +00:00
|
|
|
struct gl_vao vao;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
GLuint osd_programs[SUBBITMAP_COUNT];
|
2014-11-23 19:06:05 +00:00
|
|
|
GLuint indirect_program, scale_sep_program, final_program, inter_program;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-06-15 18:46:57 +00:00
|
|
|
struct osd_state *osd_state;
|
2013-03-01 20:19:20 +00:00
|
|
|
struct mpgl_osd *osd;
|
2014-06-15 18:46:57 +00:00
|
|
|
double osd_pts;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
GLuint lut_3d_texture;
|
|
|
|
bool use_lut_3d;
|
|
|
|
|
|
|
|
GLuint dither_texture;
|
|
|
|
float dither_quantization;
|
2013-05-30 11:36:11 +00:00
|
|
|
float dither_center;
|
2013-03-01 20:19:20 +00:00
|
|
|
int dither_size;
|
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
struct mp_image_params real_image_params; // configured format
|
|
|
|
struct mp_image_params image_params; // texture format (mind hwdec case)
|
2014-10-16 21:51:36 +00:00
|
|
|
struct mp_imgfmt_desc image_desc;
|
2015-01-29 14:50:21 +00:00
|
|
|
int plane_count;
|
|
|
|
int image_w, image_h;
|
2013-03-28 19:40:19 +00:00
|
|
|
|
2013-11-13 20:52:34 +00:00
|
|
|
bool is_yuv, is_rgb, is_packed_yuv;
|
2013-07-18 11:52:38 +00:00
|
|
|
bool has_alpha;
|
|
|
|
char color_swizzle[5];
|
2015-01-28 12:50:39 +00:00
|
|
|
float chroma_fix[2];
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2013-05-01 21:59:00 +00:00
|
|
|
float input_gamma, conv_gamma;
|
2015-02-03 16:12:04 +00:00
|
|
|
float user_gamma;
|
|
|
|
bool user_gamma_enabled; // shader handles user_gamma
|
2015-02-03 16:39:30 +00:00
|
|
|
bool sigmoid_enabled;
|
2013-05-01 21:59:00 +00:00
|
|
|
|
2013-03-28 19:40:19 +00:00
|
|
|
struct video_image image;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
struct fbotex indirect_fbo; // RGB target
|
|
|
|
struct fbotex scale_sep_fbo; // first pass when doing 2 pass scaling
|
2014-11-23 19:06:05 +00:00
|
|
|
struct fbosurface surfaces[FBOSURFACES_MAX];
|
2015-01-29 14:50:21 +00:00
|
|
|
size_t surface_idx;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
// state for luma (0) and chroma (1) scalers
|
|
|
|
struct scaler scalers[2];
|
|
|
|
|
2015-01-06 09:47:26 +00:00
|
|
|
// true if scaler is currently upscaling
|
|
|
|
bool upscaling;
|
|
|
|
|
2015-02-03 16:12:04 +00:00
|
|
|
// reinit_rendering must be called
|
|
|
|
bool need_reinit_rendering;
|
|
|
|
|
2015-02-04 22:37:38 +00:00
|
|
|
bool is_interpolated;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
struct mp_csp_equalizer video_eq;
|
|
|
|
|
2014-06-22 06:33:43 +00:00
|
|
|
// Source and destination color spaces for the CMS matrix
|
|
|
|
struct mp_csp_primaries csp_src, csp_dest;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
struct mp_rect src_rect; // displayed part of the source 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
|
2014-12-09 16:47:02 +00:00
|
|
|
bool vp_vflipped;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
int frames_rendered;
|
|
|
|
|
2013-05-25 23:48:39 +00:00
|
|
|
// Cached because computing it can take relatively long
|
|
|
|
int last_dither_matrix_size;
|
|
|
|
float *last_dither_matrix;
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
struct gl_hwdec *hwdec;
|
|
|
|
bool hwdec_active;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
void *scratch;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fmt_entry {
|
|
|
|
int mp_format;
|
|
|
|
GLint internal_format;
|
|
|
|
GLenum format;
|
|
|
|
GLenum type;
|
|
|
|
};
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
// Very special formats, for which OpenGL happens to have direct support
|
2013-03-01 20:19:20 +00:00
|
|
|
static const struct fmt_entry mp_to_gl_formats[] = {
|
2014-06-14 08:03:04 +00:00
|
|
|
{IMGFMT_BGR555, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV},
|
|
|
|
{IMGFMT_BGR565, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV},
|
|
|
|
{IMGFMT_RGB555, GL_RGBA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV},
|
|
|
|
{IMGFMT_RGB565, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5},
|
2013-03-01 20:19:20 +00:00
|
|
|
{0},
|
|
|
|
};
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
static const struct fmt_entry gl_byte_formats[] = {
|
|
|
|
{0, GL_RED, GL_RED, GL_UNSIGNED_BYTE}, // 1 x 8
|
|
|
|
{0, GL_RG, GL_RG, GL_UNSIGNED_BYTE}, // 2 x 8
|
|
|
|
{0, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, // 3 x 8
|
|
|
|
{0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, // 4 x 8
|
|
|
|
{0, GL_R16, GL_RED, GL_UNSIGNED_SHORT}, // 1 x 16
|
|
|
|
{0, GL_RG16, GL_RG, GL_UNSIGNED_SHORT}, // 2 x 16
|
|
|
|
{0, GL_RGB16, GL_RGB, GL_UNSIGNED_SHORT}, // 3 x 16
|
|
|
|
{0, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT}, // 4 x 16
|
|
|
|
};
|
|
|
|
|
2014-12-17 20:48:23 +00:00
|
|
|
static const struct fmt_entry gl_byte_formats_gles3[] = {
|
|
|
|
{0, GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // 1 x 8
|
|
|
|
{0, GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, // 2 x 8
|
|
|
|
{0, GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, // 3 x 8
|
|
|
|
{0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // 4 x 8
|
|
|
|
// There are no filterable texture formats that can be uploaded as
|
|
|
|
// GL_UNSIGNED_SHORT, so apparently we're out of luck.
|
|
|
|
{0, 0, 0, 0}, // 1 x 16
|
|
|
|
{0, 0, 0, 0}, // 2 x 16
|
|
|
|
{0, 0, 0, 0}, // 3 x 16
|
|
|
|
{0, 0, 0, 0}, // 4 x 16
|
|
|
|
};
|
|
|
|
|
2014-12-19 00:03:08 +00:00
|
|
|
static const struct fmt_entry gl_byte_formats_gles2[] = {
|
|
|
|
{0, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, // 1 x 8
|
|
|
|
{0, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, // 2 x 8
|
|
|
|
{0, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, // 3 x 8
|
|
|
|
{0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, // 4 x 8
|
|
|
|
{0, 0, 0, 0}, // 1 x 16
|
|
|
|
{0, 0, 0, 0}, // 2 x 16
|
|
|
|
{0, 0, 0, 0}, // 3 x 16
|
|
|
|
{0, 0, 0, 0}, // 4 x 16
|
|
|
|
};
|
|
|
|
|
2014-12-16 17:55:02 +00:00
|
|
|
static const struct fmt_entry gl_byte_formats_legacy[] = {
|
2014-12-18 13:46:19 +00:00
|
|
|
{0, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, // 1 x 8
|
|
|
|
{0, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, // 2 x 8
|
|
|
|
{0, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, // 3 x 8
|
|
|
|
{0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, // 4 x 8
|
|
|
|
{0, GL_LUMINANCE16, GL_LUMINANCE, GL_UNSIGNED_SHORT},// 1 x 16
|
|
|
|
{0, GL_LUMINANCE16_ALPHA16, GL_LUMINANCE_ALPHA, GL_UNSIGNED_SHORT},// 2 x 16
|
|
|
|
{0, GL_RGB16, GL_RGB, GL_UNSIGNED_SHORT},// 3 x 16
|
|
|
|
{0, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT},// 4 x 16
|
2014-12-16 17:55:02 +00:00
|
|
|
};
|
|
|
|
|
2014-12-08 16:08:26 +00:00
|
|
|
static const struct fmt_entry gl_float16_formats[] = {
|
|
|
|
{0, GL_R16F, GL_RED, GL_FLOAT}, // 1 x f
|
|
|
|
{0, GL_RG16F, GL_RG, GL_FLOAT}, // 2 x f
|
|
|
|
{0, GL_RGB16F, GL_RGB, GL_FLOAT}, // 3 x f
|
|
|
|
{0, GL_RGBA16F, GL_RGBA, GL_FLOAT}, // 4 x f
|
|
|
|
};
|
|
|
|
|
2013-11-13 20:52:34 +00:00
|
|
|
static const struct fmt_entry gl_apple_formats[] = {
|
|
|
|
{IMGFMT_UYVY, GL_RGB, GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE},
|
|
|
|
{IMGFMT_YUYV, GL_RGB, GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
struct packed_fmt_entry {
|
|
|
|
int fmt;
|
|
|
|
int8_t component_size;
|
|
|
|
int8_t components[4]; // source component - 0 means unmapped
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct packed_fmt_entry mp_packed_formats[] = {
|
2015-01-21 18:29:18 +00:00
|
|
|
// w R G B A
|
2013-07-18 11:52:38 +00:00
|
|
|
{IMGFMT_Y8, 1, {1, 0, 0, 0}},
|
|
|
|
{IMGFMT_Y16, 2, {1, 0, 0, 0}},
|
|
|
|
{IMGFMT_YA8, 1, {1, 0, 0, 2}},
|
2015-01-21 18:29:18 +00:00
|
|
|
{IMGFMT_YA16, 2, {1, 0, 0, 2}},
|
2013-07-18 11:52:38 +00:00
|
|
|
{IMGFMT_ARGB, 1, {2, 3, 4, 1}},
|
|
|
|
{IMGFMT_0RGB, 1, {2, 3, 4, 0}},
|
|
|
|
{IMGFMT_BGRA, 1, {3, 2, 1, 4}},
|
|
|
|
{IMGFMT_BGR0, 1, {3, 2, 1, 0}},
|
|
|
|
{IMGFMT_ABGR, 1, {4, 3, 2, 1}},
|
|
|
|
{IMGFMT_0BGR, 1, {4, 3, 2, 0}},
|
|
|
|
{IMGFMT_RGBA, 1, {1, 2, 3, 4}},
|
|
|
|
{IMGFMT_RGB0, 1, {1, 2, 3, 0}},
|
|
|
|
{IMGFMT_BGR24, 1, {3, 2, 1, 0}},
|
|
|
|
{IMGFMT_RGB24, 1, {1, 2, 3, 0}},
|
|
|
|
{IMGFMT_RGB48, 2, {1, 2, 3, 0}},
|
|
|
|
{IMGFMT_RGBA64, 2, {1, 2, 3, 4}},
|
|
|
|
{IMGFMT_BGRA64, 2, {3, 2, 1, 4}},
|
|
|
|
{0},
|
|
|
|
};
|
2013-03-28 19:48:53 +00:00
|
|
|
|
2014-06-10 21:56:05 +00:00
|
|
|
static const char *const osd_shaders[SUBBITMAP_COUNT] = {
|
2013-03-01 20:19:20 +00:00
|
|
|
[SUBBITMAP_LIBASS] = "frag_osd_libass",
|
|
|
|
[SUBBITMAP_RGBA] = "frag_osd_rgba",
|
|
|
|
};
|
|
|
|
|
2014-12-09 20:34:01 +00:00
|
|
|
const struct gl_video_opts gl_video_opts_def = {
|
2013-03-01 20:19:20 +00:00
|
|
|
.npot = 1,
|
|
|
|
.dither_depth = -1,
|
2013-05-25 23:48:39 +00:00
|
|
|
.dither_size = 6,
|
2014-12-17 20:35:05 +00:00
|
|
|
.fbo_format = GL_RGBA,
|
2015-01-06 09:47:26 +00:00
|
|
|
.sigmoid_center = 0.75,
|
|
|
|
.sigmoid_slope = 6.5,
|
2013-03-01 20:19:20 +00:00
|
|
|
.scalers = { "bilinear", "bilinear" },
|
2014-08-25 20:36:48 +00:00
|
|
|
.scaler_params = {{NAN, NAN}, {NAN, NAN}},
|
2015-01-26 00:56:19 +00:00
|
|
|
.scaler_radius = {3, 3},
|
2015-02-06 22:23:27 +00:00
|
|
|
.alpha_mode = 2,
|
2014-12-09 20:34:01 +00:00
|
|
|
.background = {0, 0, 0, 255},
|
2015-02-03 16:12:04 +00:00
|
|
|
.gamma = 1.0f,
|
2013-03-01 20:19:20 +00:00
|
|
|
};
|
|
|
|
|
2013-10-24 20:20:16 +00:00
|
|
|
const struct gl_video_opts gl_video_opts_hq_def = {
|
|
|
|
.npot = 1,
|
|
|
|
.dither_depth = 0,
|
|
|
|
.dither_size = 6,
|
2014-02-17 10:33:37 +00:00
|
|
|
.fbo_format = GL_RGBA16,
|
2014-12-08 16:09:39 +00:00
|
|
|
.fancy_downscaling = 1,
|
2015-01-06 09:47:26 +00:00
|
|
|
.sigmoid_center = 0.75,
|
|
|
|
.sigmoid_slope = 6.5,
|
|
|
|
.sigmoid_upscaling = 1,
|
2014-04-17 19:53:42 +00:00
|
|
|
.scalers = { "spline36", "bilinear" },
|
2015-01-26 01:03:44 +00:00
|
|
|
.dscaler = "mitchell",
|
2014-08-25 20:36:48 +00:00
|
|
|
.scaler_params = {{NAN, NAN}, {NAN, NAN}},
|
2015-01-26 00:56:19 +00:00
|
|
|
.scaler_radius = {3, 3},
|
2015-02-06 22:23:27 +00:00
|
|
|
.alpha_mode = 2,
|
2014-12-09 20:34:01 +00:00
|
|
|
.background = {0, 0, 0, 255},
|
2015-02-03 16:12:04 +00:00
|
|
|
.gamma = 1.0f,
|
2013-10-24 20:20:16 +00:00
|
|
|
};
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2013-12-21 19:03:36 +00:00
|
|
|
static int validate_scaler_opt(struct mp_log *log, const m_option_t *opt,
|
|
|
|
struct bstr name, struct bstr param);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
#define OPT_BASE_STRUCT struct gl_video_opts
|
|
|
|
const struct m_sub_options gl_video_conf = {
|
2014-06-10 21:56:05 +00:00
|
|
|
.opts = (const m_option_t[]) {
|
2015-02-03 16:12:04 +00:00
|
|
|
OPT_FLOATRANGE("gamma", gamma, 0, 0.1, 2.0),
|
2013-03-01 20:19:20 +00:00
|
|
|
OPT_FLAG("srgb", srgb, 0),
|
|
|
|
OPT_FLAG("npot", npot, 0),
|
|
|
|
OPT_FLAG("pbo", pbo, 0),
|
2015-01-20 20:46:19 +00:00
|
|
|
OPT_STRING_VALIDATE("scale", scalers[0], 0, validate_scaler_opt),
|
2013-03-01 20:19:20 +00:00
|
|
|
OPT_STRING_VALIDATE("cscale", scalers[1], 0, validate_scaler_opt),
|
2015-01-20 20:46:19 +00:00
|
|
|
OPT_STRING_VALIDATE("scale-down", dscaler, 0, validate_scaler_opt),
|
|
|
|
OPT_FLOAT("scale-param1", scaler_params[0][0], 0),
|
|
|
|
OPT_FLOAT("scale-param2", scaler_params[0][1], 0),
|
|
|
|
OPT_FLOAT("cscale-param1", scaler_params[1][0], 0),
|
|
|
|
OPT_FLOAT("cscale-param2", scaler_params[1][1], 0),
|
|
|
|
OPT_FLOATRANGE("scale-radius", scaler_radius[0], 0, 1.0, 16.0),
|
|
|
|
OPT_FLOATRANGE("cscale-radius", scaler_radius[1], 0, 1.0, 16.0),
|
|
|
|
OPT_FLOATRANGE("scale-antiring", scaler_antiring[0], 0, 0.0, 1.0),
|
|
|
|
OPT_FLOATRANGE("cscale-antiring", scaler_antiring[1], 0, 0.0, 1.0),
|
2013-05-25 21:47:55 +00:00
|
|
|
OPT_FLAG("scaler-resizes-only", scaler_resizes_only, 0),
|
2015-02-06 02:37:21 +00:00
|
|
|
OPT_FLAG("linear-scaling", linear_scaling, 0),
|
2013-03-01 20:19:20 +00:00
|
|
|
OPT_FLAG("fancy-downscaling", fancy_downscaling, 0),
|
2015-01-06 09:47:26 +00:00
|
|
|
OPT_FLAG("sigmoid-upscaling", sigmoid_upscaling, 0),
|
|
|
|
OPT_FLOATRANGE("sigmoid-center", sigmoid_center, 0, 0.0, 1.0),
|
|
|
|
OPT_FLOATRANGE("sigmoid-slope", sigmoid_slope, 0, 1.0, 20.0),
|
2013-03-01 20:19:20 +00:00
|
|
|
OPT_CHOICE("fbo-format", fbo_format, 0,
|
|
|
|
({"rgb", GL_RGB},
|
|
|
|
{"rgba", GL_RGBA},
|
|
|
|
{"rgb8", GL_RGB8},
|
|
|
|
{"rgb10", GL_RGB10},
|
2013-10-23 15:46:57 +00:00
|
|
|
{"rgb10_a2", GL_RGB10_A2},
|
2013-03-01 20:19:20 +00:00
|
|
|
{"rgb16", GL_RGB16},
|
|
|
|
{"rgb16f", GL_RGB16F},
|
2013-03-28 20:44:33 +00:00
|
|
|
{"rgb32f", GL_RGB32F},
|
|
|
|
{"rgba12", GL_RGBA12},
|
|
|
|
{"rgba16", GL_RGBA16},
|
|
|
|
{"rgba16f", GL_RGBA16F},
|
|
|
|
{"rgba32f", GL_RGBA32F})),
|
2013-03-28 20:39:17 +00:00
|
|
|
OPT_CHOICE_OR_INT("dither-depth", dither_depth, 0, -1, 16,
|
|
|
|
({"no", -1}, {"auto", 0})),
|
2013-05-25 23:48:39 +00:00
|
|
|
OPT_CHOICE("dither", dither_algo, 0,
|
|
|
|
({"fruit", 0}, {"ordered", 1}, {"no", -1})),
|
|
|
|
OPT_INTRANGE("dither-size-fruit", dither_size, 0, 2, 8),
|
|
|
|
OPT_FLAG("temporal-dither", temporal_dither, 0),
|
vo_opengl: handle chroma location
Use the video decoder chroma location flags and render chroma locations
other than centered. Until now, we've always used the intuitive and
obvious centered chroma location, but H.264 uses something else.
FFmpeg provides a small overview in libavcodec/avcodec.h:
-----------
/**
* X X 3 4 X X are luma samples,
* 1 2 1-6 are possible chroma positions
* X X 5 6 X 0 is undefined/unknown position
*/
enum AVChromaLocation{
AVCHROMA_LOC_UNSPECIFIED = 0,
AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4, h264 default
AVCHROMA_LOC_CENTER = 2, ///< mpeg1, jpeg, h263
AVCHROMA_LOC_TOPLEFT = 3, ///< DV
AVCHROMA_LOC_TOP = 4,
AVCHROMA_LOC_BOTTOMLEFT = 5,
AVCHROMA_LOC_BOTTOM = 6,
AVCHROMA_LOC_NB , ///< Not part of ABI
};
-----------
The visual difference is literally minimal, but since videophiles
apparently consider this detail as quality mark of a video renderer,
support it anyway. We don't bother with chroma locations other than
centered and left, though.
Not sure about correctness, but it's probably ok.
2013-06-08 00:15:24 +00:00
|
|
|
OPT_CHOICE("chroma-location", chroma_location, 0,
|
|
|
|
({"auto", MP_CHROMA_AUTO},
|
|
|
|
{"center", MP_CHROMA_CENTER},
|
|
|
|
{"left", MP_CHROMA_LEFT})),
|
2015-02-27 17:31:24 +00:00
|
|
|
OPT_CHOICE("alpha", alpha_mode, 0,
|
2013-09-19 14:55:56 +00:00
|
|
|
({"no", 0},
|
2015-02-27 17:31:24 +00:00
|
|
|
{"yes", 1},
|
2013-09-19 14:55:56 +00:00
|
|
|
{"blend", 2})),
|
2013-12-01 22:39:13 +00:00
|
|
|
OPT_FLAG("rectangle-textures", use_rectangle, 0),
|
2014-12-09 20:34:01 +00:00
|
|
|
OPT_COLOR("background", background, 0),
|
2014-11-23 19:06:05 +00:00
|
|
|
OPT_FLAG("smoothmotion", smoothmotion, 0),
|
|
|
|
OPT_FLOAT("smoothmotion-threshold", smoothmotion_threshold,
|
|
|
|
CONF_RANGE, .min = 0, .max = 0.5),
|
2015-01-13 23:45:31 +00:00
|
|
|
OPT_REMOVED("approx-gamma", "this is always enabled now"),
|
2015-01-20 20:46:19 +00:00
|
|
|
OPT_REMOVED("cscale-down", "chroma is never downscaled"),
|
2015-01-22 17:24:50 +00:00
|
|
|
OPT_REMOVED("scale-sep", "this is set automatically whenever sane"),
|
|
|
|
OPT_REMOVED("indirect", "this is set automatically whenever sane"),
|
2015-01-20 20:46:19 +00:00
|
|
|
|
|
|
|
OPT_REPLACED("lscale", "scale"),
|
|
|
|
OPT_REPLACED("lscale-down", "scale-down"),
|
|
|
|
OPT_REPLACED("lparam1", "scale-param1"),
|
|
|
|
OPT_REPLACED("lparam2", "scale-param2"),
|
|
|
|
OPT_REPLACED("lradius", "scale-radius"),
|
|
|
|
OPT_REPLACED("lantiring", "scale-antiring"),
|
|
|
|
OPT_REPLACED("cparam1", "cscale-param1"),
|
|
|
|
OPT_REPLACED("cparam2", "cscale-param2"),
|
|
|
|
OPT_REPLACED("cradius", "cscale-radius"),
|
|
|
|
OPT_REPLACED("cantiring", "cscale-antiring"),
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.size = sizeof(struct gl_video_opts),
|
|
|
|
.defaults = &gl_video_opts_def,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void uninit_rendering(struct gl_video *p);
|
|
|
|
static void delete_shaders(struct gl_video *p);
|
|
|
|
static void check_gl_features(struct gl_video *p);
|
|
|
|
static bool init_format(int fmt, struct gl_video *init);
|
2015-01-06 09:47:26 +00:00
|
|
|
static double get_scale_factor(struct gl_video *p);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-12-16 17:55:02 +00:00
|
|
|
static const struct fmt_entry *find_tex_format(GL *gl, int bytes_per_comp,
|
|
|
|
int n_channels)
|
|
|
|
{
|
|
|
|
assert(bytes_per_comp == 1 || bytes_per_comp == 2);
|
|
|
|
assert(n_channels >= 1 && n_channels <= 4);
|
2014-12-17 20:48:23 +00:00
|
|
|
const struct fmt_entry *fmts = gl_byte_formats;
|
2014-12-19 00:03:08 +00:00
|
|
|
if (gl->es >= 300) {
|
2014-12-17 20:48:23 +00:00
|
|
|
fmts = gl_byte_formats_gles3;
|
2014-12-19 00:03:08 +00:00
|
|
|
} else if (gl->es) {
|
|
|
|
fmts = gl_byte_formats_gles2;
|
2014-12-17 20:48:23 +00:00
|
|
|
} else if (!(gl->mpgl_caps & MPGL_CAP_TEX_RG)) {
|
|
|
|
fmts = gl_byte_formats_legacy;
|
|
|
|
}
|
2014-12-16 17:55:02 +00:00
|
|
|
return &fmts[n_channels - 1 + (bytes_per_comp - 1) * 4];
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
static void debug_check_gl(struct gl_video *p, const char *msg)
|
|
|
|
{
|
|
|
|
if (p->gl_debug)
|
2013-09-11 22:57:32 +00:00
|
|
|
glCheckError(p->gl, p->log, msg);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gl_video_set_debug(struct gl_video *p, bool enable)
|
|
|
|
{
|
2014-12-23 01:46:44 +00:00
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
p->gl_debug = enable;
|
2015-01-30 10:12:58 +00:00
|
|
|
if (p->gl->debug_context)
|
|
|
|
gl_set_debug_logger(gl, enable ? p->log : NULL);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 13:02:09 +00:00
|
|
|
// Draw a textured quad.
|
2015-02-27 21:01:27 +00:00
|
|
|
// x0, y0, x1, y1 = destination coordinates of the quad in pixels
|
|
|
|
// tx0, ty0, tx1, ty1 = source texture coordinates in pixels
|
|
|
|
// tex_w, tex_h = size of the texture in pixels
|
2014-04-20 19:37:18 +00:00
|
|
|
// flags = bits 0-1: rotate, bits 2: flip vertically
|
2015-01-30 13:02:09 +00:00
|
|
|
static void draw_quad(struct gl_video *p,
|
|
|
|
float x0, float y0, float x1, float y1,
|
|
|
|
float tx0, float ty0, float tx1, float ty1,
|
|
|
|
float tex_w, float tex_h, int flags)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2015-01-30 13:02:09 +00:00
|
|
|
if (p->gl_target != GL_TEXTURE_2D)
|
|
|
|
tex_w = tex_h = 1.0f;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-04-20 19:37:18 +00:00
|
|
|
if (flags & 4) {
|
2013-03-01 20:19:20 +00:00
|
|
|
float tmp = ty0;
|
|
|
|
ty0 = ty1;
|
|
|
|
ty1 = tmp;
|
|
|
|
}
|
|
|
|
|
2015-01-30 13:02:09 +00:00
|
|
|
struct vertex va[4] = {
|
|
|
|
{ {x0, y0}, {tx0 / tex_w, ty0 / tex_h} },
|
|
|
|
{ {x0, y1}, {tx0 / tex_w, ty1 / tex_h} },
|
|
|
|
{ {x1, y0}, {tx1 / tex_w, ty0 / tex_h} },
|
|
|
|
{ {x1, y1}, {tx1 / tex_w, ty1 / tex_h} },
|
|
|
|
};
|
2015-01-29 17:29:28 +00:00
|
|
|
|
2014-04-20 19:37:18 +00:00
|
|
|
int rot = flags & 3;
|
|
|
|
while (rot--) {
|
2015-01-30 13:02:09 +00:00
|
|
|
static const int perm[4] = {1, 3, 0, 2};
|
|
|
|
struct vertex vb[4];
|
2014-04-20 19:37:18 +00:00
|
|
|
memcpy(vb, va, sizeof(vb));
|
2015-01-30 13:02:09 +00:00
|
|
|
for (int n = 0; n < 4; n++)
|
2014-04-20 19:37:18 +00:00
|
|
|
memcpy(va[n].texcoord, vb[perm[n]].texcoord, sizeof(float[2]));
|
|
|
|
}
|
2015-01-30 13:02:09 +00:00
|
|
|
|
|
|
|
gl_vao_draw_data(&p->vao, GL_TRIANGLE_STRIP, va, 4);
|
|
|
|
|
|
|
|
debug_check_gl(p, "after rendering");
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 12:48:09 +00:00
|
|
|
static void transpose3x3(float r[3][3])
|
|
|
|
{
|
|
|
|
MPSWAP(float, r[0][1], r[1][0]);
|
|
|
|
MPSWAP(float, r[0][2], r[2][0]);
|
|
|
|
MPSWAP(float, r[1][2], r[2][1]);
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
static void update_uniforms(struct gl_video *p, GLuint program)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
GLint loc;
|
|
|
|
|
|
|
|
if (program == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->UseProgram(program);
|
|
|
|
|
2015-01-06 14:21:26 +00:00
|
|
|
struct mp_csp_params cparams = MP_CSP_PARAMS_DEFAULTS;
|
2015-01-21 18:29:18 +00:00
|
|
|
cparams.gray = p->is_yuv && !p->is_packed_yuv && p->plane_count == 1;
|
2015-01-29 14:50:21 +00:00
|
|
|
cparams.input_bits = p->image_desc.component_bits;
|
2015-01-21 18:29:18 +00:00
|
|
|
cparams.texture_bits = (cparams.input_bits + 7) & ~7;
|
2015-01-06 14:21:26 +00:00
|
|
|
mp_csp_set_image_params(&cparams, &p->image_params);
|
2013-03-01 20:19:20 +00:00
|
|
|
mp_csp_copy_equalizer_values(&cparams, &p->video_eq);
|
2013-05-01 21:59:00 +00:00
|
|
|
if (p->image_desc.flags & MP_IMGFLAG_XYZ) {
|
2015-01-06 14:04:29 +00:00
|
|
|
cparams.colorspace = MP_CSP_XYZ;
|
2013-05-01 21:59:00 +00:00
|
|
|
cparams.input_bits = 8;
|
|
|
|
cparams.texture_bits = 8;
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
loc = gl->GetUniformLocation(program, "transform");
|
2014-09-14 18:35:56 +00:00
|
|
|
if (loc >= 0 && p->vp_w > 0 && p->vp_h > 0) {
|
2013-03-01 20:19:20 +00:00
|
|
|
float matrix[3][3];
|
2014-12-09 16:47:02 +00:00
|
|
|
int vvp[2] = {p->vp_h, 0};
|
|
|
|
if (p->vp_vflipped)
|
|
|
|
MPSWAP(int, vvp[0], vvp[1]);
|
2015-01-29 13:58:26 +00:00
|
|
|
gl_matrix_ortho2d(matrix, 0, p->vp_w, vvp[0], vvp[1]);
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->UniformMatrix3fv(loc, 1, GL_FALSE, &matrix[0][0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
loc = gl->GetUniformLocation(program, "colormatrix");
|
|
|
|
if (loc >= 0) {
|
2015-01-06 15:49:53 +00:00
|
|
|
struct mp_cmat m = {{{0}}};
|
2014-03-31 02:51:47 +00:00
|
|
|
if (p->image_desc.flags & MP_IMGFLAG_XYZ) {
|
2014-03-31 22:17:07 +00:00
|
|
|
// Hard-coded as relative colorimetric for now, since this transforms
|
|
|
|
// from the source file's D55 material to whatever color space our
|
|
|
|
// projector/display lives in, which should be D55 for a proper
|
|
|
|
// home cinema setup either way.
|
2015-01-06 15:49:53 +00:00
|
|
|
mp_get_xyz2rgb_coeffs(&cparams, p->csp_src,
|
|
|
|
MP_INTENT_RELATIVE_COLORIMETRIC, &m);
|
2014-03-31 02:51:47 +00:00
|
|
|
} else {
|
2015-01-06 15:49:53 +00:00
|
|
|
mp_get_yuv2rgb_coeffs(&cparams, &m);
|
2014-03-31 02:51:47 +00:00
|
|
|
}
|
2015-02-24 12:48:09 +00:00
|
|
|
transpose3x3(m.m); // GLES2 can not transpose in glUniformMatrix3fv
|
|
|
|
gl->UniformMatrix3fv(loc, 1, GL_FALSE, &m.m[0][0]);
|
2014-12-18 21:24:45 +00:00
|
|
|
loc = gl->GetUniformLocation(program, "colormatrix_c");
|
2015-01-06 15:49:53 +00:00
|
|
|
gl->Uniform3f(loc, m.c[0], m.c[1], m.c[2]);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 21:59:00 +00:00
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "input_gamma"),
|
|
|
|
p->input_gamma);
|
|
|
|
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "conv_gamma"),
|
|
|
|
p->conv_gamma);
|
|
|
|
|
2015-01-06 09:47:26 +00:00
|
|
|
// Coefficients for the sigmoidal transform are taken from the
|
|
|
|
// formula here: http://www.imagemagick.org/Usage/color_mods/#sigmoidal
|
|
|
|
float sig_center = p->opts.sigmoid_center;
|
|
|
|
float sig_slope = p->opts.sigmoid_slope;
|
|
|
|
|
|
|
|
// This function needs to go through (0,0) and (1,1) so we compute the
|
|
|
|
// values at 1 and 0, and then scale/shift them, respectively.
|
|
|
|
float sig_offset = 1.0/(1+expf(sig_slope * sig_center));
|
|
|
|
float sig_scale = 1.0/(1+expf(sig_slope * (sig_center-1))) - sig_offset;
|
|
|
|
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "sig_center"), sig_center);
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "sig_slope"), sig_slope);
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "sig_scale"), sig_scale);
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "sig_offset"), sig_offset);
|
|
|
|
|
2015-02-03 15:52:44 +00:00
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "inv_gamma"),
|
2015-02-03 16:12:04 +00:00
|
|
|
1.0f / p->user_gamma);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < p->plane_count; n++) {
|
|
|
|
char textures_n[32];
|
|
|
|
char textures_size_n[32];
|
2013-04-29 22:52:32 +00:00
|
|
|
snprintf(textures_n, sizeof(textures_n), "texture%d", n);
|
2013-03-01 20:19:20 +00:00
|
|
|
snprintf(textures_size_n, sizeof(textures_size_n), "textures_size[%d]", n);
|
|
|
|
|
|
|
|
gl->Uniform1i(gl->GetUniformLocation(program, textures_n), n);
|
2013-12-01 22:39:13 +00:00
|
|
|
if (p->gl_target == GL_TEXTURE_2D) {
|
|
|
|
gl->Uniform2f(gl->GetUniformLocation(program, textures_size_n),
|
|
|
|
p->image.planes[n].tex_w, p->image.planes[n].tex_h);
|
|
|
|
} else {
|
|
|
|
// Makes the pixel size calculation code think they are 1x1
|
|
|
|
gl->Uniform2f(gl->GetUniformLocation(program, textures_size_n), 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loc = gl->GetUniformLocation(program, "chroma_div");
|
|
|
|
if (loc >= 0) {
|
|
|
|
int xs = p->image_desc.chroma_xs;
|
|
|
|
int ys = p->image_desc.chroma_ys;
|
|
|
|
gl->Uniform2f(loc, 1.0 / (1 << xs), 1.0 / (1 << ys));
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 12:50:39 +00:00
|
|
|
gl->Uniform2f(gl->GetUniformLocation(program, "chroma_fix"),
|
|
|
|
p->chroma_fix[0], p->chroma_fix[1]);
|
vo_opengl: change the way unaligned chroma size is handled
This deals with subsampled YUV video that has odd sizes, for example a
5x5 image with 4:2:0 subsampling.
It would be easy to handle if we actually passed separate texture
coordinates for each plane to the shader, but as of now the luma
coordinates are implicitly rescaled to chroma one. If luma and chroma
sizes don't match up, and this is not handled, you'd get a chroma shift
by 1 pixel.
The existing hack worked, but broke separable scaling. This was exposed
by a recent commit which switched to GL_NEAREST sampling for FBOs. The
rendering was accidentally scaled by 1 pixel, because the FBO size used
the original video size, while textures_sizes[0] was set to the padded
texture size (i.e. one pixel larger).
It could be fixed by setting the padded texture size only on the first
shader. But somehow that is annoying, so do something else. Don't pad
textures anymore, and rescale the chroma coordinates in the shader
instead.
Seems like this somehow doesn't work with rectangle textures (and
introduces a chroma shift), but since it's only used when doing VDA
hardware decoding, and the bug occurs only with unaligned video sizes, I
don't care much.
Fixes #1523.
2015-01-27 17:08:42 +00:00
|
|
|
|
vo_opengl: handle chroma location
Use the video decoder chroma location flags and render chroma locations
other than centered. Until now, we've always used the intuitive and
obvious centered chroma location, but H.264 uses something else.
FFmpeg provides a small overview in libavcodec/avcodec.h:
-----------
/**
* X X 3 4 X X are luma samples,
* 1 2 1-6 are possible chroma positions
* X X 5 6 X 0 is undefined/unknown position
*/
enum AVChromaLocation{
AVCHROMA_LOC_UNSPECIFIED = 0,
AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4, h264 default
AVCHROMA_LOC_CENTER = 2, ///< mpeg1, jpeg, h263
AVCHROMA_LOC_TOPLEFT = 3, ///< DV
AVCHROMA_LOC_TOP = 4,
AVCHROMA_LOC_BOTTOMLEFT = 5,
AVCHROMA_LOC_BOTTOM = 6,
AVCHROMA_LOC_NB , ///< Not part of ABI
};
-----------
The visual difference is literally minimal, but since videophiles
apparently consider this detail as quality mark of a video renderer,
support it anyway. We don't bother with chroma locations other than
centered and left, though.
Not sure about correctness, but it's probably ok.
2013-06-08 00:15:24 +00:00
|
|
|
loc = gl->GetUniformLocation(program, "chroma_center_offset");
|
|
|
|
if (loc >= 0) {
|
|
|
|
int chr = p->opts.chroma_location;
|
|
|
|
if (!chr)
|
2013-07-25 22:26:04 +00:00
|
|
|
chr = p->image_params.chroma_location;
|
vo_opengl: handle chroma location
Use the video decoder chroma location flags and render chroma locations
other than centered. Until now, we've always used the intuitive and
obvious centered chroma location, but H.264 uses something else.
FFmpeg provides a small overview in libavcodec/avcodec.h:
-----------
/**
* X X 3 4 X X are luma samples,
* 1 2 1-6 are possible chroma positions
* X X 5 6 X 0 is undefined/unknown position
*/
enum AVChromaLocation{
AVCHROMA_LOC_UNSPECIFIED = 0,
AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4, h264 default
AVCHROMA_LOC_CENTER = 2, ///< mpeg1, jpeg, h263
AVCHROMA_LOC_TOPLEFT = 3, ///< DV
AVCHROMA_LOC_TOP = 4,
AVCHROMA_LOC_BOTTOMLEFT = 5,
AVCHROMA_LOC_BOTTOM = 6,
AVCHROMA_LOC_NB , ///< Not part of ABI
};
-----------
The visual difference is literally minimal, but since videophiles
apparently consider this detail as quality mark of a video renderer,
support it anyway. We don't bother with chroma locations other than
centered and left, though.
Not sure about correctness, but it's probably ok.
2013-06-08 00:15:24 +00:00
|
|
|
int cx, cy;
|
|
|
|
mp_get_chroma_location(chr, &cx, &cy);
|
|
|
|
// By default texture coordinates are such that chroma is centered with
|
|
|
|
// any chroma subsampling. If a specific direction is given, make it
|
|
|
|
// so that the luma and chroma sample line up exactly.
|
|
|
|
// For 4:4:4, setting chroma location should have no effect at all.
|
|
|
|
// luma sample size (in chroma coord. space)
|
|
|
|
float ls_w = 1.0 / (1 << p->image_desc.chroma_xs);
|
|
|
|
float ls_h = 1.0 / (1 << p->image_desc.chroma_ys);
|
|
|
|
// move chroma center to luma center (in chroma coord. space)
|
|
|
|
float o_x = ls_w < 1 ? ls_w * -cx / 2 : 0;
|
|
|
|
float o_y = ls_h < 1 ? ls_h * -cy / 2 : 0;
|
2013-12-01 22:39:13 +00:00
|
|
|
int c = p->gl_target == GL_TEXTURE_2D ? 1 : 0;
|
|
|
|
gl->Uniform2f(loc, o_x / FFMAX(p->image.planes[1].w * c, 1),
|
|
|
|
o_y / FFMAX(p->image.planes[1].h * c, 1));
|
vo_opengl: handle chroma location
Use the video decoder chroma location flags and render chroma locations
other than centered. Until now, we've always used the intuitive and
obvious centered chroma location, but H.264 uses something else.
FFmpeg provides a small overview in libavcodec/avcodec.h:
-----------
/**
* X X 3 4 X X are luma samples,
* 1 2 1-6 are possible chroma positions
* X X 5 6 X 0 is undefined/unknown position
*/
enum AVChromaLocation{
AVCHROMA_LOC_UNSPECIFIED = 0,
AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4, h264 default
AVCHROMA_LOC_CENTER = 2, ///< mpeg1, jpeg, h263
AVCHROMA_LOC_TOPLEFT = 3, ///< DV
AVCHROMA_LOC_TOP = 4,
AVCHROMA_LOC_BOTTOMLEFT = 5,
AVCHROMA_LOC_BOTTOM = 6,
AVCHROMA_LOC_NB , ///< Not part of ABI
};
-----------
The visual difference is literally minimal, but since videophiles
apparently consider this detail as quality mark of a video renderer,
support it anyway. We don't bother with chroma locations other than
centered and left, though.
Not sure about correctness, but it's probably ok.
2013-06-08 00:15:24 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->Uniform2f(gl->GetUniformLocation(program, "dither_size"),
|
|
|
|
p->dither_size, p->dither_size);
|
|
|
|
|
|
|
|
gl->Uniform1i(gl->GetUniformLocation(program, "lut_3d"), TEXUNIT_3DLUT);
|
|
|
|
|
2014-03-26 00:46:38 +00:00
|
|
|
loc = gl->GetUniformLocation(program, "cms_matrix");
|
|
|
|
if (loc >= 0) {
|
|
|
|
float cms_matrix[3][3] = {{0}};
|
2014-03-31 22:17:07 +00:00
|
|
|
// Hard-coded to relative colorimetric - for a BT.2020 3DLUT we expect
|
|
|
|
// the input to be actual BT.2020 and not something red- or blueshifted,
|
|
|
|
// and for sRGB monitors we most likely want relative scaling either way.
|
|
|
|
mp_get_cms_matrix(p->csp_src, p->csp_dest, MP_INTENT_RELATIVE_COLORIMETRIC, cms_matrix);
|
2014-03-26 00:46:38 +00:00
|
|
|
gl->UniformMatrix3fv(loc, 1, GL_TRUE, &cms_matrix[0][0]);
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
for (int n = 0; n < 2; n++) {
|
|
|
|
const char *lut = p->scalers[n].lut_name;
|
|
|
|
if (lut)
|
|
|
|
gl->Uniform1i(gl->GetUniformLocation(program, lut),
|
|
|
|
TEXUNIT_SCALERS + n);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->Uniform1i(gl->GetUniformLocation(program, "dither"), TEXUNIT_DITHER);
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "dither_quantization"),
|
|
|
|
p->dither_quantization);
|
2013-05-30 11:36:11 +00:00
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "dither_center"),
|
|
|
|
p->dither_center);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-08-25 20:36:48 +00:00
|
|
|
float sparam1_l = p->opts.scaler_params[0][0];
|
|
|
|
float sparam1_c = p->opts.scaler_params[1][0];
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "filter_param1_l"),
|
|
|
|
isnan(sparam1_l) ? 0.5f : sparam1_l);
|
|
|
|
gl->Uniform1f(gl->GetUniformLocation(program, "filter_param1_c"),
|
|
|
|
isnan(sparam1_c) ? 0.5f : sparam1_c);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-10-29 22:14:46 +00:00
|
|
|
gl->Uniform3f(gl->GetUniformLocation(program, "translation"), 0, 0, 0);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->UseProgram(0);
|
|
|
|
|
|
|
|
debug_check_gl(p, "update_uniforms()");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_all_uniforms(struct gl_video *p)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < SUBBITMAP_COUNT; n++)
|
2015-01-29 17:29:28 +00:00
|
|
|
update_uniforms(p, p->osd->programs[n]);
|
2013-03-01 20:19:20 +00:00
|
|
|
update_uniforms(p, p->indirect_program);
|
|
|
|
update_uniforms(p, p->scale_sep_program);
|
|
|
|
update_uniforms(p, p->final_program);
|
2014-11-23 19:06:05 +00:00
|
|
|
update_uniforms(p, p->inter_program);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SECTION_HEADER "#!section "
|
|
|
|
|
|
|
|
static char *get_section(void *talloc_ctx, struct bstr source,
|
|
|
|
const char *section)
|
|
|
|
{
|
|
|
|
char *res = talloc_strdup(talloc_ctx, "");
|
|
|
|
bool copy = false;
|
|
|
|
while (source.len) {
|
|
|
|
struct bstr line = bstr_strip_linebreaks(bstr_getline(source, &source));
|
|
|
|
if (bstr_eatstart(&line, bstr0(SECTION_HEADER))) {
|
|
|
|
copy = bstrcmp0(line, section) == 0;
|
|
|
|
} else if (copy) {
|
|
|
|
res = talloc_asprintf_append_buffer(res, "%.*s\n", BSTR_P(line));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *t_concat(void *talloc_ctx, const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
return talloc_asprintf(talloc_ctx, "%s%s", s1, s2);
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
static GLuint create_shader(struct gl_video *p, GLenum type, const char *header,
|
2013-03-01 20:19:20 +00:00
|
|
|
const char *source)
|
|
|
|
{
|
2013-07-31 19:44:21 +00:00
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
void *tmp = talloc_new(NULL);
|
|
|
|
const char *full_source = t_concat(tmp, header, source);
|
|
|
|
|
|
|
|
GLuint shader = gl->CreateShader(type);
|
|
|
|
gl->ShaderSource(shader, 1, &full_source, NULL);
|
|
|
|
gl->CompileShader(shader);
|
|
|
|
GLint status;
|
|
|
|
gl->GetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
|
|
|
GLint log_length;
|
|
|
|
gl->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
|
|
|
|
|
2013-12-21 20:41:18 +00:00
|
|
|
int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DEBUG) : MSGL_ERR;
|
2013-03-01 20:19:20 +00:00
|
|
|
const char *typestr = type == GL_VERTEX_SHADER ? "vertex" : "fragment";
|
2013-12-21 20:49:13 +00:00
|
|
|
if (mp_msg_test(p->log, pri)) {
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_MSG(p, pri, "%s shader source:\n", typestr);
|
|
|
|
mp_log_source(p->log, pri, full_source);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
if (log_length > 1) {
|
2013-07-31 19:44:21 +00:00
|
|
|
GLchar *logstr = talloc_zero_size(tmp, log_length + 1);
|
|
|
|
gl->GetShaderInfoLog(shader, log_length, NULL, logstr);
|
|
|
|
MP_MSG(p, pri, "%s shader compile log (status=%d):\n%s\n",
|
|
|
|
typestr, status, logstr);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
talloc_free(tmp);
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
static void prog_create_shader(struct gl_video *p, GLuint program, GLenum type,
|
|
|
|
const char *header, const char *source)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2013-07-31 19:44:21 +00:00
|
|
|
GL *gl = p->gl;
|
|
|
|
GLuint shader = create_shader(p, type, header, source);
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->AttachShader(program, shader);
|
|
|
|
gl->DeleteShader(shader);
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
static void link_shader(struct gl_video *p, GLuint program)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2013-07-31 19:44:21 +00:00
|
|
|
GL *gl = p->gl;
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->LinkProgram(program);
|
|
|
|
GLint status;
|
|
|
|
gl->GetProgramiv(program, GL_LINK_STATUS, &status);
|
|
|
|
GLint log_length;
|
|
|
|
gl->GetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length);
|
|
|
|
|
2013-12-21 20:41:18 +00:00
|
|
|
int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DEBUG) : MSGL_ERR;
|
2013-12-21 20:49:13 +00:00
|
|
|
if (mp_msg_test(p->log, pri)) {
|
2013-07-31 19:44:21 +00:00
|
|
|
GLchar *logstr = talloc_zero_size(NULL, log_length + 1);
|
|
|
|
gl->GetProgramInfoLog(program, log_length, NULL, logstr);
|
|
|
|
MP_MSG(p, pri, "shader link log (status=%d): %s\n", status, logstr);
|
|
|
|
talloc_free(logstr);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:58:32 +00:00
|
|
|
#define PRELUDE_END "// -- prelude end\n"
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
static GLuint create_program(struct gl_video *p, const char *name,
|
|
|
|
const char *header, const char *vertex,
|
2015-01-29 17:29:28 +00:00
|
|
|
const char *frag, struct gl_vao *vao)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2013-07-31 19:44:21 +00:00
|
|
|
GL *gl = p->gl;
|
|
|
|
MP_VERBOSE(p, "compiling shader program '%s', header:\n", name);
|
2013-06-01 17:58:32 +00:00
|
|
|
const char *real_header = strstr(header, PRELUDE_END);
|
|
|
|
real_header = real_header ? real_header + strlen(PRELUDE_END) : header;
|
2013-07-31 19:44:21 +00:00
|
|
|
mp_log_source(p->log, MSGL_V, real_header);
|
2013-03-01 20:19:20 +00:00
|
|
|
GLuint prog = gl->CreateProgram();
|
2013-07-31 19:44:21 +00:00
|
|
|
prog_create_shader(p, prog, GL_VERTEX_SHADER, header, vertex);
|
|
|
|
prog_create_shader(p, prog, GL_FRAGMENT_SHADER, header, frag);
|
2015-01-29 17:29:28 +00:00
|
|
|
gl_vao_bind_attribs(vao, prog);
|
2013-07-31 19:44:21 +00:00
|
|
|
link_shader(p, prog);
|
2013-03-01 20:19:20 +00:00
|
|
|
return prog;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_def(char **shader, const char *name,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
*shader = talloc_asprintf_append(*shader, "#define %s %s\n", name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_def_opt(char **shader, const char *name, bool b)
|
|
|
|
{
|
|
|
|
if (b)
|
|
|
|
shader_def(shader, name, "1");
|
|
|
|
}
|
|
|
|
|
2014-12-08 15:04:08 +00:00
|
|
|
#define APPENDF(s_ptr, ...) \
|
|
|
|
*(s_ptr) = talloc_asprintf_append(*(s_ptr), __VA_ARGS__)
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
static void shader_setup_scaler(char **shader, struct scaler *scaler, int pass)
|
|
|
|
{
|
2014-12-08 15:04:08 +00:00
|
|
|
int unit = scaler->index;
|
2015-01-20 20:46:19 +00:00
|
|
|
const char *target = unit == 0 ? "SAMPLE" : "SAMPLE_C";
|
2013-03-01 20:19:20 +00:00
|
|
|
if (!scaler->kernel) {
|
2014-12-08 15:04:08 +00:00
|
|
|
APPENDF(shader, "#define %s(p0, p1, p2) "
|
|
|
|
"sample_%s(p0, p1, p2, filter_param1_%c)\n",
|
|
|
|
target, scaler->name, "lc"[unit]);
|
2013-03-01 20:19:20 +00:00
|
|
|
} else {
|
|
|
|
int size = scaler->kernel->size;
|
2014-12-08 15:04:08 +00:00
|
|
|
const char *lut_tex = scaler->lut_name;
|
|
|
|
char name[40];
|
|
|
|
snprintf(name, sizeof(name), "sample_scaler%d", unit);
|
2014-12-09 21:30:49 +00:00
|
|
|
APPENDF(shader, "#define DEF_SCALER%d \\\n ", unit);
|
2014-12-08 15:04:08 +00:00
|
|
|
char lut_fn[40];
|
2015-01-04 22:11:27 +00:00
|
|
|
if (scaler->kernel->polar) {
|
2015-02-23 22:52:01 +00:00
|
|
|
double radius = scaler->kernel->radius;
|
|
|
|
int bound = (int)ceil(radius);
|
2015-01-18 17:57:12 +00:00
|
|
|
// SAMPLE_CONVOLUTION_POLAR_R(NAME, R, LUT, WEIGHTS_FN, ANTIRING)
|
2015-02-23 22:52:01 +00:00
|
|
|
APPENDF(shader, "SAMPLE_CONVOLUTION_POLAR_R(%s, %f, %s, WEIGHTS%d, %f)\n",
|
2015-01-18 17:57:12 +00:00
|
|
|
name, radius, lut_tex, unit, scaler->antiring);
|
2015-01-18 16:41:49 +00:00
|
|
|
|
|
|
|
// Pre-compute unrolled weights matrix
|
|
|
|
APPENDF(shader, "#define WEIGHTS%d(LUT) \\\n ", unit);
|
2015-02-23 22:52:01 +00:00
|
|
|
for (int y = 1-bound; y <= bound; y++) {
|
|
|
|
for (int x = 1-bound; x <= bound; x++) {
|
2015-01-18 16:41:49 +00:00
|
|
|
// Since we can't know the subpixel position in advance,
|
|
|
|
// assume a worst case scenario.
|
|
|
|
int yy = y > 0 ? y-1 : y;
|
|
|
|
int xx = x > 0 ? x-1 : x;
|
|
|
|
double d = sqrt(xx*xx + yy*yy);
|
|
|
|
|
2015-02-23 21:41:13 +00:00
|
|
|
if (d < radius - 1) {
|
|
|
|
// Samples definitely inside the main ring
|
2015-01-18 17:57:12 +00:00
|
|
|
APPENDF(shader, "SAMPLE_POLAR_%s(LUT, %f, %d, %d) \\\n ",
|
|
|
|
// The center 4 coefficients are the primary
|
|
|
|
// contributors, used to clamp the result for
|
|
|
|
// anti-ringing
|
|
|
|
(x >= 0 && y >= 0 && x <= 1 && y <= 1)
|
|
|
|
? "PRIMARY" : "HELPER",
|
2015-02-23 22:52:01 +00:00
|
|
|
radius, x, y);
|
2015-02-23 21:41:13 +00:00
|
|
|
} else if (d < radius) {
|
|
|
|
// Samples on the edge, these are potential values
|
|
|
|
APPENDF(shader, "SAMPLE_POLAR_POTENTIAL(LUT, %f, %d, %d) \\\n ",
|
2015-02-23 22:52:01 +00:00
|
|
|
radius, x, y);
|
2015-01-18 16:41:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
APPENDF(shader, "\n");
|
2014-12-08 15:04:08 +00:00
|
|
|
} else {
|
2015-01-04 22:11:27 +00:00
|
|
|
if (size == 2 || size == 6) {
|
|
|
|
snprintf(lut_fn, sizeof(lut_fn), "weights%d", size);
|
|
|
|
} else {
|
|
|
|
snprintf(lut_fn, sizeof(lut_fn), "weights_scaler%d", unit);
|
|
|
|
APPENDF(shader, "WEIGHTS_N(%s, %d) \\\n ", lut_fn, size);
|
|
|
|
}
|
|
|
|
if (pass != -1) {
|
|
|
|
// The direction/pass assignment is rather arbitrary, but fixed in
|
|
|
|
// other parts of the code (like FBO setup).
|
|
|
|
const char *direction = pass == 0 ? "0, 1" : "1, 0";
|
2015-02-27 03:32:22 +00:00
|
|
|
// SAMPLE_CONVOLUTION_SEP_N(NAME, DIR, N, LUT, WEIGHTS_FUNC, ANTIRING)
|
|
|
|
APPENDF(shader, "SAMPLE_CONVOLUTION_SEP_N(%s, vec2(%s), %d, %s, %s, %f)\n",
|
|
|
|
name, direction, size, lut_tex, lut_fn, scaler->antiring);
|
2015-01-04 22:11:27 +00:00
|
|
|
} else {
|
|
|
|
// SAMPLE_CONVOLUTION_N(NAME, N, LUT, WEIGHTS_FUNC)
|
|
|
|
APPENDF(shader, "SAMPLE_CONVOLUTION_N(%s, %d, %s, %s)\n",
|
|
|
|
name, size, lut_tex, lut_fn);
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
2014-12-08 15:04:08 +00:00
|
|
|
APPENDF(shader, "#define %s %s\n", target, name);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return false if RGB or 4:4:4 YUV
|
|
|
|
static bool input_is_subsampled(struct gl_video *p)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < p->plane_count; i++)
|
2013-03-28 19:40:19 +00:00
|
|
|
if (p->image_desc.xs[i] || p->image_desc.ys[i])
|
2013-03-01 20:19:20 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void compile_shaders(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2014-12-17 20:48:23 +00:00
|
|
|
debug_check_gl(p, "before shaders");
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
delete_shaders(p);
|
|
|
|
|
|
|
|
void *tmp = talloc_new(NULL);
|
|
|
|
|
|
|
|
struct bstr src = bstr0(vo_opengl_shaders);
|
|
|
|
char *vertex_shader = get_section(tmp, src, "vertex_all");
|
|
|
|
char *shader_prelude = get_section(tmp, src, "prelude");
|
|
|
|
char *s_video = get_section(tmp, src, "frag_video");
|
|
|
|
|
2014-12-21 20:54:50 +00:00
|
|
|
bool rg = gl->mpgl_caps & MPGL_CAP_TEX_RG;
|
2015-01-17 16:28:47 +00:00
|
|
|
bool tex1d = gl->mpgl_caps & MPGL_CAP_1D_TEX;
|
2014-12-21 20:54:50 +00:00
|
|
|
bool tex3d = gl->mpgl_caps & MPGL_CAP_3D_TEX;
|
|
|
|
bool arrays = gl->mpgl_caps & MPGL_CAP_1ST_CLASS_ARRAYS;
|
2014-12-16 17:55:02 +00:00
|
|
|
char *header =
|
2014-12-17 20:48:23 +00:00
|
|
|
talloc_asprintf(tmp, "#version %d%s\n"
|
2014-12-16 17:55:02 +00:00
|
|
|
"#define HAVE_RG %d\n"
|
2015-01-17 16:28:47 +00:00
|
|
|
"#define HAVE_1DTEX %d\n"
|
2014-12-21 20:54:50 +00:00
|
|
|
"#define HAVE_3DTEX %d\n"
|
|
|
|
"#define HAVE_ARRAYS %d\n"
|
2014-12-16 17:55:02 +00:00
|
|
|
"%s%s",
|
2014-12-19 00:03:08 +00:00
|
|
|
gl->glsl_version, gl->es >= 300 ? " es" : "",
|
2015-01-17 16:28:47 +00:00
|
|
|
rg, tex1d, tex3d, arrays, shader_prelude, PRELUDE_END);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-03-26 00:46:38 +00:00
|
|
|
bool use_cms = p->opts.srgb || p->use_lut_3d;
|
2015-02-06 02:37:21 +00:00
|
|
|
// 3DLUT overrides sRGB
|
|
|
|
bool use_srgb = p->opts.srgb && !p->use_lut_3d;
|
2014-06-22 06:33:43 +00:00
|
|
|
|
|
|
|
float input_gamma = 1.0;
|
|
|
|
float conv_gamma = 1.0;
|
|
|
|
|
2015-01-28 17:52:33 +00:00
|
|
|
bool is_xyz = p->image_desc.flags & MP_IMGFLAG_XYZ;
|
|
|
|
if (is_xyz) {
|
2014-06-22 06:33:43 +00:00
|
|
|
input_gamma *= 2.6;
|
2015-02-06 02:37:21 +00:00
|
|
|
// Note that this results in linear light, so we make sure to enable
|
|
|
|
// use_linear_light for XYZ inputs as well.
|
2014-06-22 06:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->input_gamma = input_gamma;
|
|
|
|
p->conv_gamma = conv_gamma;
|
|
|
|
|
|
|
|
bool use_input_gamma = p->input_gamma != 1.0;
|
|
|
|
bool use_conv_gamma = p->conv_gamma != 1.0;
|
|
|
|
bool use_const_luma = p->image_params.colorspace == MP_CSP_BT_2020_C;
|
Revert "Revert recent vo_opengl related commits"
Omitted a simple, but devastasting check. Fixed the relevant commits
now.
This reverts commit 8d24e9d9b8ad1b5d82139980eca148dc0f4a1eab.
diff --git a/video/out/gl_video.c b/video/out/gl_video.c
index 9c8a643..f1ea03e 100644
--- a/video/out/gl_video.c
+++ b/video/out/gl_video.c
@@ -1034,9 +1034,9 @@ static void compile_shaders(struct gl_video *p)
shader_def_opt(&header_conv, "USE_CONV_GAMMA", use_conv_gamma);
shader_def_opt(&header_conv, "USE_CONST_LUMA", use_const_luma);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_BT1886",
- gamma_fun == MP_CSP_TRC_BT_1886);
+ use_linear_light && gamma_fun == MP_CSP_TRC_BT_1886);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_SRGB",
- gamma_fun == MP_CSP_TRC_SRGB);
+ use_linear_light && gamma_fun == MP_CSP_TRC_SRGB);
shader_def_opt(&header_conv, "USE_SIGMOID", use_sigmoid);
if (p->opts.alpha_mode > 0 && p->has_alpha && p->plane_count > 3)
shader_def(&header_conv, "USE_ALPHA_PLANE", "3");
2015-02-28 19:15:12 +00:00
|
|
|
enum mp_csp_trc gamma_fun = p->image_params.gamma;
|
2014-11-26 20:35:08 +00:00
|
|
|
|
2015-02-06 02:37:21 +00:00
|
|
|
// If either color correction option (3dlut or srgb) is enabled, or if
|
|
|
|
// sigmoidal upscaling is requested, or if the source is linear XYZ, we
|
|
|
|
// always scale in linear light
|
|
|
|
bool use_linear_light = p->opts.linear_scaling || p->opts.sigmoid_upscaling
|
|
|
|
|| use_cms || is_xyz;
|
|
|
|
|
|
|
|
// The inverse of the above transformation is normally handled by
|
|
|
|
// the CMS cases, but if CMS is disabled we need to go back manually
|
|
|
|
bool use_inv_bt1886 = false;
|
|
|
|
if (use_linear_light && !use_cms) {
|
|
|
|
if (gamma_fun == MP_CSP_TRC_SRGB) {
|
|
|
|
use_srgb = true;
|
|
|
|
} else {
|
|
|
|
use_inv_bt1886 = true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-06 09:47:26 +00:00
|
|
|
|
2015-02-06 02:37:21 +00:00
|
|
|
// Optionally transform to sigmoidal color space if requested.
|
|
|
|
p->sigmoid_enabled = p->opts.sigmoid_upscaling;
|
2015-02-03 16:39:30 +00:00
|
|
|
bool use_sigmoid = p->sigmoid_enabled && p->upscaling;
|
2015-01-06 09:47:26 +00:00
|
|
|
|
2014-06-22 06:33:43 +00:00
|
|
|
// Figure out the right color spaces we need to convert, if any
|
2014-03-31 02:51:47 +00:00
|
|
|
enum mp_csp_prim prim_src = p->image_params.primaries, prim_dest;
|
|
|
|
if (use_cms) {
|
|
|
|
// sRGB mode wants sRGB aka BT.709 primaries, but the 3DLUT is
|
|
|
|
// always built against BT.2020.
|
|
|
|
prim_dest = p->opts.srgb ? MP_CSP_PRIM_BT_709 : MP_CSP_PRIM_BT_2020;
|
|
|
|
} else {
|
|
|
|
// If no CMS is being done we just want to output stuff as-is,
|
|
|
|
// in the native colorspace of the source.
|
|
|
|
prim_dest = prim_src;
|
2014-06-22 06:33:43 +00:00
|
|
|
}
|
2014-03-26 00:46:38 +00:00
|
|
|
|
2014-03-31 02:51:47 +00:00
|
|
|
// XYZ input has no defined input color space, so we can directly convert
|
|
|
|
// it to whatever output space we actually need.
|
|
|
|
if (p->image_desc.flags & MP_IMGFLAG_XYZ)
|
|
|
|
prim_src = prim_dest;
|
|
|
|
|
|
|
|
// Set the colorspace primaries and figure out whether we need to perform
|
|
|
|
// an extra conversion.
|
|
|
|
p->csp_src = mp_get_csp_primaries(prim_src);
|
|
|
|
p->csp_dest = mp_get_csp_primaries(prim_dest);
|
|
|
|
|
|
|
|
bool use_cms_matrix = prim_src != prim_dest;
|
|
|
|
|
2013-12-01 22:39:13 +00:00
|
|
|
if (p->gl_target == GL_TEXTURE_RECTANGLE) {
|
|
|
|
shader_def(&header, "VIDEO_SAMPLER", "sampler2DRect");
|
|
|
|
shader_def_opt(&header, "USE_RECTANGLE", true);
|
|
|
|
} else {
|
|
|
|
shader_def(&header, "VIDEO_SAMPLER", "sampler2D");
|
|
|
|
}
|
|
|
|
|
2013-03-28 20:44:27 +00:00
|
|
|
// Need to pass alpha through the whole chain. (Not needed for OSD shaders.)
|
2013-09-19 14:55:56 +00:00
|
|
|
if (p->opts.alpha_mode == 1)
|
|
|
|
shader_def_opt(&header, "USE_ALPHA", p->has_alpha);
|
2013-03-28 20:44:27 +00:00
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
char *header_osd = talloc_strdup(tmp, header);
|
2015-01-13 23:45:31 +00:00
|
|
|
shader_def_opt(&header_osd, "USE_OSD_LINEAR_CONV_BT1886",
|
|
|
|
use_cms && gamma_fun == MP_CSP_TRC_BT_1886);
|
2014-11-26 20:35:08 +00:00
|
|
|
shader_def_opt(&header_osd, "USE_OSD_LINEAR_CONV_SRGB",
|
|
|
|
use_cms && gamma_fun == MP_CSP_TRC_SRGB);
|
2014-03-26 00:46:38 +00:00
|
|
|
shader_def_opt(&header_osd, "USE_OSD_CMS_MATRIX", use_cms_matrix);
|
2013-03-01 20:19:20 +00:00
|
|
|
shader_def_opt(&header_osd, "USE_OSD_3DLUT", p->use_lut_3d);
|
2015-02-06 02:37:21 +00:00
|
|
|
shader_def_opt(&header_osd, "USE_OSD_SRGB", use_cms && use_srgb);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < SUBBITMAP_COUNT; n++) {
|
|
|
|
const char *name = osd_shaders[n];
|
|
|
|
if (name) {
|
|
|
|
char *s_osd = get_section(tmp, src, name);
|
2015-01-29 17:29:28 +00:00
|
|
|
p->osd_programs[n] = create_program(p, name, header_osd,
|
|
|
|
vertex_shader, s_osd,
|
|
|
|
&p->osd->vao);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-29 17:29:28 +00:00
|
|
|
struct gl_vao *v = &p->vao; // VAO to use to draw primitives
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
char *header_conv = talloc_strdup(tmp, "");
|
|
|
|
char *header_final = talloc_strdup(tmp, "");
|
2014-11-23 19:06:05 +00:00
|
|
|
char *header_inter = talloc_strdup(tmp, "");
|
2013-03-01 20:19:20 +00:00
|
|
|
char *header_sep = NULL;
|
|
|
|
|
2014-10-16 21:44:10 +00:00
|
|
|
if (p->image_desc.id == IMGFMT_NV12 || p->image_desc.id == IMGFMT_NV21) {
|
2013-03-28 20:02:41 +00:00
|
|
|
shader_def(&header_conv, "USE_CONV", "CONV_NV12");
|
|
|
|
} else if (p->plane_count > 1) {
|
|
|
|
shader_def(&header_conv, "USE_CONV", "CONV_PLANAR");
|
|
|
|
}
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
if (p->color_swizzle[0])
|
|
|
|
shader_def(&header_conv, "USE_COLOR_SWIZZLE", p->color_swizzle);
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_INPUT_GAMMA", use_input_gamma);
|
2013-05-01 21:59:00 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_COLORMATRIX", !p->is_rgb);
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_CONV_GAMMA", use_conv_gamma);
|
2014-03-26 22:00:09 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_CONST_LUMA", use_const_luma);
|
2015-01-13 23:45:31 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_BT1886",
|
Revert "Revert recent vo_opengl related commits"
Omitted a simple, but devastasting check. Fixed the relevant commits
now.
This reverts commit 8d24e9d9b8ad1b5d82139980eca148dc0f4a1eab.
diff --git a/video/out/gl_video.c b/video/out/gl_video.c
index 9c8a643..f1ea03e 100644
--- a/video/out/gl_video.c
+++ b/video/out/gl_video.c
@@ -1034,9 +1034,9 @@ static void compile_shaders(struct gl_video *p)
shader_def_opt(&header_conv, "USE_CONV_GAMMA", use_conv_gamma);
shader_def_opt(&header_conv, "USE_CONST_LUMA", use_const_luma);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_BT1886",
- gamma_fun == MP_CSP_TRC_BT_1886);
+ use_linear_light && gamma_fun == MP_CSP_TRC_BT_1886);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_SRGB",
- gamma_fun == MP_CSP_TRC_SRGB);
+ use_linear_light && gamma_fun == MP_CSP_TRC_SRGB);
shader_def_opt(&header_conv, "USE_SIGMOID", use_sigmoid);
if (p->opts.alpha_mode > 0 && p->has_alpha && p->plane_count > 3)
shader_def(&header_conv, "USE_ALPHA_PLANE", "3");
2015-02-28 19:15:12 +00:00
|
|
|
use_linear_light && gamma_fun == MP_CSP_TRC_BT_1886);
|
2014-11-26 20:35:08 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_SRGB",
|
Revert "Revert recent vo_opengl related commits"
Omitted a simple, but devastasting check. Fixed the relevant commits
now.
This reverts commit 8d24e9d9b8ad1b5d82139980eca148dc0f4a1eab.
diff --git a/video/out/gl_video.c b/video/out/gl_video.c
index 9c8a643..f1ea03e 100644
--- a/video/out/gl_video.c
+++ b/video/out/gl_video.c
@@ -1034,9 +1034,9 @@ static void compile_shaders(struct gl_video *p)
shader_def_opt(&header_conv, "USE_CONV_GAMMA", use_conv_gamma);
shader_def_opt(&header_conv, "USE_CONST_LUMA", use_const_luma);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_BT1886",
- gamma_fun == MP_CSP_TRC_BT_1886);
+ use_linear_light && gamma_fun == MP_CSP_TRC_BT_1886);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_SRGB",
- gamma_fun == MP_CSP_TRC_SRGB);
+ use_linear_light && gamma_fun == MP_CSP_TRC_SRGB);
shader_def_opt(&header_conv, "USE_SIGMOID", use_sigmoid);
if (p->opts.alpha_mode > 0 && p->has_alpha && p->plane_count > 3)
shader_def(&header_conv, "USE_ALPHA_PLANE", "3");
2015-02-28 19:15:12 +00:00
|
|
|
use_linear_light && gamma_fun == MP_CSP_TRC_SRGB);
|
2015-01-06 09:47:26 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_SIGMOID", use_sigmoid);
|
2013-09-19 14:55:56 +00:00
|
|
|
if (p->opts.alpha_mode > 0 && p->has_alpha && p->plane_count > 3)
|
2013-03-28 20:44:27 +00:00
|
|
|
shader_def(&header_conv, "USE_ALPHA_PLANE", "3");
|
2013-09-19 14:55:56 +00:00
|
|
|
if (p->opts.alpha_mode == 2 && p->has_alpha)
|
|
|
|
shader_def(&header_conv, "USE_ALPHA_BLEND", "1");
|
vo_opengl: change the way unaligned chroma size is handled
This deals with subsampled YUV video that has odd sizes, for example a
5x5 image with 4:2:0 subsampling.
It would be easy to handle if we actually passed separate texture
coordinates for each plane to the shader, but as of now the luma
coordinates are implicitly rescaled to chroma one. If luma and chroma
sizes don't match up, and this is not handled, you'd get a chroma shift
by 1 pixel.
The existing hack worked, but broke separable scaling. This was exposed
by a recent commit which switched to GL_NEAREST sampling for FBOs. The
rendering was accidentally scaled by 1 pixel, because the FBO size used
the original video size, while textures_sizes[0] was set to the padded
texture size (i.e. one pixel larger).
It could be fixed by setting the padded texture size only on the first
shader. But somehow that is annoying, so do something else. Don't pad
textures anymore, and rescale the chroma coordinates in the shader
instead.
Seems like this somehow doesn't work with rectangle textures (and
introduces a chroma shift), but since it's only used when doing VDA
hardware decoding, and the bug occurs only with unaligned video sizes, I
don't care much.
Fixes #1523.
2015-01-27 17:08:42 +00:00
|
|
|
shader_def_opt(&header_conv, "USE_CHROMA_FIX",
|
2015-01-28 12:50:39 +00:00
|
|
|
p->chroma_fix[0] != 1.0f || p->chroma_fix[1] != 1.0f);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-06 09:47:26 +00:00
|
|
|
shader_def_opt(&header_final, "USE_SIGMOID_INV", use_sigmoid);
|
2015-02-03 16:12:04 +00:00
|
|
|
shader_def_opt(&header_final, "USE_INV_GAMMA", p->user_gamma_enabled);
|
2014-03-26 00:46:38 +00:00
|
|
|
shader_def_opt(&header_final, "USE_CMS_MATRIX", use_cms_matrix);
|
2013-03-01 20:19:20 +00:00
|
|
|
shader_def_opt(&header_final, "USE_3DLUT", p->use_lut_3d);
|
2015-02-06 02:37:21 +00:00
|
|
|
shader_def_opt(&header_final, "USE_SRGB", use_srgb);
|
|
|
|
shader_def_opt(&header_final, "USE_INV_BT1886", use_inv_bt1886);
|
2013-03-01 20:19:20 +00:00
|
|
|
shader_def_opt(&header_final, "USE_DITHER", p->dither_texture != 0);
|
2013-05-25 23:48:39 +00:00
|
|
|
shader_def_opt(&header_final, "USE_TEMPORAL_DITHER", p->opts.temporal_dither);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-22 17:24:50 +00:00
|
|
|
if (p->scalers[0].kernel && !p->scalers[0].kernel->polar) {
|
2013-03-01 20:19:20 +00:00
|
|
|
header_sep = talloc_strdup(tmp, "");
|
|
|
|
shader_def_opt(&header_sep, "FIXED_SCALE", true);
|
|
|
|
shader_setup_scaler(&header_sep, &p->scalers[0], 0);
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
shader_setup_scaler(&header_inter, &p->scalers[0], 1);
|
2013-03-01 20:19:20 +00:00
|
|
|
} else {
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
shader_setup_scaler(&header_inter, &p->scalers[0], -1);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-23 19:06:05 +00:00
|
|
|
bool use_interpolation = p->opts.smoothmotion;
|
|
|
|
|
|
|
|
if (use_interpolation) {
|
|
|
|
shader_def_opt(&header_inter, "FIXED_SCALE", true);
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
shader_def_opt(&header_final, "USE_LINEAR_INTERPOLATION", 1);
|
2014-11-23 19:06:05 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 19:56:40 +00:00
|
|
|
// The indirect pass is used to preprocess the image before scaling.
|
2015-01-22 17:24:50 +00:00
|
|
|
bool use_indirect = false;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
// Don't sample from input video textures before converting the input to
|
2015-01-13 23:45:31 +00:00
|
|
|
// its proper gamma.
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
if (use_input_gamma || use_conv_gamma || use_linear_light || use_const_luma)
|
2013-03-01 20:19:20 +00:00
|
|
|
use_indirect = true;
|
|
|
|
|
2015-01-22 17:24:50 +00:00
|
|
|
// Trivial scalers are implemented directly and efficiently by the GPU.
|
|
|
|
// This only includes bilinear and nearest neighbour in OpenGL, but we
|
|
|
|
// don't support nearest neighbour upsampling.
|
|
|
|
bool trivial_scaling = strcmp(p->scalers[0].name, "bilinear") == 0 &&
|
|
|
|
strcmp(p->scalers[1].name, "bilinear") == 0;
|
|
|
|
|
2015-01-20 19:56:40 +00:00
|
|
|
// If the video is subsampled, chroma information needs to be pulled up to
|
|
|
|
// the input size before scaling can be done. Even for 4:4:4 or planar RGB
|
|
|
|
// this is also faster because it means the scalers can operate on all
|
2015-01-22 17:24:50 +00:00
|
|
|
// channels simultaneously. This is unnecessary for trivial scaling.
|
|
|
|
if (p->plane_count > 1 && !trivial_scaling)
|
2013-03-01 20:19:20 +00:00
|
|
|
use_indirect = true;
|
|
|
|
|
|
|
|
if (input_is_subsampled(p)) {
|
|
|
|
shader_setup_scaler(&header_conv, &p->scalers[1], -1);
|
|
|
|
} else {
|
2015-01-20 20:46:19 +00:00
|
|
|
// Force using the normal scaler on chroma. If the "indirect" stage is
|
2013-03-01 20:19:20 +00:00
|
|
|
// used, the actual scaling will happen in the next stage.
|
|
|
|
shader_def(&header_conv, "SAMPLE_C",
|
2015-01-20 20:46:19 +00:00
|
|
|
use_indirect ? "SAMPLE_TRIVIAL" : "SAMPLE");
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (use_indirect) {
|
|
|
|
// We don't use filtering for the Y-plane (luma), because it's never
|
|
|
|
// scaled in this scenario.
|
2015-01-20 20:46:19 +00:00
|
|
|
shader_def(&header_conv, "SAMPLE", "SAMPLE_TRIVIAL");
|
2013-03-01 20:19:20 +00:00
|
|
|
shader_def_opt(&header_conv, "FIXED_SCALE", true);
|
|
|
|
header_conv = t_concat(tmp, header, header_conv);
|
|
|
|
p->indirect_program =
|
2015-01-29 17:29:28 +00:00
|
|
|
create_program(p, "indirect", header_conv, vertex_shader, s_video, v);
|
2013-03-01 20:19:20 +00:00
|
|
|
} else if (header_sep) {
|
|
|
|
header_sep = t_concat(tmp, header_sep, header_conv);
|
|
|
|
} else {
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
header_inter = t_concat(tmp, header_inter, header_conv);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (header_sep) {
|
|
|
|
header_sep = t_concat(tmp, header, header_sep);
|
|
|
|
p->scale_sep_program =
|
2015-01-29 17:29:28 +00:00
|
|
|
create_program(p, "scale_sep", header_sep, vertex_shader, s_video, v);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-23 19:06:05 +00:00
|
|
|
if (use_interpolation) {
|
|
|
|
header_inter = t_concat(tmp, header, header_inter);
|
|
|
|
p->inter_program =
|
2015-01-29 17:29:28 +00:00
|
|
|
create_program(p, "inter", header_inter, vertex_shader, s_video, v);
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
} else {
|
|
|
|
header_final = t_concat(tmp, header_final, header_inter);
|
2014-11-23 19:06:05 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
header_final = t_concat(tmp, header, header_final);
|
|
|
|
p->final_program =
|
2015-01-29 17:29:28 +00:00
|
|
|
create_program(p, "final", header_final, vertex_shader, s_video, v);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
debug_check_gl(p, "shader compilation");
|
|
|
|
|
|
|
|
talloc_free(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_program(GL *gl, GLuint *prog)
|
|
|
|
{
|
|
|
|
gl->DeleteProgram(*prog);
|
|
|
|
*prog = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_shaders(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
for (int n = 0; n < SUBBITMAP_COUNT; n++)
|
2015-01-29 17:29:28 +00:00
|
|
|
delete_program(gl, &p->osd->programs[n]);
|
2013-03-01 20:19:20 +00:00
|
|
|
delete_program(gl, &p->indirect_program);
|
|
|
|
delete_program(gl, &p->scale_sep_program);
|
|
|
|
delete_program(gl, &p->final_program);
|
2014-11-23 19:06:05 +00:00
|
|
|
delete_program(gl, &p->inter_program);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-28 22:57:06 +00:00
|
|
|
static void get_scale_factors(struct gl_video *p, double xy[2])
|
|
|
|
{
|
|
|
|
xy[0] = (p->dst_rect.x1 - p->dst_rect.x0) /
|
|
|
|
(double)(p->src_rect.x1 - p->src_rect.x0);
|
|
|
|
xy[1] = (p->dst_rect.y1 - p->dst_rect.y0) /
|
|
|
|
(double)(p->src_rect.y1 - p->src_rect.y0);
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
static double get_scale_factor(struct gl_video *p)
|
|
|
|
{
|
2014-11-28 22:57:06 +00:00
|
|
|
double xy[2];
|
|
|
|
get_scale_factors(p, xy);
|
|
|
|
return FFMIN(xy[0], xy[1]);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-28 22:57:06 +00:00
|
|
|
static void update_scale_factor(struct gl_video *p, struct scaler *scaler)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2014-11-28 22:57:06 +00:00
|
|
|
double scale = 1.0;
|
|
|
|
double xy[2];
|
|
|
|
get_scale_factors(p, xy);
|
|
|
|
double f = MPMIN(xy[0], xy[1]);
|
2015-01-25 00:35:17 +00:00
|
|
|
if (p->opts.fancy_downscaling && scaler->index == 0 && f < 1.0 &&
|
2014-11-28 22:57:06 +00:00
|
|
|
fabs(xy[0] - f) < 0.01 && fabs(xy[1] - f) < 0.01)
|
|
|
|
{
|
|
|
|
MP_VERBOSE(p, "Using fancy-downscaling (scaler %d).\n", scaler->index);
|
|
|
|
scale = FFMAX(1.0, 1.0 / f);
|
|
|
|
}
|
|
|
|
scaler->insufficient = !mp_init_filter(scaler->kernel, filter_sizes, scale);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void init_scaler(struct gl_video *p, struct scaler *scaler)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
assert(scaler->name);
|
|
|
|
|
|
|
|
scaler->kernel = NULL;
|
2014-11-28 22:57:06 +00:00
|
|
|
scaler->insufficient = false;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
const struct filter_kernel *t_kernel = mp_find_filter_kernel(scaler->name);
|
|
|
|
if (!t_kernel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scaler->kernel_storage = *t_kernel;
|
|
|
|
scaler->kernel = &scaler->kernel_storage;
|
|
|
|
|
|
|
|
for (int n = 0; n < 2; n++) {
|
2014-08-25 20:36:48 +00:00
|
|
|
if (!isnan(p->opts.scaler_params[scaler->index][n]))
|
|
|
|
scaler->kernel->params[n] = p->opts.scaler_params[scaler->index][n];
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 17:57:12 +00:00
|
|
|
scaler->antiring = p->opts.scaler_antiring[scaler->index];
|
|
|
|
|
2015-01-26 00:56:19 +00:00
|
|
|
if (scaler->kernel->radius < 0)
|
|
|
|
scaler->kernel->radius = p->opts.scaler_radius[scaler->index];
|
2014-08-25 22:41:30 +00:00
|
|
|
|
2014-11-28 22:57:06 +00:00
|
|
|
update_scale_factor(p, scaler);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-17 16:28:47 +00:00
|
|
|
int size = scaler->kernel->size;
|
2014-12-08 16:08:26 +00:00
|
|
|
int elems_per_pixel = 4;
|
2015-01-18 15:28:41 +00:00
|
|
|
if (size == 1) {
|
2015-01-04 22:11:27 +00:00
|
|
|
elems_per_pixel = 1;
|
|
|
|
} else if (size == 2) {
|
2014-12-08 16:08:26 +00:00
|
|
|
elems_per_pixel = 2;
|
|
|
|
} else if (size == 6) {
|
|
|
|
elems_per_pixel = 3;
|
|
|
|
}
|
|
|
|
int width = size / elems_per_pixel;
|
2015-01-18 15:28:41 +00:00
|
|
|
assert(size == width * elems_per_pixel);
|
2014-12-08 16:08:26 +00:00
|
|
|
const struct fmt_entry *fmt = &gl_float16_formats[elems_per_pixel - 1];
|
2015-01-17 16:28:47 +00:00
|
|
|
int target;
|
|
|
|
|
|
|
|
if (scaler->kernel->polar) {
|
|
|
|
target = GL_TEXTURE_1D;
|
|
|
|
scaler->lut_name = scaler->index == 0 ? "lut_1d_l" : "lut_1d_c";
|
|
|
|
} else {
|
|
|
|
target = GL_TEXTURE_2D;
|
|
|
|
scaler->lut_name = scaler->index == 0 ? "lut_2d_l" : "lut_2d_c";
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + TEXUNIT_SCALERS + scaler->index);
|
|
|
|
|
|
|
|
if (!scaler->gl_lut)
|
|
|
|
gl->GenTextures(1, &scaler->gl_lut);
|
|
|
|
|
2015-01-17 16:28:47 +00:00
|
|
|
gl->BindTexture(target, scaler->gl_lut);
|
2015-01-04 22:11:27 +00:00
|
|
|
|
2015-01-18 15:28:41 +00:00
|
|
|
float *weights = talloc_array(NULL, float, LOOKUP_TEXTURE_SIZE * size);
|
|
|
|
mp_compute_lut(scaler->kernel, LOOKUP_TEXTURE_SIZE, weights);
|
2015-01-17 16:28:47 +00:00
|
|
|
|
|
|
|
if (target == GL_TEXTURE_1D) {
|
|
|
|
gl->TexImage1D(target, 0, fmt->internal_format, LOOKUP_TEXTURE_SIZE,
|
|
|
|
0, fmt->format, GL_FLOAT, weights);
|
|
|
|
} else {
|
|
|
|
gl->TexImage2D(target, 0, fmt->internal_format, width, LOOKUP_TEXTURE_SIZE,
|
|
|
|
0, fmt->format, GL_FLOAT, weights);
|
|
|
|
}
|
|
|
|
|
2015-01-18 15:28:41 +00:00
|
|
|
talloc_free(weights);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-17 16:28:47 +00:00
|
|
|
gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
if (target != GL_TEXTURE_1D)
|
|
|
|
gl->TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
|
|
|
|
|
|
|
debug_check_gl(p, "after initializing scaler");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_dither(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
// Assume 8 bits per component if unknown.
|
|
|
|
int dst_depth = p->depth_g ? p->depth_g : 8;
|
|
|
|
if (p->opts.dither_depth > 0)
|
|
|
|
dst_depth = p->opts.dither_depth;
|
|
|
|
|
2013-05-25 23:48:39 +00:00
|
|
|
if (p->opts.dither_depth < 0 || p->opts.dither_algo < 0)
|
2013-03-01 20:19:20 +00:00
|
|
|
return;
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_VERBOSE(p, "Dither to %d.\n", dst_depth);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2013-05-25 23:48:39 +00:00
|
|
|
int tex_size;
|
|
|
|
void *tex_data;
|
2013-05-30 11:36:11 +00:00
|
|
|
GLint tex_iformat;
|
2014-12-17 20:36:17 +00:00
|
|
|
GLint tex_format;
|
2013-05-25 23:48:39 +00:00
|
|
|
GLenum tex_type;
|
|
|
|
unsigned char temp[256];
|
|
|
|
|
|
|
|
if (p->opts.dither_algo == 0) {
|
|
|
|
int sizeb = p->opts.dither_size;
|
|
|
|
int size = 1 << sizeb;
|
|
|
|
|
|
|
|
if (p->last_dither_matrix_size != size) {
|
|
|
|
p->last_dither_matrix = talloc_realloc(p, p->last_dither_matrix,
|
|
|
|
float, size * size);
|
|
|
|
mp_make_fruit_dither_matrix(p->last_dither_matrix, sizeb);
|
|
|
|
p->last_dither_matrix_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
tex_size = size;
|
2014-12-17 20:36:17 +00:00
|
|
|
tex_iformat = gl_float16_formats[0].internal_format;
|
|
|
|
tex_format = gl_float16_formats[0].format;
|
2013-05-25 23:48:39 +00:00
|
|
|
tex_type = GL_FLOAT;
|
|
|
|
tex_data = p->last_dither_matrix;
|
|
|
|
} else {
|
|
|
|
assert(sizeof(temp) >= 8 * 8);
|
|
|
|
mp_make_ordered_dither_matrix(temp, 8);
|
|
|
|
|
2014-12-17 20:36:17 +00:00
|
|
|
const struct fmt_entry *fmt = find_tex_format(gl, 1, 1);
|
2013-05-25 23:48:39 +00:00
|
|
|
tex_size = 8;
|
2014-12-17 20:36:17 +00:00
|
|
|
tex_iformat = fmt->internal_format;
|
|
|
|
tex_format = fmt->format;
|
|
|
|
tex_type = fmt->type;
|
2013-05-25 23:48:39 +00:00
|
|
|
tex_data = temp;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
// This defines how many bits are considered significant for output on
|
2013-05-25 23:48:39 +00:00
|
|
|
// screen. The superfluous bits will be used for rounding according to the
|
2013-03-01 20:19:20 +00:00
|
|
|
// dither matrix. The precision of the source implicitly decides how many
|
|
|
|
// dither patterns can be visible.
|
|
|
|
p->dither_quantization = (1 << dst_depth) - 1;
|
2013-05-30 11:36:11 +00:00
|
|
|
p->dither_center = 0.5 / (tex_size * tex_size);
|
2013-05-25 23:48:39 +00:00
|
|
|
p->dither_size = tex_size;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + TEXUNIT_DITHER);
|
|
|
|
gl->GenTextures(1, &p->dither_texture);
|
|
|
|
gl->BindTexture(GL_TEXTURE_2D, p->dither_texture);
|
|
|
|
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
2014-12-16 17:55:02 +00:00
|
|
|
gl->TexImage2D(GL_TEXTURE_2D, 0, tex_iformat, tex_size, tex_size, 0,
|
|
|
|
tex_format, tex_type, tex_data);
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
2014-12-18 23:58:56 +00:00
|
|
|
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
2014-12-17 20:36:17 +00:00
|
|
|
|
|
|
|
debug_check_gl(p, "dither setup");
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void recreate_osd(struct gl_video *p)
|
|
|
|
{
|
|
|
|
if (p->osd)
|
|
|
|
mpgl_osd_destroy(p->osd);
|
2015-01-29 17:29:28 +00:00
|
|
|
p->osd = mpgl_osd_init(p->gl, p->log, p->osd_state, p->osd_programs);
|
2013-03-01 20:19:20 +00:00
|
|
|
p->osd->use_pbo = p->opts.pbo;
|
|
|
|
}
|
|
|
|
|
2013-05-25 21:47:55 +00:00
|
|
|
static bool does_resize(struct mp_rect src, struct mp_rect dst)
|
|
|
|
{
|
|
|
|
return src.x1 - src.x0 != dst.x1 - dst.x0 ||
|
|
|
|
src.y1 - src.y0 != dst.y1 - dst.y0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *expected_scaler(struct gl_video *p, int unit)
|
|
|
|
{
|
|
|
|
if (p->opts.scaler_resizes_only && unit == 0 &&
|
|
|
|
!does_resize(p->src_rect, p->dst_rect))
|
|
|
|
{
|
|
|
|
return "bilinear";
|
|
|
|
}
|
2015-01-20 13:33:53 +00:00
|
|
|
if (unit == 0 && p->opts.dscaler && get_scale_factor(p) < 1.0)
|
|
|
|
return p->opts.dscaler;
|
2013-05-25 21:47:55 +00:00
|
|
|
return p->opts.scalers[unit];
|
|
|
|
}
|
|
|
|
|
2015-02-03 16:12:04 +00:00
|
|
|
static void update_settings(struct gl_video *p)
|
|
|
|
{
|
|
|
|
struct mp_csp_params params;
|
|
|
|
mp_csp_copy_equalizer_values(¶ms, &p->video_eq);
|
|
|
|
|
|
|
|
p->user_gamma = params.gamma * p->opts.gamma;
|
|
|
|
|
|
|
|
// Lazy gamma shader initialization (a microoptimization)
|
|
|
|
if (p->user_gamma != 1.0f && !p->user_gamma_enabled) {
|
|
|
|
p->user_gamma_enabled = true;
|
|
|
|
p->need_reinit_rendering = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
static void reinit_rendering(struct gl_video *p)
|
|
|
|
{
|
2015-01-29 13:58:26 +00:00
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_VERBOSE(p, "Reinit rendering.\n");
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
debug_check_gl(p, "before scaler initialization");
|
|
|
|
|
|
|
|
uninit_rendering(p);
|
|
|
|
|
2015-01-29 14:50:21 +00:00
|
|
|
if (!p->image_params.imgfmt)
|
2013-03-01 20:19:20 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-03 16:12:04 +00:00
|
|
|
update_settings(p);
|
|
|
|
|
2013-05-25 21:47:55 +00:00
|
|
|
for (int n = 0; n < 2; n++)
|
|
|
|
p->scalers[n].name = expected_scaler(p, n);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
init_dither(p);
|
|
|
|
|
|
|
|
init_scaler(p, &p->scalers[0]);
|
|
|
|
init_scaler(p, &p->scalers[1]);
|
|
|
|
|
|
|
|
compile_shaders(p);
|
|
|
|
update_all_uniforms(p);
|
|
|
|
|
2014-04-20 19:37:18 +00:00
|
|
|
int w = p->image_w;
|
|
|
|
int h = p->image_h;
|
|
|
|
|
2015-01-29 13:58:26 +00:00
|
|
|
// Convolution filters don't need linear sampling, so using nearest is
|
|
|
|
// often faster.
|
|
|
|
GLenum filter = p->scalers[0].kernel ? GL_NEAREST : GL_LINEAR;
|
|
|
|
|
|
|
|
if (p->indirect_program) {
|
|
|
|
fbotex_init(&p->indirect_fbo, gl, p->log, w, h, p->gl_target, filter,
|
|
|
|
p->opts.fbo_format);
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
recreate_osd(p);
|
2015-02-03 16:12:04 +00:00
|
|
|
|
|
|
|
p->need_reinit_rendering = false;
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit_rendering(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
delete_shaders(p);
|
|
|
|
|
|
|
|
for (int n = 0; n < 2; n++) {
|
|
|
|
gl->DeleteTextures(1, &p->scalers[n].gl_lut);
|
|
|
|
p->scalers[n].gl_lut = 0;
|
|
|
|
p->scalers[n].lut_name = NULL;
|
|
|
|
p->scalers[n].kernel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->DeleteTextures(1, &p->dither_texture);
|
|
|
|
p->dither_texture = 0;
|
2015-01-20 20:24:29 +00:00
|
|
|
|
2015-01-29 13:58:26 +00:00
|
|
|
fbotex_uninit(&p->indirect_fbo);
|
|
|
|
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
for (int i = 0; i < FBOSURFACES_MAX; i++) {
|
2015-01-29 13:58:26 +00:00
|
|
|
fbotex_uninit(&p->surfaces[i].fbotex);
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
p->surfaces[i].valid = false;
|
|
|
|
}
|
2015-01-29 13:58:26 +00:00
|
|
|
|
|
|
|
fbotex_uninit(&p->scale_sep_fbo);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gl_video_set_lut3d(struct gl_video *p, struct lut3d *lut3d)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2014-03-24 22:30:12 +00:00
|
|
|
if (!lut3d) {
|
|
|
|
if (p->use_lut_3d) {
|
|
|
|
p->use_lut_3d = false;
|
|
|
|
reinit_rendering(p);
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
return;
|
2014-03-24 22:30:12 +00:00
|
|
|
}
|
|
|
|
|
2014-12-23 01:48:58 +00:00
|
|
|
if (!(gl->mpgl_caps & MPGL_CAP_3D_TEX))
|
|
|
|
return;
|
|
|
|
|
2014-03-24 22:30:12 +00:00
|
|
|
if (!p->lut_3d_texture)
|
|
|
|
gl->GenTextures(1, &p->lut_3d_texture);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + TEXUNIT_3DLUT);
|
|
|
|
gl->BindTexture(GL_TEXTURE_3D, p->lut_3d_texture);
|
|
|
|
gl->TexImage3D(GL_TEXTURE_3D, 0, GL_RGB16, lut3d->size[0], lut3d->size[1],
|
|
|
|
lut3d->size[2], 0, GL_RGB, GL_UNSIGNED_SHORT, lut3d->data);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->TexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
|
|
|
|
|
|
|
p->use_lut_3d = true;
|
|
|
|
check_gl_features(p);
|
|
|
|
|
|
|
|
debug_check_gl(p, "after 3d lut creation");
|
2014-03-24 22:30:12 +00:00
|
|
|
|
|
|
|
reinit_rendering(p);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
static void set_image_textures(struct gl_video *p, struct video_image *vimg,
|
|
|
|
GLuint imgtex[4])
|
2013-03-28 19:40:19 +00:00
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
2013-11-04 00:20:11 +00:00
|
|
|
GLuint dummy[4] = {0};
|
2013-11-03 23:00:18 +00:00
|
|
|
if (!imgtex)
|
|
|
|
imgtex = dummy;
|
2013-03-28 19:40:19 +00:00
|
|
|
|
2015-01-22 17:29:37 +00:00
|
|
|
assert(vimg->mpi);
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
if (p->hwdec_active) {
|
2015-01-22 17:29:37 +00:00
|
|
|
p->hwdec->driver->map_image(p->hwdec, vimg->mpi, imgtex);
|
2013-11-03 23:00:18 +00:00
|
|
|
} else {
|
|
|
|
for (int n = 0; n < p->plane_count; n++)
|
|
|
|
imgtex[n] = vimg->planes[n].gl_texture;
|
|
|
|
}
|
2013-03-28 19:40:19 +00:00
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
for (int n = 0; n < 4; n++) {
|
2013-03-28 19:40:19 +00:00
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + n);
|
2013-12-01 22:39:13 +00:00
|
|
|
gl->BindTexture(p->gl_target, imgtex[n]);
|
2013-11-03 23:00:18 +00:00
|
|
|
}
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unset_image_textures(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
for (int n = 0; n < 4; n++) {
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + n);
|
2013-12-01 22:39:13 +00:00
|
|
|
gl->BindTexture(p->gl_target, 0);
|
2013-03-28 19:40:19 +00:00
|
|
|
}
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
2013-11-03 23:00:18 +00:00
|
|
|
|
|
|
|
if (p->hwdec_active)
|
2013-11-05 18:08:44 +00:00
|
|
|
p->hwdec->driver->unmap_image(p->hwdec);
|
2013-03-28 19:40:19 +00:00
|
|
|
}
|
|
|
|
|
2015-01-29 14:50:21 +00:00
|
|
|
static int align_pow2(int s)
|
|
|
|
{
|
|
|
|
int r = 1;
|
|
|
|
while (r < s)
|
|
|
|
r *= 2;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
static void init_video(struct gl_video *p)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
check_gl_features(p);
|
2013-11-05 18:08:44 +00:00
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
init_format(p->image_params.imgfmt, p);
|
2013-12-01 22:39:13 +00:00
|
|
|
p->gl_target = p->opts.use_rectangle ? GL_TEXTURE_RECTANGLE : GL_TEXTURE_2D;
|
2015-01-29 18:53:49 +00:00
|
|
|
|
|
|
|
if (p->hwdec_active) {
|
|
|
|
if (p->hwdec->driver->reinit(p->hwdec, &p->image_params) < 0)
|
|
|
|
MP_ERR(p, "Initializing texture for hardware decoding failed.\n");
|
|
|
|
init_format(p->image_params.imgfmt, p);
|
2013-12-01 22:39:13 +00:00
|
|
|
p->gl_target = p->hwdec->gl_texture_target;
|
2015-01-29 18:53:49 +00:00
|
|
|
}
|
2013-12-01 22:39:13 +00:00
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
mp_image_params_guess_csp(&p->image_params);
|
2013-12-01 22:39:13 +00:00
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
p->image_w = p->image_params.w;
|
|
|
|
p->image_h = p->image_params.h;
|
2013-11-05 18:08:44 +00:00
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
int eq_caps = MP_CSP_EQ_CAPS_GAMMA;
|
2014-03-26 22:00:09 +00:00
|
|
|
if (p->is_yuv && p->image_params.colorspace != MP_CSP_BT_2020_C)
|
2013-03-01 20:19:20 +00:00
|
|
|
eq_caps |= MP_CSP_EQ_CAPS_COLORMATRIX;
|
2014-03-31 02:51:47 +00:00
|
|
|
if (p->image_desc.flags & MP_IMGFLAG_XYZ)
|
|
|
|
eq_caps |= MP_CSP_EQ_CAPS_BRIGHTNESS;
|
2013-03-01 20:19:20 +00:00
|
|
|
p->video_eq.capabilities = eq_caps;
|
|
|
|
|
|
|
|
debug_check_gl(p, "before video texture creation");
|
|
|
|
|
2013-03-28 19:40:19 +00:00
|
|
|
struct video_image *vimg = &p->image;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < p->plane_count; n++) {
|
2013-03-28 19:40:19 +00:00
|
|
|
struct texplane *plane = &vimg->planes[n];
|
|
|
|
|
vo_opengl: change the way unaligned chroma size is handled
This deals with subsampled YUV video that has odd sizes, for example a
5x5 image with 4:2:0 subsampling.
It would be easy to handle if we actually passed separate texture
coordinates for each plane to the shader, but as of now the luma
coordinates are implicitly rescaled to chroma one. If luma and chroma
sizes don't match up, and this is not handled, you'd get a chroma shift
by 1 pixel.
The existing hack worked, but broke separable scaling. This was exposed
by a recent commit which switched to GL_NEAREST sampling for FBOs. The
rendering was accidentally scaled by 1 pixel, because the FBO size used
the original video size, while textures_sizes[0] was set to the padded
texture size (i.e. one pixel larger).
It could be fixed by setting the padded texture size only on the first
shader. But somehow that is annoying, so do something else. Don't pad
textures anymore, and rescale the chroma coordinates in the shader
instead.
Seems like this somehow doesn't work with rectangle textures (and
introduces a chroma shift), but since it's only used when doing VDA
hardware decoding, and the bug occurs only with unaligned video sizes, I
don't care much.
Fixes #1523.
2015-01-27 17:08:42 +00:00
|
|
|
plane->w = mp_chroma_div_up(p->image_w, p->image_desc.xs[n]);
|
|
|
|
plane->h = mp_chroma_div_up(p->image_h, p->image_desc.ys[n]);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-29 14:50:21 +00:00
|
|
|
plane->tex_w = plane->w;
|
|
|
|
plane->tex_h = plane->h;
|
|
|
|
|
|
|
|
if (!p->hwdec_active) {
|
|
|
|
if (!p->opts.npot) {
|
|
|
|
plane->tex_w = align_pow2(plane->tex_w);
|
|
|
|
plane->tex_h = align_pow2(plane->tex_h);
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + n);
|
|
|
|
gl->GenTextures(1, &plane->gl_texture);
|
2013-12-01 22:39:13 +00:00
|
|
|
gl->BindTexture(p->gl_target, plane->gl_texture);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2013-12-01 22:39:13 +00:00
|
|
|
gl->TexImage2D(p->gl_target, 0, plane->gl_internal_format,
|
2013-11-03 23:00:18 +00:00
|
|
|
plane->tex_w, plane->tex_h, 0,
|
|
|
|
plane->gl_format, plane->gl_type, NULL);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-29 14:50:21 +00:00
|
|
|
gl->TexParameteri(p->gl_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri(p->gl_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri(p->gl_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->TexParameteri(p->gl_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2013-11-03 23:00:18 +00:00
|
|
|
}
|
2013-03-28 19:48:53 +00:00
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
MP_VERBOSE(p, "Texture for plane %d: %dx%d\n",
|
|
|
|
n, plane->tex_w, plane->tex_h);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
|
|
|
|
2015-01-28 12:50:39 +00:00
|
|
|
// If the dimensions of the Y plane are not aligned on the luma.
|
|
|
|
// Assume 4:2:0 with size (3,3). The last luma pixel is (2,2).
|
|
|
|
// The last chroma pixel is (1,1), not (0,0). So for luma, the
|
|
|
|
// coordinate range is [0,3), for chroma it is [0,2). This means the
|
|
|
|
// texture coordinates for chroma are stretched by adding 1 luma pixel
|
|
|
|
// to the range. Undo this.
|
2015-01-29 14:50:21 +00:00
|
|
|
p->chroma_fix[0] = p->image.planes[0].tex_w / (double)p->image.planes[1].tex_w
|
2015-01-28 12:50:39 +00:00
|
|
|
/ (1 << p->image_desc.chroma_xs);
|
2015-01-29 14:50:21 +00:00
|
|
|
p->chroma_fix[1] = p->image.planes[0].tex_h / (double)p->image.planes[1].tex_h
|
2015-01-28 12:50:39 +00:00
|
|
|
/ (1 << p->image_desc.chroma_ys);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
debug_check_gl(p, "after video texture creation");
|
|
|
|
|
|
|
|
reinit_rendering(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit_video(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
uninit_rendering(p);
|
|
|
|
|
2013-03-28 19:40:19 +00:00
|
|
|
struct video_image *vimg = &p->image;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
for (int n = 0; n < 3; n++) {
|
2013-03-28 19:40:19 +00:00
|
|
|
struct texplane *plane = &vimg->planes[n];
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
gl->DeleteTextures(1, &plane->gl_texture);
|
|
|
|
plane->gl_texture = 0;
|
|
|
|
gl->DeleteBuffers(1, &plane->gl_buffer);
|
|
|
|
plane->gl_buffer = 0;
|
|
|
|
plane->buffer_ptr = NULL;
|
|
|
|
plane->buffer_size = 0;
|
|
|
|
}
|
2015-01-22 17:29:37 +00:00
|
|
|
mp_image_unrefp(&vimg->mpi);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-01-07 18:00:26 +00:00
|
|
|
// Invalidate image_params to ensure that gl_video_config() will call
|
|
|
|
// init_video() on uninitialized gl_video.
|
2015-01-29 18:53:49 +00:00
|
|
|
p->real_image_params = (struct mp_image_params){0};
|
|
|
|
p->image_params = p->real_image_params;
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2013-05-25 23:48:39 +00:00
|
|
|
static void change_dither_trafo(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
int program = p->final_program;
|
|
|
|
|
|
|
|
int phase = p->frames_rendered % 8u;
|
|
|
|
float r = phase * (M_PI / 2); // rotate
|
|
|
|
float m = phase < 4 ? 1 : -1; // mirror
|
|
|
|
|
|
|
|
gl->UseProgram(program);
|
|
|
|
|
|
|
|
float matrix[2][2] = {{cos(r), -sin(r) },
|
|
|
|
{sin(r) * m, cos(r) * m}};
|
|
|
|
gl->UniformMatrix2fv(gl->GetUniformLocation(program, "dither_trafo"),
|
|
|
|
1, GL_TRUE, &matrix[0][0]);
|
|
|
|
|
|
|
|
gl->UseProgram(0);
|
|
|
|
}
|
|
|
|
|
2014-04-20 19:30:23 +00:00
|
|
|
struct pass {
|
2014-04-20 19:37:18 +00:00
|
|
|
int num;
|
2014-04-20 19:30:23 +00:00
|
|
|
// Not necessarily a FBO; we just abuse this struct because it's convenient.
|
|
|
|
// It specifies the source texture/sub-rectangle for the next pass.
|
|
|
|
struct fbotex f;
|
|
|
|
// If true, render source (f) to dst, instead of the full dest. fbo viewport
|
|
|
|
bool use_dst;
|
|
|
|
struct mp_rect dst;
|
2014-04-20 19:37:18 +00:00
|
|
|
int flags; // for write_quad
|
2014-04-20 19:30:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// *chain contains the source, and is overwritten with a copy of the result
|
|
|
|
// fbo is used as destination texture/render target.
|
|
|
|
static void handle_pass(struct gl_video *p, struct pass *chain,
|
|
|
|
struct fbotex *fbo, GLuint program)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2014-04-20 19:30:23 +00:00
|
|
|
if (!program)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->BindTexture(p->gl_target, chain->f.texture);
|
|
|
|
gl->UseProgram(program);
|
|
|
|
|
gl_video: fix scaling when image is cropped, or with no-npot
When the displayed image is cropped in Y direction (like using panscan
controls when playing 4:3 video on a 16:9 monitor), and separated
scaling is used, the texture size for the FBO holding the intermediate
result was calculated incorrectly. This could lead to artifacts, which
were quite apparent with extreme scale factors.
Actually, the size of that texture is OK, but the texture shouldn't be
used to hold the complete scaled image. Instead, it should be used for
the visible part of the image only. Because separate scaling works by
scaling in Y direction first, it's still fine to scale the image on the
full image width on the first pass. This helps avoiding artifacts on
the left/right border of the image when scaling in X direction, as the
scaler will try to fetch pixels from beyond the border. (The left border
is still kind of fine, but the right border will fetch garbage, unless
the texture is strictly sized, or explicit clamping is added to the
shader. Too much trouble, so using the full image width is simpler.)
Also fix some issues with no-npot mode, which enables use of power-of-2
textures. Maybe this mode isn't really useful anymore (modern hardware
is faster with smaller non-power-of-2 textures), but keep it for now.
2013-06-14 21:16:58 +00:00
|
|
|
gl->Viewport(fbo->vp_x, fbo->vp_y, fbo->vp_w, fbo->vp_h);
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->BindFramebuffer(GL_FRAMEBUFFER, fbo->fbo);
|
|
|
|
|
2014-04-20 19:30:23 +00:00
|
|
|
int tex_w = chain->f.tex_w;
|
|
|
|
int tex_h = chain->f.tex_h;
|
|
|
|
struct mp_rect src = {
|
|
|
|
.x0 = chain->f.vp_x,
|
|
|
|
.y0 = chain->f.vp_y,
|
|
|
|
.x1 = chain->f.vp_x + chain->f.vp_w,
|
|
|
|
.y1 = chain->f.vp_y + chain->f.vp_h,
|
|
|
|
};
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-04-20 19:30:23 +00:00
|
|
|
struct mp_rect dst = {-1, -1, 1, 1};
|
|
|
|
if (chain->use_dst)
|
|
|
|
dst = chain->dst;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-04-20 19:37:18 +00:00
|
|
|
MP_TRACE(p, "Pass %d: [%d,%d,%d,%d] -> [%d,%d,%d,%d][%d,%d@%dx%d/%dx%d] (%d)\n",
|
|
|
|
chain->num, src.x0, src.y0, src.x1, src.y1,
|
|
|
|
dst.x0, dst.y0, dst.x1, dst.y1,
|
|
|
|
fbo->vp_x, fbo->vp_y, fbo->vp_w, fbo->vp_h,
|
|
|
|
fbo->tex_w, fbo->tex_h, chain->flags);
|
|
|
|
|
2015-01-30 13:02:09 +00:00
|
|
|
draw_quad(p,
|
|
|
|
dst.x0, dst.y0, dst.x1, dst.y1,
|
|
|
|
src.x0, src.y0, src.x1, src.y1,
|
|
|
|
tex_w, tex_h, chain->flags);
|
2014-04-20 19:30:23 +00:00
|
|
|
|
|
|
|
*chain = (struct pass){
|
2014-04-20 19:37:18 +00:00
|
|
|
.num = chain->num + 1,
|
2014-04-20 19:30:23 +00:00
|
|
|
.f = *fbo,
|
|
|
|
};
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-29 14:50:21 +00:00
|
|
|
static size_t fbosurface_next(struct gl_video *p)
|
|
|
|
{
|
|
|
|
return (p->surface_idx + 1) % FBOSURFACES_MAX;
|
|
|
|
}
|
|
|
|
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
// Handle all of the frame passes upto and including upscaling, assuming
|
|
|
|
// upscaling is not part of the final pass
|
|
|
|
static void gl_video_upscale_frame(struct gl_video *p, struct pass *chain, struct fbotex *inter_fbo)
|
|
|
|
{
|
|
|
|
// Order of processing: [indirect -> [scale_sep ->]] inter
|
|
|
|
handle_pass(p, chain, &p->indirect_fbo, p->indirect_program);
|
|
|
|
|
|
|
|
// compensated for optional rotation
|
|
|
|
struct mp_rect src_rect_rot = p->src_rect;
|
|
|
|
if ((p->image_params.rotate % 180) == 90) {
|
|
|
|
MPSWAP(int, src_rect_rot.x0, src_rect_rot.y0);
|
|
|
|
MPSWAP(int, src_rect_rot.x1, src_rect_rot.y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip to visible height so that separate scaling scales the visible part
|
|
|
|
// only (and the target FBO texture can have a bounded size).
|
|
|
|
// Don't clamp width; too hard to get correct final scaling on l/r borders.
|
|
|
|
chain->f.vp_y = src_rect_rot.y0;
|
|
|
|
chain->f.vp_h = src_rect_rot.y1 - src_rect_rot.y0;
|
|
|
|
|
|
|
|
handle_pass(p, chain, &p->scale_sep_fbo, p->scale_sep_program);
|
|
|
|
|
|
|
|
// For Y direction, use the whole source viewport; it has been fit to the
|
|
|
|
// correct origin/height before.
|
|
|
|
// For X direction, assume the texture wasn't scaled yet, so we can
|
|
|
|
// select the correct portion, which will be scaled to screen.
|
|
|
|
chain->f.vp_x = src_rect_rot.x0;
|
|
|
|
chain->f.vp_w = src_rect_rot.x1 - src_rect_rot.x0;
|
|
|
|
|
|
|
|
if (inter_fbo)
|
|
|
|
handle_pass(p, chain, inter_fbo, p->inter_program);
|
|
|
|
}
|
|
|
|
|
|
|
|
static double gl_video_interpolate_frame(struct gl_video *p,
|
2014-11-23 19:06:05 +00:00
|
|
|
struct pass *chain,
|
|
|
|
struct frame_timing *t)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
double inter_coeff = 0.0;
|
|
|
|
int64_t prev_pts = p->surfaces[fbosurface_next(p)].pts;
|
|
|
|
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
// Make sure all surfaces are actually valid, and redraw them manually
|
|
|
|
// if this is not the case
|
|
|
|
for (int i = 0; i < FBOSURFACES_MAX; i++) {
|
|
|
|
if (!p->surfaces[i].valid) {
|
|
|
|
struct pass frame = { .f = chain->f };
|
|
|
|
gl_video_upscale_frame(p, &frame, &p->surfaces[i].fbotex);
|
|
|
|
p->surfaces[i].valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t && prev_pts < t->pts) {
|
2014-11-23 19:06:05 +00:00
|
|
|
MP_STATS(p, "new-pts");
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
gl_video_upscale_frame(p, chain, &p->surfaces[p->surface_idx].fbotex);
|
|
|
|
p->surfaces[p->surface_idx].valid = true;
|
2015-01-29 14:50:21 +00:00
|
|
|
p->surfaces[p->surface_idx].pts = t->pts;
|
|
|
|
p->surface_idx = fbosurface_next(p);
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
} else {
|
|
|
|
// re-use the previously rendered surface as source
|
|
|
|
chain->f = p->surfaces[fbosurface_next(p)].fbotex;
|
2014-11-23 19:06:05 +00:00
|
|
|
}
|
|
|
|
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
// fbosurface 0 is bound by handle_pass
|
2015-02-19 13:03:18 +00:00
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + 1);
|
|
|
|
gl->BindTexture(p->gl_target, p->surfaces[p->surface_idx].fbotex.texture);
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
|
|
|
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
if (!t) {
|
|
|
|
p->is_interpolated = false;
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t vsync_interval = t->next_vsync - t->prev_vsync;
|
|
|
|
|
2015-02-19 13:03:18 +00:00
|
|
|
if (t->pts > t->next_vsync && t->pts < t->next_vsync + vsync_interval) {
|
|
|
|
// current frame overlaps PTS boundary, blend
|
|
|
|
double R = t->pts - t->next_vsync;
|
|
|
|
float ts = p->opts.smoothmotion_threshold;
|
|
|
|
inter_coeff = R / vsync_interval;
|
|
|
|
inter_coeff = inter_coeff < 0.0 + ts ? 0.0 : inter_coeff;
|
|
|
|
inter_coeff = inter_coeff > 1.0 - ts ? 1.0 : inter_coeff;
|
|
|
|
MP_DBG(p, "inter frame ppts: %lld, pts: %lld, "
|
|
|
|
"vsync: %lld, mix: %f\n",
|
|
|
|
(long long)prev_pts, (long long)t->pts,
|
|
|
|
(long long)t->next_vsync, inter_coeff);
|
|
|
|
MP_STATS(p, "frame-mix");
|
|
|
|
|
|
|
|
// the value is scaled to fit in the graph with the completely
|
|
|
|
// unrelated "phase" value (which is stupid)
|
|
|
|
MP_STATS(p, "value-timed %lld %f mix-value",
|
|
|
|
(long long)t->pts, inter_coeff * 10000);
|
|
|
|
} else if (t->pts > t->next_vsync) {
|
|
|
|
// there's a new frame, but we haven't displayed or blended it yet,
|
|
|
|
// so we still draw the old frame
|
|
|
|
inter_coeff = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->is_interpolated = inter_coeff > 0.0;
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
return inter_coeff;
|
2014-11-23 19:06:05 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 19:11:20 +00:00
|
|
|
// (fbo==0 makes BindFramebuffer select the screen backbuffer)
|
2014-11-23 19:06:05 +00:00
|
|
|
void gl_video_render_frame(struct gl_video *p, int fbo, struct frame_timing *t)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
2013-03-28 19:40:19 +00:00
|
|
|
struct video_image *vimg = &p->image;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2015-02-04 22:37:38 +00:00
|
|
|
p->is_interpolated = false;
|
|
|
|
|
2014-12-02 19:11:20 +00:00
|
|
|
gl->BindFramebuffer(GL_FRAMEBUFFER, fbo);
|
|
|
|
gl->Viewport(p->vp_x, p->vp_y, p->vp_w, p->vp_h);
|
|
|
|
|
2013-05-25 23:48:39 +00:00
|
|
|
if (p->opts.temporal_dither)
|
|
|
|
change_dither_trafo(p);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
if (p->dst_rect.x0 > p->vp_x || p->dst_rect.y0 > p->vp_y
|
|
|
|
|| p->dst_rect.x1 < p->vp_x + p->vp_w
|
|
|
|
|| p->dst_rect.y1 < p->vp_y + p->vp_h)
|
|
|
|
{
|
|
|
|
gl->Clear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2015-01-22 17:29:37 +00:00
|
|
|
if (!vimg->mpi) {
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
gl->Clear(GL_COLOR_BUFFER_BIT);
|
2014-06-18 18:04:59 +00:00
|
|
|
goto draw_osd;
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
GLuint imgtex[4] = {0};
|
|
|
|
set_image_textures(p, vimg, imgtex);
|
2013-03-28 19:40:19 +00:00
|
|
|
|
2014-04-20 19:30:23 +00:00
|
|
|
struct pass chain = {
|
|
|
|
.f = {
|
|
|
|
.vp_w = p->image_w,
|
|
|
|
.vp_h = p->image_h,
|
2015-01-29 14:50:21 +00:00
|
|
|
.tex_w = vimg->planes[0].tex_w,
|
|
|
|
.tex_h = vimg->planes[0].tex_h,
|
2014-04-20 19:30:23 +00:00
|
|
|
.texture = imgtex[0],
|
|
|
|
},
|
2013-03-01 20:19:20 +00:00
|
|
|
};
|
|
|
|
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
double inter_coeff = 0.0;
|
|
|
|
if (p->opts.smoothmotion) {
|
|
|
|
inter_coeff = gl_video_interpolate_frame(p, &chain, t);
|
2014-11-23 19:06:05 +00:00
|
|
|
} else {
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
gl_video_upscale_frame(p, &chain, NULL);
|
2014-11-23 19:06:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-20 19:30:23 +00:00
|
|
|
struct fbotex screen = {
|
|
|
|
.vp_x = p->vp_x,
|
|
|
|
.vp_y = p->vp_y,
|
|
|
|
.vp_w = p->vp_w,
|
|
|
|
.vp_h = p->vp_h,
|
2014-12-02 19:11:20 +00:00
|
|
|
.fbo = fbo,
|
2014-04-20 19:30:23 +00:00
|
|
|
};
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-04-20 19:30:23 +00:00
|
|
|
chain.use_dst = true;
|
|
|
|
chain.dst = p->dst_rect;
|
2014-04-20 19:37:18 +00:00
|
|
|
chain.flags = (p->image_params.rotate % 90 ? 0 : p->image_params.rotate / 90)
|
|
|
|
| (vimg->image_flipped ? 4 : 0);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
gl->UseProgram(p->final_program);
|
|
|
|
GLint loc = gl->GetUniformLocation(p->final_program, "inter_coeff");
|
|
|
|
gl->Uniform1f(loc, inter_coeff);
|
2014-04-20 19:30:23 +00:00
|
|
|
handle_pass(p, &chain, &screen, p->final_program);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
gl->UseProgram(0);
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
unset_image_textures(p);
|
|
|
|
|
2013-05-25 23:48:39 +00:00
|
|
|
p->frames_rendered++;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
debug_check_gl(p, "after video rendering");
|
2014-06-15 21:58:33 +00:00
|
|
|
|
2014-06-18 18:04:59 +00:00
|
|
|
draw_osd:
|
2015-01-29 17:29:28 +00:00
|
|
|
mpgl_osd_draw(p->osd, p->osd_rect, p->osd_pts, p->image_params.stereo_out);
|
2014-12-02 19:11:20 +00:00
|
|
|
|
|
|
|
gl->BindFramebuffer(GL_FRAMEBUFFER, 0);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_window_sized_objects(struct gl_video *p)
|
|
|
|
{
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
int w = p->dst_rect.x1 - p->dst_rect.x0;
|
|
|
|
int h = p->dst_rect.y1 - p->dst_rect.y0;
|
|
|
|
if ((p->image_params.rotate % 180) == 90)
|
|
|
|
MPSWAP(int, w, h);
|
|
|
|
|
|
|
|
// Round up to an arbitrary alignment to make window resizing or
|
|
|
|
// panscan controls smoother (less texture reallocations).
|
|
|
|
int width = FFALIGN(w, 256);
|
|
|
|
int height = FFALIGN(h, 256);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
if (p->scale_sep_program) {
|
|
|
|
if (h > p->scale_sep_fbo.tex_h) {
|
2015-01-29 13:58:26 +00:00
|
|
|
fbotex_uninit(&p->scale_sep_fbo);
|
|
|
|
fbotex_init(&p->scale_sep_fbo, p->gl, p->log, p->image_w, height,
|
|
|
|
p->gl_target, GL_NEAREST, p->opts.fbo_format);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
p->scale_sep_fbo.vp_w = p->image_w;
|
|
|
|
p->scale_sep_fbo.vp_h = h;
|
|
|
|
}
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
|
|
|
|
if (p->opts.smoothmotion) {
|
|
|
|
for (int i = 0; i < FBOSURFACES_MAX; i++) {
|
|
|
|
struct fbotex *fbo = &p->surfaces[i].fbotex;
|
|
|
|
if (w > fbo->tex_w || h > fbo->tex_h) {
|
|
|
|
fbotex_uninit(fbo);
|
|
|
|
fbotex_init(fbo, p->gl, p->log, width, height,
|
|
|
|
p->gl_target, GL_NEAREST, p->opts.fbo_format);
|
|
|
|
}
|
|
|
|
fbo->vp_w = w;
|
|
|
|
fbo->vp_h = h;
|
|
|
|
p->surfaces[i].valid = false;
|
|
|
|
}
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_resize(struct gl_video *p)
|
|
|
|
{
|
|
|
|
bool need_scaler_reinit = false; // filter size change needed
|
|
|
|
bool need_scaler_update = false; // filter LUT change needed
|
|
|
|
bool too_small = false;
|
|
|
|
for (int n = 0; n < 2; n++) {
|
|
|
|
if (p->scalers[n].kernel) {
|
2014-11-28 22:57:06 +00:00
|
|
|
struct filter_kernel old = *p->scalers[n].kernel;
|
|
|
|
update_scale_factor(p, &p->scalers[n]);
|
|
|
|
struct filter_kernel new = *p->scalers[n].kernel;
|
|
|
|
need_scaler_reinit |= (new.size != old.size);
|
|
|
|
need_scaler_update |= (new.inv_scale != old.inv_scale);
|
|
|
|
too_small |= p->scalers[n].insufficient;
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-25 21:47:55 +00:00
|
|
|
for (int n = 0; n < 2; n++) {
|
|
|
|
if (strcmp(p->scalers[n].name, expected_scaler(p, n)) != 0)
|
|
|
|
need_scaler_reinit = true;
|
|
|
|
}
|
2015-01-06 09:47:26 +00:00
|
|
|
if (p->upscaling != (get_scale_factor(p) > 1.0)) {
|
|
|
|
p->upscaling = !p->upscaling;
|
|
|
|
// Switching between upscaling and downscaling also requires sigmoid
|
|
|
|
// to be toggled
|
2015-02-03 16:39:30 +00:00
|
|
|
need_scaler_reinit |= p->sigmoid_enabled;
|
2015-01-06 09:47:26 +00:00
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
if (need_scaler_reinit) {
|
|
|
|
reinit_rendering(p);
|
|
|
|
} else if (need_scaler_update) {
|
|
|
|
init_scaler(p, &p->scalers[0]);
|
|
|
|
init_scaler(p, &p->scalers[1]);
|
|
|
|
}
|
|
|
|
if (too_small) {
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_WARN(p, "Can't downscale that much, window "
|
2014-11-28 22:57:06 +00:00
|
|
|
"output may look suboptimal.\n");
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update_window_sized_objects(p);
|
|
|
|
update_all_uniforms(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_video_resize(struct gl_video *p, struct mp_rect *window,
|
|
|
|
struct mp_rect *src, struct mp_rect *dst,
|
2014-12-09 16:47:02 +00:00
|
|
|
struct mp_osd_res *osd, bool vflip)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
|
|
|
p->src_rect = *src;
|
|
|
|
p->dst_rect = *dst;
|
|
|
|
p->osd_rect = *osd;
|
|
|
|
|
|
|
|
p->vp_x = window->x0;
|
|
|
|
p->vp_y = window->y0;
|
|
|
|
p->vp_w = window->x1 - window->x0;
|
|
|
|
p->vp_h = window->y1 - window->y0;
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
p->vp_vflipped = vflip;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
check_resize(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool get_image(struct gl_video *p, struct mp_image *mpi)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
if (!p->opts.pbo)
|
|
|
|
return false;
|
|
|
|
|
2013-03-28 19:40:19 +00:00
|
|
|
struct video_image *vimg = &p->image;
|
|
|
|
|
2013-08-26 08:09:27 +00:00
|
|
|
// See comments in init_video() about odd video sizes.
|
|
|
|
// The normal upload path does this too, but less explicit.
|
|
|
|
mp_image_set_size(mpi, vimg->planes[0].w, vimg->planes[0].h);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
for (int n = 0; n < p->plane_count; n++) {
|
2013-03-28 19:40:19 +00:00
|
|
|
struct texplane *plane = &vimg->planes[n];
|
|
|
|
mpi->stride[n] = mpi->plane_w[n] * p->image_desc.bytes[n];
|
|
|
|
int needed_size = mpi->plane_h[n] * mpi->stride[n];
|
2013-03-01 20:19:20 +00:00
|
|
|
if (!plane->gl_buffer)
|
|
|
|
gl->GenBuffers(1, &plane->gl_buffer);
|
|
|
|
gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, plane->gl_buffer);
|
|
|
|
if (needed_size > plane->buffer_size) {
|
|
|
|
plane->buffer_size = needed_size;
|
|
|
|
gl->BufferData(GL_PIXEL_UNPACK_BUFFER, plane->buffer_size,
|
|
|
|
NULL, GL_DYNAMIC_DRAW);
|
|
|
|
}
|
|
|
|
if (!plane->buffer_ptr)
|
|
|
|
plane->buffer_ptr = gl->MapBuffer(GL_PIXEL_UNPACK_BUFFER,
|
|
|
|
GL_WRITE_ONLY);
|
|
|
|
mpi->planes[n] = plane->buffer_ptr;
|
|
|
|
gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_video_upload_image(struct gl_video *p, struct mp_image *mpi)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2013-03-28 19:40:19 +00:00
|
|
|
struct video_image *vimg = &p->image;
|
|
|
|
|
2014-06-15 18:46:57 +00:00
|
|
|
p->osd_pts = mpi->pts;
|
|
|
|
|
2015-01-22 17:29:37 +00:00
|
|
|
talloc_free(vimg->mpi);
|
|
|
|
vimg->mpi = mpi;
|
|
|
|
|
|
|
|
if (p->hwdec_active)
|
2013-11-03 23:00:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
assert(mpi->num_planes == p->plane_count);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
mp_image_t mpi2 = *mpi;
|
|
|
|
bool pbo = false;
|
2013-03-28 19:40:19 +00:00
|
|
|
if (!vimg->planes[0].buffer_ptr && get_image(p, &mpi2)) {
|
2013-11-03 23:00:18 +00:00
|
|
|
for (int n = 0; n < p->plane_count; n++) {
|
2013-03-28 19:40:19 +00:00
|
|
|
int line_bytes = mpi->plane_w[n] * p->image_desc.bytes[n];
|
|
|
|
memcpy_pic(mpi2.planes[n], mpi->planes[n], line_bytes, mpi->plane_h[n],
|
2013-03-01 20:19:20 +00:00
|
|
|
mpi2.stride[n], mpi->stride[n]);
|
|
|
|
}
|
|
|
|
pbo = true;
|
|
|
|
}
|
2014-06-18 13:55:01 +00:00
|
|
|
vimg->image_flipped = mpi2.stride[0] < 0;
|
2013-11-03 23:00:18 +00:00
|
|
|
for (int n = 0; n < p->plane_count; n++) {
|
2013-03-28 19:40:19 +00:00
|
|
|
struct texplane *plane = &vimg->planes[n];
|
2014-06-18 13:55:01 +00:00
|
|
|
void *plane_ptr = mpi2.planes[n];
|
2013-03-01 20:19:20 +00:00
|
|
|
if (pbo) {
|
|
|
|
gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, plane->gl_buffer);
|
|
|
|
if (!gl->UnmapBuffer(GL_PIXEL_UNPACK_BUFFER))
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_FATAL(p, "Video PBO upload failed. "
|
|
|
|
"Remove the 'pbo' suboption.\n");
|
2013-03-01 20:19:20 +00:00
|
|
|
plane->buffer_ptr = NULL;
|
|
|
|
plane_ptr = NULL; // PBO offset 0
|
|
|
|
}
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0 + n);
|
2013-12-01 22:39:13 +00:00
|
|
|
gl->BindTexture(p->gl_target, plane->gl_texture);
|
|
|
|
glUploadTex(gl, p->gl_target, plane->gl_format, plane->gl_type,
|
2014-06-18 13:55:01 +00:00
|
|
|
plane_ptr, mpi2.stride[n], 0, 0, plane->w, plane->h, 0);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
2014-12-20 16:22:36 +00:00
|
|
|
if (pbo)
|
|
|
|
gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 09:35:49 +00:00
|
|
|
static bool test_fbo(struct gl_video *p, bool *success)
|
2013-05-30 13:37:13 +00:00
|
|
|
{
|
2015-02-26 09:35:49 +00:00
|
|
|
if (!*success)
|
|
|
|
return false;
|
|
|
|
|
2013-05-30 13:37:13 +00:00
|
|
|
GL *gl = p->gl;
|
2015-02-26 09:35:49 +00:00
|
|
|
*success = false;
|
|
|
|
MP_VERBOSE(p, "Testing user-set FBO format (0x%x)\n",
|
|
|
|
(unsigned)p->opts.fbo_format);
|
2013-05-30 13:37:13 +00:00
|
|
|
struct fbotex fbo = {0};
|
2015-02-26 09:35:49 +00:00
|
|
|
if (fbotex_init(&fbo, p->gl, p->log, 16, 16, p->gl_target, GL_LINEAR,
|
|
|
|
p->opts.fbo_format))
|
2015-01-29 13:58:26 +00:00
|
|
|
{
|
2013-05-30 13:37:13 +00:00
|
|
|
gl->BindFramebuffer(GL_FRAMEBUFFER, fbo.fbo);
|
|
|
|
gl->BindFramebuffer(GL_FRAMEBUFFER, 0);
|
2015-02-26 09:35:49 +00:00
|
|
|
*success = true;
|
2013-05-30 13:37:13 +00:00
|
|
|
}
|
2015-01-29 13:58:26 +00:00
|
|
|
fbotex_uninit(&fbo);
|
2013-09-11 22:57:32 +00:00
|
|
|
glCheckError(gl, p->log, "FBO test");
|
2015-02-26 09:35:49 +00:00
|
|
|
return *success;
|
2013-05-30 13:37:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
// Disable features that are not supported with the current OpenGL version.
|
|
|
|
static void check_gl_features(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
bool have_float_tex = gl->mpgl_caps & MPGL_CAP_FLOAT_TEX;
|
|
|
|
bool have_fbo = gl->mpgl_caps & MPGL_CAP_FB;
|
2014-12-21 20:54:50 +00:00
|
|
|
bool have_arrays = gl->mpgl_caps & MPGL_CAP_1ST_CLASS_ARRAYS;
|
2015-01-17 16:28:47 +00:00
|
|
|
bool have_1d_tex = gl->mpgl_caps & MPGL_CAP_1D_TEX;
|
2014-12-23 01:48:58 +00:00
|
|
|
bool have_3d_tex = gl->mpgl_caps & MPGL_CAP_3D_TEX;
|
2014-03-05 14:01:32 +00:00
|
|
|
bool have_mix = gl->glsl_version >= 130;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
char *disabled[10];
|
|
|
|
int n_disabled = 0;
|
|
|
|
|
|
|
|
// Normally, we want to disable them by default if FBOs are unavailable,
|
|
|
|
// because they will be slow (not critically slow, but still slower).
|
|
|
|
// Without FP textures, we must always disable them.
|
2014-12-16 17:55:02 +00:00
|
|
|
// I don't know if luminance alpha float textures exist, so disregard them.
|
2015-02-26 09:35:49 +00:00
|
|
|
for (int n = 0; n < 2; n++) {
|
|
|
|
const struct filter_kernel *kernel = mp_find_filter_kernel(p->opts.scalers[n]);
|
|
|
|
if (kernel) {
|
|
|
|
char *reason = NULL;
|
|
|
|
if (!test_fbo(p, &have_fbo))
|
|
|
|
reason = "scaler (FBO)";
|
|
|
|
if (!have_float_tex)
|
|
|
|
reason = "scaler (float tex.)";
|
|
|
|
if (!have_arrays)
|
|
|
|
reason = "scaler (no GLSL support)";
|
|
|
|
if (!have_1d_tex && kernel->polar)
|
|
|
|
reason = "scaler (1D tex.)";
|
|
|
|
if (reason) {
|
|
|
|
p->opts.scalers[n] = "bilinear";
|
|
|
|
disabled[n_disabled++] = reason;
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 00:03:08 +00:00
|
|
|
// GLES3 doesn't provide filtered 16 bit integer textures
|
|
|
|
// GLES2 doesn't even provide 3D textures
|
2014-12-23 01:48:58 +00:00
|
|
|
if (p->use_lut_3d && !(have_3d_tex && have_float_tex)) {
|
2014-12-17 20:48:23 +00:00
|
|
|
p->use_lut_3d = false;
|
|
|
|
disabled[n_disabled++] = "color management (GLES unsupported)";
|
|
|
|
}
|
|
|
|
|
2014-12-21 20:54:50 +00:00
|
|
|
// Missing float textures etc. (maybe ordered would actually work)
|
|
|
|
if (p->opts.dither_algo >= 0 && gl->es) {
|
|
|
|
p->opts.dither_algo = -1;
|
|
|
|
disabled[n_disabled++] = "dithering (GLES unsupported)";
|
|
|
|
}
|
|
|
|
|
2014-03-05 14:01:32 +00:00
|
|
|
int use_cms = p->opts.srgb || p->use_lut_3d;
|
|
|
|
|
|
|
|
// srgb_compand() not available
|
|
|
|
if (!have_mix && p->opts.srgb) {
|
2013-03-01 20:19:20 +00:00
|
|
|
p->opts.srgb = false;
|
2014-03-05 14:01:32 +00:00
|
|
|
disabled[n_disabled++] = "sRGB output (GLSL version)";
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
2015-02-26 09:35:49 +00:00
|
|
|
if (use_cms && !test_fbo(p, &have_fbo)) {
|
2014-03-05 14:01:32 +00:00
|
|
|
p->opts.srgb = false;
|
2013-03-01 20:19:20 +00:00
|
|
|
p->use_lut_3d = false;
|
|
|
|
disabled[n_disabled++] = "color management (FBO)";
|
|
|
|
}
|
2015-02-26 09:35:49 +00:00
|
|
|
if (p->opts.smoothmotion && !test_fbo(p, &have_fbo)) {
|
vo_opengl: greatly increase smoothmotion performance
Instead of rendering and upscaling each video frame on every vsync, this
version of the algorithm only draws them once and caches the result,
so the only operation that has to run on every vsync is a cheap linear
interpolation, plus CMS/dithering.
On my machine, this is a huge speedup for 24 Hz content (on a 60 Hz
monitor), up to 120% faster. (The speedup is not quite 250% because of
the overhead that the larger FBOs and CMS provides)
In terms of the implementation, this commit basically swaps
interpolation and upscaling - upscaling is moved to inter_program, and
interpolation is moved to the final_program.
Furthermore, the main bulk of the frame rendering logic (upscaling etc.)
was moved to a separete function, which is called from
gl_video_interpolate_frame only if it's actually necessarily, and
skipped otherwise.
2015-02-20 21:12:02 +00:00
|
|
|
p->opts.smoothmotion = false;
|
|
|
|
disabled[n_disabled++] = "smoothmotion (FBO)";
|
|
|
|
}
|
2015-01-28 12:36:07 +00:00
|
|
|
// because of bt709_expand()
|
|
|
|
if (!have_mix && p->use_lut_3d) {
|
|
|
|
p->use_lut_3d = false;
|
|
|
|
disabled[n_disabled++] = "color management (GLSL version)";
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
2014-12-18 23:15:29 +00:00
|
|
|
if (gl->es && p->opts.pbo) {
|
|
|
|
p->opts.pbo = 0;
|
|
|
|
disabled[n_disabled++] = "PBOs (GLES unsupported)";
|
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
if (n_disabled) {
|
2014-12-16 17:55:02 +00:00
|
|
|
MP_ERR(p, "Some OpenGL extensions not detected, disabling: ");
|
2013-03-01 20:19:20 +00:00
|
|
|
for (int n = 0; n < n_disabled; n++) {
|
|
|
|
if (n)
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_ERR(p, ", ");
|
|
|
|
MP_ERR(p, "%s", disabled[n]);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_ERR(p, ".\n");
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init_gl(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
debug_check_gl(p, "before init_gl");
|
|
|
|
|
|
|
|
check_gl_features(p);
|
|
|
|
|
|
|
|
gl->Disable(GL_DITHER);
|
|
|
|
|
2015-01-28 21:22:29 +00:00
|
|
|
gl_vao_init(&p->vao, gl, sizeof(struct vertex), vertex_vao);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
gl_video_set_gl_state(p);
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2014-12-24 15:54:47 +00:00
|
|
|
// Test whether we can use 10 bit. Hope that testing a single format/channel
|
|
|
|
// is good enough (instead of testing all 1-4 channels variants etc.).
|
|
|
|
const struct fmt_entry *fmt = find_tex_format(gl, 2, 1);
|
|
|
|
if (gl->GetTexLevelParameteriv && fmt->format) {
|
|
|
|
GLuint tex;
|
|
|
|
gl->GenTextures(1, &tex);
|
|
|
|
gl->BindTexture(GL_TEXTURE_2D, tex);
|
|
|
|
gl->TexImage2D(GL_TEXTURE_2D, 0, fmt->internal_format, 64, 64, 0,
|
|
|
|
fmt->format, fmt->type, NULL);
|
|
|
|
GLenum pname = 0;
|
|
|
|
switch (fmt->format) {
|
|
|
|
case GL_RED: pname = GL_TEXTURE_RED_SIZE; break;
|
|
|
|
case GL_LUMINANCE: pname = GL_TEXTURE_LUMINANCE_SIZE; break;
|
|
|
|
}
|
|
|
|
GLint param = 0;
|
|
|
|
if (pname)
|
|
|
|
gl->GetTexLevelParameteriv(GL_TEXTURE_2D, 0, pname, ¶m);
|
|
|
|
if (param) {
|
|
|
|
MP_VERBOSE(p, "16 bit texture depth: %d.\n", (int)param);
|
|
|
|
p->texture_16bit_depth = param;
|
|
|
|
}
|
2015-02-27 21:13:15 +00:00
|
|
|
gl->DeleteTextures(1, &tex);
|
2014-12-24 15:54:47 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
debug_check_gl(p, "after init_gl");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_video_uninit(struct gl_video *p)
|
|
|
|
{
|
2014-12-03 21:37:39 +00:00
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
GL *gl = p->gl;
|
|
|
|
|
|
|
|
uninit_video(p);
|
|
|
|
|
2015-01-28 21:22:29 +00:00
|
|
|
gl_vao_uninit(&p->vao);
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
gl->DeleteTextures(1, &p->lut_3d_texture);
|
|
|
|
|
|
|
|
mpgl_osd_destroy(p->osd);
|
|
|
|
|
2015-01-29 14:50:21 +00:00
|
|
|
gl_set_debug_logger(gl, NULL);
|
2014-12-23 01:46:44 +00:00
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
talloc_free(p);
|
|
|
|
}
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
void gl_video_set_gl_state(struct gl_video *p)
|
|
|
|
{
|
|
|
|
GL *gl = p->gl;
|
|
|
|
|
2014-12-09 20:34:01 +00:00
|
|
|
struct m_color c = p->opts.background;
|
|
|
|
gl->ClearColor(c.r / 255.0, c.g / 255.0, c.b / 255.0, c.a / 255.0);
|
2014-12-09 16:47:02 +00:00
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
2015-01-22 17:54:05 +00:00
|
|
|
if (gl->mpgl_caps & MPGL_CAP_ROW_LENGTH)
|
2014-12-18 23:58:56 +00:00
|
|
|
gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gl_video_unset_gl_state(struct gl_video *p)
|
|
|
|
{
|
2015-01-28 21:22:29 +00:00
|
|
|
/* nop */
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2014-11-23 19:06:05 +00:00
|
|
|
void gl_video_reset(struct gl_video *p)
|
|
|
|
{
|
2015-01-29 14:50:21 +00:00
|
|
|
for (int i = 0; i < FBOSURFACES_MAX; i++)
|
2014-11-23 19:06:05 +00:00
|
|
|
p->surfaces[i].pts = 0;
|
2015-01-29 14:50:21 +00:00
|
|
|
p->surface_idx = 0;
|
2014-11-23 19:06:05 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 22:37:38 +00:00
|
|
|
bool gl_video_showing_interpolated_frame(struct gl_video *p)
|
|
|
|
{
|
|
|
|
return p->is_interpolated;
|
|
|
|
}
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
// dest = src.<w> (always using 4 components)
|
2014-12-16 17:55:02 +00:00
|
|
|
static void packed_fmt_swizzle(char w[5], const struct fmt_entry *texfmt,
|
|
|
|
const struct packed_fmt_entry *fmt)
|
2013-07-18 11:52:38 +00:00
|
|
|
{
|
2014-12-16 17:55:02 +00:00
|
|
|
const char *comp = "rgba";
|
|
|
|
|
2014-12-18 13:46:19 +00:00
|
|
|
// Normally, we work with GL_RG
|
2014-12-16 17:55:02 +00:00
|
|
|
if (texfmt && texfmt->internal_format == GL_LUMINANCE_ALPHA)
|
|
|
|
comp = "ragb";
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
for (int c = 0; c < 4; c++)
|
2014-12-16 17:55:02 +00:00
|
|
|
w[c] = comp[MPMAX(fmt->components[c] - 1, 0)];
|
2013-07-18 11:52:38 +00:00
|
|
|
w[4] = '\0';
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
static bool init_format(int fmt, struct gl_video *init)
|
|
|
|
{
|
2014-12-16 17:55:02 +00:00
|
|
|
struct GL *gl = init->gl;
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
init->hwdec_active = false;
|
2013-11-29 13:19:51 +00:00
|
|
|
if (init->hwdec && init->hwdec->driver->imgfmt == fmt) {
|
2013-11-03 23:00:18 +00:00
|
|
|
fmt = init->hwdec->converted_imgfmt;
|
|
|
|
init->hwdec_active = true;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt);
|
|
|
|
if (!desc.id)
|
|
|
|
return false;
|
|
|
|
|
2013-03-28 19:48:53 +00:00
|
|
|
if (desc.num_planes > 4)
|
|
|
|
return false;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
const struct fmt_entry *plane_format[4] = {0};
|
2013-03-28 19:48:53 +00:00
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
init->color_swizzle[0] = '\0';
|
|
|
|
init->has_alpha = false;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
// YUV/planar formats
|
2014-03-01 14:40:46 +00:00
|
|
|
if (desc.flags & MP_IMGFLAG_YUV_P) {
|
2015-01-21 18:29:18 +00:00
|
|
|
int bits = desc.component_bits;
|
2013-03-28 19:48:53 +00:00
|
|
|
if ((desc.flags & MP_IMGFLAG_NE) && bits >= 8 && bits <= 16) {
|
2013-07-18 11:52:38 +00:00
|
|
|
init->has_alpha = desc.num_planes > 3;
|
2014-12-16 17:55:02 +00:00
|
|
|
plane_format[0] = find_tex_format(gl, (bits + 7) / 8, 1);
|
2013-07-18 11:52:38 +00:00
|
|
|
for (int p = 1; p < desc.num_planes; p++)
|
|
|
|
plane_format[p] = plane_format[0];
|
2014-03-01 14:40:46 +00:00
|
|
|
goto supported;
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 20:02:41 +00:00
|
|
|
// YUV/half-packed
|
2014-03-01 14:40:46 +00:00
|
|
|
if (fmt == IMGFMT_NV12 || fmt == IMGFMT_NV21) {
|
2014-12-16 17:55:02 +00:00
|
|
|
if (!(init->gl->mpgl_caps & MPGL_CAP_TEX_RG))
|
|
|
|
return false;
|
|
|
|
plane_format[0] = find_tex_format(gl, 1, 1);
|
|
|
|
plane_format[1] = find_tex_format(gl, 1, 2);
|
2013-07-18 11:52:38 +00:00
|
|
|
if (fmt == IMGFMT_NV21)
|
|
|
|
snprintf(init->color_swizzle, sizeof(init->color_swizzle), "rbga");
|
2014-03-01 14:40:46 +00:00
|
|
|
goto supported;
|
2013-03-28 20:02:41 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
// RGB/planar
|
2014-03-01 14:40:46 +00:00
|
|
|
if (fmt == IMGFMT_GBRP) {
|
2013-07-18 11:52:38 +00:00
|
|
|
snprintf(init->color_swizzle, sizeof(init->color_swizzle), "brga");
|
2014-12-16 17:55:02 +00:00
|
|
|
plane_format[0] = find_tex_format(gl, 1, 1);
|
2013-07-18 11:52:38 +00:00
|
|
|
for (int p = 1; p < desc.num_planes; p++)
|
|
|
|
plane_format[p] = plane_format[0];
|
2014-03-01 14:40:46 +00:00
|
|
|
goto supported;
|
2013-03-28 19:48:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 20:58:21 +00:00
|
|
|
// XYZ (same organization as RGB packed, but requires conversion matrix)
|
2014-03-01 14:40:46 +00:00
|
|
|
if (fmt == IMGFMT_XYZ12) {
|
2014-12-16 17:55:02 +00:00
|
|
|
plane_format[0] = find_tex_format(gl, 2, 3);
|
2014-03-01 14:40:46 +00:00
|
|
|
goto supported;
|
2013-05-01 21:59:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
// Packed RGB special formats
|
2014-03-01 14:40:46 +00:00
|
|
|
for (const struct fmt_entry *e = mp_to_gl_formats; e->mp_format; e++) {
|
2014-12-20 18:23:17 +00:00
|
|
|
if (!gl->es && e->mp_format == fmt) {
|
2014-03-01 14:40:46 +00:00
|
|
|
plane_format[0] = e;
|
|
|
|
goto supported;
|
2013-07-18 11:52:38 +00:00
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
// Packed RGB(A) formats
|
2014-03-01 14:40:46 +00:00
|
|
|
for (const struct packed_fmt_entry *e = mp_packed_formats; e->fmt; e++) {
|
|
|
|
if (e->fmt == fmt) {
|
|
|
|
int n_comp = desc.bytes[0] / e->component_size;
|
2014-12-16 17:55:02 +00:00
|
|
|
plane_format[0] = find_tex_format(gl, e->component_size, n_comp);
|
|
|
|
packed_fmt_swizzle(init->color_swizzle, plane_format[0], e);
|
2014-03-01 14:40:46 +00:00
|
|
|
init->has_alpha = e->components[3] != 0;
|
|
|
|
goto supported;
|
2013-03-28 19:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-13 20:52:34 +00:00
|
|
|
// Packed YUV Apple formats
|
|
|
|
if (init->gl->mpgl_caps & MPGL_CAP_APPLE_RGB_422) {
|
|
|
|
for (const struct fmt_entry *e = gl_apple_formats; e->mp_format; e++) {
|
|
|
|
if (e->mp_format == fmt) {
|
|
|
|
init->is_packed_yuv = true;
|
|
|
|
snprintf(init->color_swizzle, sizeof(init->color_swizzle),
|
|
|
|
"gbra");
|
|
|
|
plane_format[0] = e;
|
2014-03-01 14:40:46 +00:00
|
|
|
goto supported;
|
2013-11-13 20:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-01 14:40:46 +00:00
|
|
|
// Unsupported format
|
|
|
|
return false;
|
|
|
|
|
|
|
|
supported:
|
2013-07-18 11:52:38 +00:00
|
|
|
|
2013-03-28 20:44:27 +00:00
|
|
|
// Stuff like IMGFMT_420AP10. Untested, most likely insane.
|
2015-01-29 14:50:21 +00:00
|
|
|
if (desc.num_planes == 4 && (desc.component_bits % 8) != 0)
|
2013-03-28 20:44:27 +00:00
|
|
|
return false;
|
|
|
|
|
2015-01-29 14:50:21 +00:00
|
|
|
if (desc.component_bits > 8 && desc.component_bits < 16) {
|
2014-12-24 15:54:47 +00:00
|
|
|
if (init->texture_16bit_depth < 16)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-17 20:48:23 +00:00
|
|
|
for (int p = 0; p < desc.num_planes; p++) {
|
|
|
|
if (!plane_format[p]->format)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-18 11:52:38 +00:00
|
|
|
for (int p = 0; p < desc.num_planes; p++) {
|
|
|
|
struct texplane *plane = &init->image.planes[p];
|
|
|
|
const struct fmt_entry *format = plane_format[p];
|
|
|
|
assert(format);
|
|
|
|
plane->gl_format = format->format;
|
|
|
|
plane->gl_internal_format = format->internal_format;
|
|
|
|
plane->gl_type = format->type;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
init->is_yuv = desc.flags & MP_IMGFLAG_YUV;
|
2013-05-01 21:13:39 +00:00
|
|
|
init->is_rgb = desc.flags & MP_IMGFLAG_RGB;
|
2013-03-28 20:02:53 +00:00
|
|
|
init->plane_count = desc.num_planes;
|
2013-03-28 19:40:19 +00:00
|
|
|
init->image_desc = desc;
|
2013-03-01 20:19:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
bool gl_video_check_format(struct gl_video *p, int mp_format)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2013-11-03 23:00:18 +00:00
|
|
|
struct gl_video tmp = *p;
|
|
|
|
return init_format(mp_format, &tmp);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 23:35:44 +00:00
|
|
|
void gl_video_config(struct gl_video *p, struct mp_image_params *params)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2015-01-22 17:29:37 +00:00
|
|
|
mp_image_unrefp(&p->image.mpi);
|
2013-11-05 18:08:44 +00:00
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
if (!mp_image_params_equal(&p->real_image_params, params)) {
|
2013-11-05 18:08:44 +00:00
|
|
|
uninit_video(p);
|
2015-01-29 18:53:49 +00:00
|
|
|
p->real_image_params = *params;
|
|
|
|
p->image_params = *params;
|
2014-12-09 20:36:45 +00:00
|
|
|
if (params->imgfmt)
|
2015-01-29 18:53:49 +00:00
|
|
|
init_video(p);
|
2013-11-05 18:08:44 +00:00
|
|
|
}
|
2014-11-07 14:28:12 +00:00
|
|
|
|
|
|
|
check_resize(p);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gl_video_set_output_depth(struct gl_video *p, int r, int g, int b)
|
|
|
|
{
|
2013-07-31 19:44:21 +00:00
|
|
|
MP_VERBOSE(p, "Display depth: R=%d, G=%d, B=%d\n", r, g, b);
|
2013-03-01 20:19:20 +00:00
|
|
|
p->depth_g = g;
|
|
|
|
}
|
|
|
|
|
2014-06-15 18:46:57 +00:00
|
|
|
struct gl_video *gl_video_init(GL *gl, struct mp_log *log, struct osd_state *osd)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2015-01-21 19:32:42 +00:00
|
|
|
if (gl->version < 210 && gl->es < 200) {
|
2014-12-22 11:49:20 +00:00
|
|
|
mp_err(log, "At least OpenGL 2.1 or OpenGL ES 2.0 required.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:19:20 +00:00
|
|
|
struct gl_video *p = talloc_ptrtype(NULL, p);
|
|
|
|
*p = (struct gl_video) {
|
|
|
|
.gl = gl,
|
2013-07-31 19:44:21 +00:00
|
|
|
.log = log,
|
2014-06-15 18:46:57 +00:00
|
|
|
.osd_state = osd,
|
2013-03-01 20:19:20 +00:00
|
|
|
.opts = gl_video_opts_def,
|
2013-12-01 22:39:13 +00:00
|
|
|
.gl_target = GL_TEXTURE_2D,
|
2014-12-24 15:54:47 +00:00
|
|
|
.texture_16bit_depth = 16,
|
2015-02-03 16:12:04 +00:00
|
|
|
.user_gamma = 1.0f,
|
2013-03-01 20:19:20 +00:00
|
|
|
.scalers = {
|
|
|
|
{ .index = 0, .name = "bilinear" },
|
|
|
|
{ .index = 1, .name = "bilinear" },
|
|
|
|
},
|
|
|
|
.scratch = talloc_zero_array(p, char *, 1),
|
|
|
|
};
|
2014-12-23 01:46:44 +00:00
|
|
|
gl_video_set_debug(p, true);
|
2013-03-01 20:19:20 +00:00
|
|
|
init_gl(p);
|
|
|
|
recreate_osd(p);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get static string for scaler shader.
|
2015-01-22 18:58:22 +00:00
|
|
|
static const char *handle_scaler_opt(const char *name)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2015-01-26 01:03:44 +00:00
|
|
|
if (name && name[0]) {
|
2013-03-01 20:19:20 +00:00
|
|
|
const struct filter_kernel *kernel = mp_find_filter_kernel(name);
|
2015-01-26 00:56:19 +00:00
|
|
|
if (kernel)
|
2013-03-01 20:19:20 +00:00
|
|
|
return kernel->name;
|
|
|
|
|
2014-06-10 21:56:05 +00:00
|
|
|
for (const char *const *filter = fixed_scale_filters; *filter; filter++) {
|
2013-03-01 20:19:20 +00:00
|
|
|
if (strcmp(*filter, name) == 0)
|
|
|
|
return *filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the options, and possibly update the filter chain too.
|
|
|
|
// Note: assumes all options are valid and verified by the option parser.
|
|
|
|
void gl_video_set_options(struct gl_video *p, struct gl_video_opts *opts)
|
|
|
|
{
|
|
|
|
p->opts = *opts;
|
|
|
|
for (int n = 0; n < 2; n++) {
|
|
|
|
p->opts.scalers[n] = (char *)handle_scaler_opt(p->opts.scalers[n]);
|
2015-01-20 13:33:53 +00:00
|
|
|
p->opts.dscaler = (char *)handle_scaler_opt(p->opts.dscaler);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_gl_features(p);
|
|
|
|
reinit_rendering(p);
|
2015-01-22 18:25:16 +00:00
|
|
|
check_resize(p);
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 23:25:08 +00:00
|
|
|
void gl_video_get_colorspace(struct gl_video *p, struct mp_image_params *params)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2014-03-28 23:25:08 +00:00
|
|
|
*params = p->image_params; // supports everything
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 16:34:29 +00:00
|
|
|
struct mp_csp_equalizer *gl_video_eq_ptr(struct gl_video *p)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2015-01-06 16:34:29 +00:00
|
|
|
return &p->video_eq;
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 16:34:29 +00:00
|
|
|
// Call when the mp_csp_equalizer returned by gl_video_eq_ptr() was changed.
|
|
|
|
void gl_video_eq_update(struct gl_video *p)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2015-02-03 16:12:04 +00:00
|
|
|
update_settings(p);
|
|
|
|
|
|
|
|
if (p->need_reinit_rendering) {
|
|
|
|
reinit_rendering(p);
|
|
|
|
check_resize(p);
|
|
|
|
} else {
|
|
|
|
update_all_uniforms(p);
|
2015-01-06 16:34:29 +00:00
|
|
|
}
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 19:03:36 +00:00
|
|
|
static int validate_scaler_opt(struct mp_log *log, const m_option_t *opt,
|
|
|
|
struct bstr name, struct bstr param)
|
2013-03-01 20:19:20 +00:00
|
|
|
{
|
2015-01-22 18:58:22 +00:00
|
|
|
char s[20] = {0};
|
|
|
|
int r = 1;
|
2013-07-22 00:14:15 +00:00
|
|
|
if (bstr_equals0(param, "help")) {
|
2015-01-22 18:58:22 +00:00
|
|
|
r = M_OPT_EXIT - 1;
|
|
|
|
} else {
|
|
|
|
snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
|
|
|
|
if (!handle_scaler_opt(s))
|
|
|
|
r = M_OPT_INVALID;
|
|
|
|
}
|
|
|
|
if (r < 1) {
|
2013-12-21 19:03:36 +00:00
|
|
|
mp_info(log, "Available scalers:\n");
|
2014-06-10 21:56:05 +00:00
|
|
|
for (const char *const *filter = fixed_scale_filters; *filter; filter++)
|
2013-12-21 19:03:36 +00:00
|
|
|
mp_info(log, " %s\n", *filter);
|
2013-07-22 00:14:15 +00:00
|
|
|
for (int n = 0; mp_filter_kernels[n].name; n++)
|
2013-12-21 19:03:36 +00:00
|
|
|
mp_info(log, " %s\n", mp_filter_kernels[n].name);
|
2015-01-22 18:58:22 +00:00
|
|
|
if (s[0])
|
|
|
|
mp_fatal(log, "No scaler named '%s' found!\n", s);
|
2013-07-22 00:14:15 +00:00
|
|
|
}
|
2015-01-22 18:58:22 +00:00
|
|
|
return r;
|
2013-03-01 20:19:20 +00:00
|
|
|
}
|
2013-03-15 19:17:33 +00:00
|
|
|
|
2014-10-18 16:30:22 +00:00
|
|
|
// Resize and redraw the contents of the window without further configuration.
|
|
|
|
// Intended to be used in situations where the frontend can't really be
|
|
|
|
// involved with reconfiguring the VO properly.
|
|
|
|
// gl_video_resize() should be called when user interaction is done.
|
|
|
|
void gl_video_resize_redraw(struct gl_video *p, int w, int h)
|
|
|
|
{
|
|
|
|
p->vp_w = w;
|
|
|
|
p->vp_h = h;
|
2014-11-23 19:06:05 +00:00
|
|
|
gl_video_render_frame(p, 0, NULL);
|
2014-10-18 16:30:22 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 23:00:18 +00:00
|
|
|
void gl_video_set_hwdec(struct gl_video *p, struct gl_hwdec *hwdec)
|
|
|
|
{
|
|
|
|
p->hwdec = hwdec;
|
2015-01-22 17:29:37 +00:00
|
|
|
mp_image_unrefp(&p->image.mpi);
|
2013-11-03 23:00:18 +00:00
|
|
|
}
|