YV12 format and OpenGl


I have YV12 format pictures (or video data) and i would like to use them with OpenGl (texture).
Can OpenGl texture YV12 without any conversion (eg. to RGB)?
So, basically, is it possible to use YV12 format with OpenGl, please?

Thanks a lot for your answer/help.
Wish you a nice day.


AFAIK that isn’t possible, but you can do the conversion using shaders.
Maybe the sample code at the bottom of this page will help.

Hi NaVsetko,

core OpenGL does not have external formats handling YUV planar formats like YV12 and I420. Regarding YUV external formats, the Apple and Mesa OpenGL implementations have extensions for handling YUV packed formats like YUYV and UYVY that are respectively called GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture.

For the planar formats, the best solution is to use a pixel shader converting from YUV to RGB. Here is a fragment program that can do that using multitexturing with a texture for each three planes:

ATTRIB position = fragment.texcoord[0];
TEMP R0, R1;
TEX R0, position, texture[0], 2D;
MAD R0, R0, 1.164, -0.073;
TEX R1.r, position, texture[1], 2D;
TEX R1.g, position, texture[2], 2D;
SUB R1.rg, R1, { 0.5, 0.5 };
MAD R0.rgb, { 0, -0.391, 2.018 }, R1.rrra, R0;
MAD R0.rgb, { 1.596, -0.813, 0 }, R1.ggga, R0;
MUL result.color, fragment.color, R0;

The other lot less efficient solution is to do the color space conversion to RGB in the CPU…