VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_opengl_picture.h File Reference

This file defines the public OpenGL picture interface. More...

Include dependency graph for vlc_opengl_picture.h:

Go to the source code of this file.

Data Structures

struct  vlc_gl_picture
 An OpenGL picture state, with textures and a coordinate transformation matrix. More...

Macros

#define MTX(ROW, COL)

Functions

static void vlc_gl_picture_ToTexCoords (const struct vlc_gl_picture *pic, unsigned coords_count, const float *pic_coords, float *tex_coords_out)
 Convert from picture coordinates to texture coordinates, which can be used to sample at the correct location.
static void vlc_gl_picture_ComputeDirectionMatrix (const struct vlc_gl_picture *pic, float direction[static 2 *2])
 Return a matrix to orient texture coordinates.

Detailed Description

This file defines the public OpenGL picture interface.

A vlc_gl_picture stores the OpenGL textures and transformation matrix associated with a VLC picture, as provided by the interop/importer.

Macro Definition Documentation

◆ MTX

#define MTX ( ROW,
COL )
Value:
mtx[(COL)*2+(ROW)]

Referenced by vlc_gl_picture_ToTexCoords().

Function Documentation

◆ vlc_gl_picture_ComputeDirectionMatrix()

void vlc_gl_picture_ComputeDirectionMatrix ( const struct vlc_gl_picture * pic,
float direction[static 2 *2] )
inlinestatic

Return a matrix to orient texture coordinates.

This matrix is 2x2 and is stored in column-major order.

While pic_to_tex_matrix transforms any picture coordinates into texture coordinates, it may be useful for example for vertex or fragment shaders to sample one pixel to the left of the current one, or two pixels to the top. Since the input texture may be rotated or flipped, the shaders need to know in which direction is the top and in which direction is the right of the picture.

This 2x2 matrix allows to transform a 2D vector expressed in picture coordinates into a 2D vector expressed in texture coordinates.

Concretely, it contains the coordinates (U, V) of the transformed unit vectors u = / 1 \ and v = / 0 \: \ 0 / \ 1 /

/ Ux Vx \ \ Uy Vy /

It is guaranteed that:

  • both U and V are unit vectors (this matrix does not change the scaling);
  • only one of their components have a non-zero value (they may not be oblique); in other words, here are the possible values for U and V:
    /  0 \  or  / 0 \  or  / 1 \  or  / -1 \
    \ -1 /      \ 1 /      \ 0 /      \  0 /
    
  • U and V are orthogonal.

Therefore, there are 8 possible matrices (4 possible rotations, flipped or not).

It may theoretically change on every picture (the transform matrix provided by Android may change). If it has changed since the last picture, then pic->mtx_has_changed is true.

The direction matrix is extracted from pic->mtx:

mtx = / a b c \ \ d e f /

The last column (the offset part of the affine transformation) is discarded, and the 2 remaining column vectors are normalized to remove any scaling:

direction = / a/unorm b/vnorm \ \ d/unorm e/vnorm /

where unorm = norm( / a \ ) and vnorm = norm( / b \ ). \ d / \ e /

References vlc_gl_picture::mtx.

◆ vlc_gl_picture_ToTexCoords()

void vlc_gl_picture_ToTexCoords ( const struct vlc_gl_picture * pic,
unsigned coords_count,
const float * pic_coords,
float * tex_coords_out )
inlinestatic

Convert from picture coordinates to texture coordinates, which can be used to sample at the correct location.

This is a equivalent to retrieve the matrix and multiply manually.

The picture and texture coords may point to the same memory, in that case the transformation is applied in place (overwriting the picture coordinates by the texture coordinates).

Parameters
picturethe OpenGL picture
coords_countthe number of coordinates (x,y) coordinates to convert
pic_coordspicture coordinates as an array of 2*coords_count floats
tex_coords_outtexture coordinates as an array of 2*coords_count floats

References MTX, and vlc_gl_picture::mtx.