summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/video.c
Commit message (Collapse)AuthorAgeFilesLines
* vo_opengl: skip tonemapping if the output trc is HDRNiklas Haas2016-05-161-1/+3
| | | | | | | | | | | | | This makes it so that users with actual HDR displays can just set their config to target-trc=st2084 and get native HDR output. This will look a bit silly for SDR content (everything will be really bright), but for lack of a better tone mapping situation (including reverse tone mapping) this is the easiest thing to do for now. Ideally the brightness metadata should be part of the colorspace struct or something (with mpv always adapting where necessary), but it depends on the TRC and not the primaries so it's a bit more complicated than that.
* vo_opengl: copy over HDR parameters to dumb_modeNiklas Haas2016-05-161-0/+3
| | | | | | Since dumb mode is affected by tone mapping (which I'll call a feature, not a bug), we need to copy over the configuration - in particular, the defaults. (To prevent a render failure)
* vo_opengl: fall back to gamma2.2 by default for HDR contentNiklas Haas2016-05-161-2/+7
| | | | | | | | | | | Since HDR content is now auto-detected as such, we should probably do something smarter in the "no configuration" case, such as outputting gamma 2.2 instead. This decision will affect the majority of users of stock configurations who just play back appropriately tagged HDR files, so having a good default behavior is important. "Output the HDR content as-is" is definitely not likely to give the user a good result.
* vo_opengl: remove unnecessary castswm42016-05-161-11/+11
|
* vo_opengl: remove another unneeded allocationwm42016-05-161-3/+1
|
* vo_opengl: remove possibly undefined behaviorwm42016-05-161-1/+3
|
* vo_opengl: free to-be-added hook on hook array overflowwm42016-05-161-0/+3
| | | | | | Seems sensible. Untested.
* vo_opengl: never clear file cachewm42016-05-161-12/+4
| | | | | | | | | Make it dynamic and never remove entries from it. For now, this is better than possibly creating dangling pointers all over the place in the gl_user_shader struct. Untested.
* vo_opengl: implement more HDR tonemapping algorithmsNiklas Haas2016-05-161-4/+13
| | | | | | | | | | | | | | | | | | | | | This is now a configurable option, with tunable parameters. I got inspiration for these algorithms off wikipedia. "simple" seems to work pretty well, but not well enough to make it a reasonable default. Some other notable candidates: - Local functions (e.g. based on local contrast or gradient) - Clamp with soft knee (linear up to a point) - Mapping in CIE L*Ch. Map L smoothly, clamp C and h. - Color appearance models These will have to be implemented some other time. Note that the parameter "peak_src" to pass_tone_map should, in principle, be auto-detected from the SEI information of the source file where available. This will also have to be implemented in a later commit.
* vo_opengl: avoid redundant double-gamma conversionNiklas Haas2016-05-161-3/+3
| | | | | | | | | | | | Due to the way color management in mpv worked historically, the subtitle blending function was written to preserve the linearity of the input. (In the past, the 3DLUT function required linear inputs) Since the 3DLUT was refactored to accept the video color directly, the re-linearization after blending is now virtually always redundant. (Notably, it's also redundant when CMS is turned off, so this way of writing the code stopped making sense a long time ago. It is a remnant from before the pass_colormanage function was as flexible as it is now)
* vo_opengl: implement HDR (SMPTE ST2084)Niklas Haas2016-05-161-3/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, this relies on the user manually entering their display brightness (since we have no way to detect this at runtime or from ICC metadata). The default value of 250 was picked by looking at ~10 reviews on tftcentral.co.uk and realizing they all come with around 250 cd/m^2 out of the box. (In addition, ITU-R Rec. BT.2022 supports this) Since there is no metadata in FFmpeg to indicate usage of this TRC, the only way to actually play HDR content currently is to set ``--vf=format=gamma=st2084``. (It could be guessed based on SEI, but this is not implemented yet) Incidentally, since SEI is ignored, it's currently assumed that all content is scaled to 10,000 cd/m^2 (and hard-clipped where out of range). I don't see this assumption changing much, though. As an unfortunate consequence of the fact that we don't know the display brightness, mixed with the fact that LittleCMS' parametric tone curves are not flexible enough to support PQ, we have to build the 3DLUT against gamma 2.2 if it's used. This might be a good thing, though, consdering the PQ source space is probably not fantastic for interpolation either way. Partially addresses #2572.
* vo_opengl: use enums for choice options internallyNiklas Haas2016-05-161-28/+31
| | | | | | This is much more readable than hard-coding magic IDs all over the file, and removes the need for all the explanatory comments that were a direct result of this.
* vo_opengl: abstract hook texture access behind macroNiklas Haas2016-05-151-66/+63
| | | | | | | | | | | | | | | | | | | | | | | | This macro takes care of rotation, swizzling, integer conversion and normalization automatically. I found the performance impact to be nonexistant for superxbr and debanding, although rotation *did* have an impact due to the extra matrix multiplication. (So it gets skipped where possible) All of the internal hooks have been rewritten to use this new mechanism, and the prescaler hooks have finally been separated from each other. This also means the prescale FBO kludge is no longer required. This fixes image corruption for image formats like 0bgr, and also fixes prescaling under rotation. (As well as other user hooks that have orientation-dependent access) The "raw" attributes (tex, tex_pos, pixel_size) are still un-rotated, in case something needs them, but ideally the hooks should be rewritten to use the new API as much as possible. The hooked texture has been renamed from just NAME to NAME_raw to make script authors notice the change (and also deemphasize direct texture access). This is also a step towards getting rid of the use_integer pass.
* vo_opengl: make the screen blue on shader errorsNiklas Haas2016-05-151-0/+11
| | | | | This helps visually signify that somthing went wrong, and prevents confusing shader compilation errors with other types of bugs.
* vo_opengl: use RPN expressions for user hook sizesNiklas Haas2016-05-151-1/+88
| | | | | | | | | This replaces the previous TRANSFORM by WIDTH, HEIGHT and OFFSET where WIDTH and HEIGHT are RPN expressions. This allows for more fine-grained control over the output size, and also makes sure that overwriting existing textures works more cleanly. (Also add some more useful bstr functions)
* vo_opengl: support external user hooksNiklas Haas2016-05-151-33/+110
| | | | | | | | | | | This allows users to add their own near-arbitrary hooks to the vo_opengl processing pipeline, greatly enhancing the flexibility of user shaders. This enables, among other things, user shaders such as CrossBilateral, SuperRes, LumaSharpen and many more. To make parsing the user shaders easier, shaders are now loaded as bstrs, and the hooks are set up during video reconfig instead of on every single frame.
* vo_opengl: add optional hook pointsNiklas Haas2016-05-151-85/+138
| | | | | | | | | | | | | | These are "sequence points" where the image could be rendered out to an FBO, hooked, and re-loaded if any such hook exists. This is perfect for things like the current user shaders system, as well as optional effects like unsharp masking. Note that since we have to pick *some* FBO to store the optionally hooked texture, we just store it in an array indexed by an increasing counter. Since we only ever store as many as MAX_TEXTURE_HOOKS + all internal hook points entries, this is guaranteed to be enough space. This commit also removes some of the now unused FBOs.
* vo_opengl: add hooks and rework pass_read_videoNiklas Haas2016-05-151-232/+440
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The hook mechanism allows arbitrary processing stages to get dispatched whenever certain named textures have been "finalized" by the code. This is mostly meant to serve as a change that opens up the internal processing in pass_read_video to user scripts, but as a side benefit all of the code dealing with offsets and plane alignment and other such confusing things has been rewritten. This hook mechanism is powerful enough to cover the needs of both debanding and prescaling (and more), so as a result they can be removed from pass_read_video entirely and implemented through hooks. Some avenues for optimization: - The prescale hook is currently somewhat distributed code-wise. It might be cleaner to split it into superxbr and NNEDI3 hooks which can each be self-contained. - It might be possible to move a large part of the hook code out to an external file (including the hook definitions for debanding and prescaling), which would be very much desired. - Currently, some stages (chroma merging, integer conversion) will *always* run even if unnecessary. I'm planning another series of refactors (deferred img_tex) to allow dropping unnecessary shader stages like these, but that's probably some ways away. In the meantime it would be doable to re-add some of the logic to skip these stages if we know we don't need them. - More hook locations could be added (?)
* vo_opengl: minor change to scaler_resizes_onlyNiklas Haas2016-05-151-3/+6
| | | | | | Instead of rounding down, we round to the nearest float. This reduces the maximum possible error introduced by this rounding operation. Also clarify the comment.
* vo_opengl: partially fix 0bgr format supportwm42016-05-131-2/+6
| | | | | | | | | | | | | | | | | | | Fixes broken colors with --vf=format=0bgr (but only if deband is disabled). 0bgr means the first byte is padding, while the following three bytes are bgr. From the vo_opengl perspective, it has 4 physical components with 3 logical components. copy_img_tex() simply copied 3 components from the physical representation, which means the last component (r) was sliced off. Fix this by not using p->color_swizzle for packed formats, and instead let packed formats set the per-plane swizzle in texplane.swizzle. The latter applies the swizzle as part of operation in copy_img_tex(), which essentially moves physical to logical representations. Unfortunately, debanding (and thus with opengl-hq defaults) is still broken.
* vo_opengl: drop duplicate LUMINANCE_ALPHA handlingwm42016-05-131-10/+3
| | | | | | This was supposed to handle the absence of GL_ARB_texture_rg. But it's already handled elsewhere. (init_format() sets texplane.swizzle accordingly.)
* vo_opengl: minor simplificationwm42016-05-131-8/+8
| | | | | | | | Make the find_plane_format function take a bit count. This also makes the function's comment true for the first time the function and its comment exist. (It was commented as taking bits, but always took bytes.)
* vo_opengl: slightly better FBO format checkwm42016-05-121-9/+17
| | | | | | | | | | | Now that we know in advance whether an implementation should support a specific format, we have more flexibility when determining which format to use. In particular, we can drop the roundabout ES logic. I'm not sure if actually trying to create the FBO for probing still has any value. But it might, so leave it for now.
* vo_opengl: disable scalers on ES2wm42016-05-121-4/+6
| | | | | | | | Even if everything else is available, the need for first class arrays breaks it. In theory we could fix this since we don't strictly need them, but I guess it's not worth bothering. Also give the misnamed have_mix variable a slightly better name.
* vo_opengl: reorganize texture format handlingwm42016-05-121-165/+40
| | | | | | | | | | | | | This merges all knowledge about texture format into a central table. Most of the work done here is actually identifying which formats exactly are supported by OpenGL(ES) under which circumstances, and keeping this information in the format table in a somewhat declarative way. (Although only to the extend needed by mpv.) In particular, ES and float formats are a horrible mess. Again this is a big refactor that might cause regression on "obscure" configurations.
* vo_opengl: correctly disable interpolation if tscale can't be usedwm42016-05-121-0/+2
| | | | It'll fail with an assertion in the interpolation code otherwise.
* vo_opengl: don't use dumb-mode with 10 bit integer texture hackwm42016-05-111-2/+3
| | | | | Recent regression. Caused it to use dumb-mode with integer textures, which on ANGLE leads to nearest scaling.
* vo_opengl: fix passing along swizzle from hwdec interopwm42016-05-101-0/+2
| | | | | | | | | | In theory this was needed for the previous commit (but wasn't in practice, since for hwdec the LUMINANCE_ALPHA mangling is not applied anymore, and ANGLE uses RG textures in absence of GL_ARB_texture_rg for whatever crazy reasons). In practice this caused funky colors on OSX with the uyvy422 format, which is also fixed in this commit.
* vo_opengl: cosmetics: rename variableswm42016-05-101-17/+16
| | | | | "p" is used for the private context everywhere in the source file, but renaming it also requires renaming some local variables.
* vo_opengl: refactor how hwdec interop exports textureswm42016-05-101-82/+125
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a struct gl_hwdec_frame describing the exact texture layout. This gives more flexibility to what the hwdec interop can export. In particular, it can export strange component orders/permutations and textures with padded size. (The latter originating from cropped video.) The way gl_hwdec_frame works is in the spirit of the rest of the vo_opengl video processing code, which tends to put as much information in immediate state (as part of the dataflow), instead of declaring it globally. To some degree this duplicates the texplane and img_tex structs, but until we somehow unify those, it's better to give the hwdec state its own struct. The fact that changing the hwdec struct would require changes and testing on at least 4 platform/GPU combinations makes duplicating it almost a requirement to avoid pain later. Make gl_hwdec_driver.reinit set the new image format and remove the gl_hwdec.converted_imgfmt field. Likewise, gl_hwdec.gl_texture_target is replaced with gl_hwdec_plane.gl_target. Split out a init_image_desc function from init_format. The latter is not called in the hwdec case at all anymore. Setting up most of struct texplane is also completely separate in the hwdec and normal cases. video.c does not check whether the hwdec "mapped" image format is supported. This should not really happen anyway, and if it does, the hwdec interop backend must fail at creation time, so this is not an issue.
* vo_opengl: support GL_EXT_texture_norm16 on GLESwm42016-04-271-6/+5
| | | | | | | | | | | | | | | This gives us 16 bit fixed-point integer texture formats, including ability to sample from them with linear filtering, and using them as FBO attachments. The integer texture format path is still there for the sake of ANGLE, which does not support GL_EXT_texture_norm16 yet. The change to pass_dither() is needed, because the code path using GL_R16 for the dither texture relies on glTexImage2D being able to convert from GL_FLOAT to GL_R16. GLES does not allow this. This could be trivially fixed by doing the conversion ourselves, but I'm too lazy to do this now.
* vo_opengl: always use sized internal formatswm42016-04-271-8/+8
| | | | | This shouldn't make much of a difference, but should make the following commit simpler.
* vo_opengl: print error if opengl hwdec interop failswm42016-04-271-0/+2
|
* vo_opengl: always reset some GL state when leaving rendererwm42016-04-221-5/+6
| | | | | | The active texture and some pixelstore parameters are now always reset to defaults when entering and leaving the renderer. Could be important for libmpv.
* vo_opengl: improve rotation handling (again)wm42016-04-081-43/+47
| | | | | | | | | | | | | | | | | Apply basic transformations like rotation by 90° and mirroring when sampling from the source textures. The original idea was making this part of img_tex.transform, but this didn't work: lots of code plays tricks on the transform, so manipulating it is not necessarily transparent, especially when width/height are switched. So add a new pre_transform field, which is strictly applied before the normal transform. This fixes most glitches involved with rotating the image. Cropping and rotation are now weirdly separated, even though they could be done in the same step. I think this is not much of a problem, and has the advantage that changing panscan does not trigger FBO reallocations (I think...).
* vo_opengl: minor simplificationwm42016-04-051-3/+2
| | | | It's the same functionally.
* vo_opengl: fix nnedi + rectangle textureswm42016-04-051-1/+1
| | | | Shader compilation error due to incompatible samplers.
* vo_opengl: generate 3DLUT against source and use full BT.1886Niklas Haas2016-04-011-29/+43
| | | | | | | | | | | | | | | | | | | This commit refactors the 3DLUT loading mechanism to build the 3DLUT against the original source characteristics of the file. This allows us, among other things, to use a real BT.1886 profile for the source. This also allows us to actually use perceptual mappings. Finally, this reduces errors on standard gamut displays (where the previous 3DLUT target of BT.2020 was unreasonably wide). This also improves the overall accuracy of the 3DLUT due to eliminating rounding errors where possible, and allows for more accurate use of LUT-based ICC profiles. The current code is somewhat more ugly than necessary, because the idea was to implement this commit in a working state first, and then maybe refactor the profile loading mechanism in a later commit. Fixes #2815.
* vo_opengl: draw transparency checkerboard after upscalingNiklas Haas2016-03-291-4/+10
| | | | | | | | | | | | | This also draws it after color management etc. In a nutshell, this change makes the transparency checkerboard independent of upscaling, panning, cropping etc. It will always be the same apparent size and position (relative to the window). It will also be independent of the video colorspace and such things. (Note: This might cause white imbalance issues if playing a file with a white point that does not match the display, in absolute colorimetric mode. But that's uncommon, especially in conjunction with transparent image files, so it's not a primary concern here)
* vo_opengl: always premultiply alphawm42016-03-291-2/+1
| | | | | | Until now, we've let the windowing backend decide. But since they usually require premultiplied alpha, and premultiplied alpha is easier to handle, hardcode it.
* vo_opengl: fix rotation directionwm42016-03-291-1/+1
| | | | | | The recent changes fixed rotation handling, but reversed the rotation direction. The direction is expected to be counter-clockwise, because demuxers export video rotation metadata as such.
* vo_opengl: fix rotationwm42016-03-281-48/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | This has been completely broken since commit 93546f0c. But even before, rotation handling did not make too much sense. In particular, it rotated the contents of the cropped image, instead of adjusting the crop rectangle as well. The result was that things like panscan or zooming did not behave as expected with rotation applied. The same is true for vertical flipping. Flipping is triggered by negative image stride. OpenGL does not support flipping the image on upload, so it's done as part of the rendering. It can be triggered with --vf=flip, but other filters and even decoders could setup negative stride to flip the image. Fix these issues by applying transforms to texture coordinates properly, and by making rotation and flipping part of these transforms. This still doesn't work properly for separated scaling. The issue is that we'd have to adjust how the passes are done. For now, pick a very stupid solution by rotating the image to a FBO, and then scaling from that. This has the avantage that the scale logic doesn't have to be complicated for such a rare case. It could be improved later. Prescaling is apparently still broken. I don't know if chroma positioning works properly either. None of this should affect the case with no rotation.
* vo_opengl: don't upload potentially uninitialized memory to GL bufferwm42016-03-281-1/+1
| | | | | | | | | If the texture count is lower than 4, entries in va.textcoord[] will remain uninitialized. While this is unlikely to be a problem (since these values are unused on the shader side too), it's not nice and might explain some things which have shown up in valgrind. Fix by always initializing the whole thing.
* vo_openg: fix debanding + rectangle-textureswm42016-03-271-1/+1
|
* vo_opengl_cb: fix NULL derefwm42016-03-231-1/+2
| | | | | Broken in commit d6c99c85. vo_opengl_cb.c adds the corner case that p->osd can be NULL. This make opengl-cb always crash.
* vo_opengl: fix blend-subtitles=video in some caseswm42016-03-221-0/+1
| | | | | | | | | Shader miscompilation and bad output. Regression probably since commit 93546f0c (or one of the following ones). Fixes #2982.
* vo_opengl, osd: allow osc.lua to react faster on resizeswm42016-03-211-0/+2
| | | | | | | | | Glitches when resizing are still possible, but are reduced. Other VOs could support this too, but don't need to do so. (Totally avoiding glitches would be much more effort, and probably not worth the trouble. How about you just watch the video the player is playing, instead of spending your time resizing the window.)
* vo_opengl: fix operation without GL_ARB_texture_rgwm42016-03-171-4/+11
| | | | | | | | This also gets rid of the kind of hard to read texture swizzle setup and turns it into something dumber. Assumes that we don't create any FBOs with 2 channel formats. (Only the video source textures are handled by this commit.)
* vo_opengl: fix sharpen filterwm42016-03-161-1/+2
| | | | | | Regression since commit 93546f0c. Fixes #2956.
* vo_opengl: refactor superxbr algorithmNiklas Haas2016-03-071-1/+2
| |