Converting RGBA to ARGB (glReadPixels -> AVAssetWriter)

前端 未结 5 1861
时光取名叫无心
时光取名叫无心 2021-01-06 17:37

I want to record images, rendered with OpenGL, into a movie-file with the help of AVAssetWriter. The problem arises, that the only way to access pixels from an

5条回答
  •  甜味超标
    2021-01-06 18:06

    I came to the conclusion, that the fastest way to convert RGBA to ARGB would be to give glReadPixels the buffer shifted by one byte

    This will however shift your alpha values by 1 pixel as well. Here's another suggestion:

    Render the picture to a texture (using a FBO with that texture as color attachment). Next render that texture to another framebuffer, with a swizzling fragment shader:

    #version ...
    uniform sampler2D image;
    uniform vec2 image_dim;
    void main() 
    {
        // we want to address texel centers by absolute fragment coordinates, this
        // requires a bit of work (OpenGL-ES SL doesn't provide texelFetch function).
        gl_FragColor.rgba = 
            texture2D(image, vec2( (2*gl_FragCoord.x + 1)/(2*image_dim.y), 
                                   (2*gl_FragCoord.y + 1)/(2*image_dim.y) )
            ).argb; // this swizzles RGBA into ARGB order if read into a RGBA buffer
    }
    

提交回复
热议问题