I’m trying to implement video playing within my OpenGL app. I have some code that does most of what I want, but not using OpenGL. It creates a frame as a YUV overlay, which is then displayed. I need to find a way to display the YUV overlay as a texture within OpenGL. To the best of my knowledge I must convert the frame to a RGB texture. This can be done in software, but since modern video cards (I have a GeForce4 Ti 4400) can do this much faster, I’d really like to be able to harness the power of the GPU.
I saw a SGI newsgroup post about drawing into a pbuffer with YUV source packing and RGBA destination. Is this the way to go? Is there a better way? Can someone point me to some sample code? Any tips?
I assume there exists a 3x3 matrix to rotate YUV colors to RGB colors. If so, you need to apply this 3x3 matrix to each pixel’s final color.
This can be done in the register combiners on nvidia hardware. Input the matrix as per-stage register combiner constants using glCombinerStageParameterNV(). You’ll be doing three dot products and three adds on your (otherwise) final pixel color, so if I’m thinking about it right you’ll need two or three general combiner stages in addition to any you may already have.
Thanks NitroGL and Zeno. It has also been suggested to me that I should be able to do the color space transformation using the color matrix (in GL_ARB_imaging). It is not clear whether one approach or the other would be faster.
Well, if there’s an extension for this very thing, it would probably be the fastest and it wouldn’t tie up register combiners that you could use for something else.
However, as we all know, there’s really only one way to find out .
Here’s some ARB_f_p code that I made to convert YUV to RGB (not a complete frag program of course). In is the input image (YUV mapped to RGB), Out is the image output (the converted YUV to RGB), temp is just a TEMP var.
I don’t believe my GF4 driver supports ARB_f_p, so this precise method won’t be available. But a version of it using register combiners may be feasible.