Skip to content
  • Romain Vimont's avatar
    opengl: use TransformMatrix to apply OpenGL vflip · 0686e998
    Romain Vimont authored
    Uploading a picture_t to OpenGL flips it vertically.
    
    To display the video in the correct orientation, the renderer reversed
    the transformation: each vertex received as attribute texture
    coordinates (x, 1-y) instead of (x, y), in order to flip the image
    vertically.
    
    This caused several problems.
    
    Firstly, the renderer must be independent of the input picture storage.
    Otherwise, when it will receive an input in the correct orientation, it
    will wrongly apply a vertical flip.
    
    Secondly, since the vflip was applied on the input coordinates, it
    occurred before the orientation transform:
    
        OrientationMatrix * VFlipMatrix * input_coords  (semantically)
    
    whereas the correct transformation is:
    
        VFlipMatrix * OrientationMatrix * input_coords
    
    (for reasons explained in e329c4bb).
    
    Since matrix multiplication is not commutative, it resulted in a
    wrong orientation in some cases (for example if OrientationMatrix
    contains a rotation by 90°).
    
    (In fact, in pratice, this case still worked, because the initialization
    of OrientationMatrix was also wrong, see the two previous commits).
    
    To fix all these problems, initialize the texture coordinates in the
    normal orientation in the renderer, and apply the vertical flip using
    the TransformationMatrix in the sampler.
    
    This also allows to simplify the Android interop, which can just provide
    its own transform matrix without compensating for the vertical flip
    that was applied in the renderer.
    0686e998