Search code examples
opengl-estexturesopengl-es-2.0yuvqnx

How to emulate GL_TEXTURE_EXTERNAL_OES texture?


I have a OpenGL ES 2.0 QNX application that uses camera input, makes some processing and renders something to screen.

All my shaders take GL_TEXTURE_EXTERNAL_OES texture from the camera as input and it's format is YUV422.

I want to test my application on the target platform (QNX) using RGB images in png format.

The question is: how can I create GL_TEXTURE_EXTERNAL_OES texture from RGB image to emulate the input from the camera for my application?


Solution

  • Answering own question.

    Steps to create GL_TEXTURE_EXTERNAL_OES texture from RGB buffer on QNX.

    1.Converting RGB to YUV422 format on CPU

    2.Creating pixmap buffer using screen

    EGLNativePixmapType pObjEglPixmap = ...
    

    3.Binding pixmap to GL_TEXTURE_EXTERNAL_OES texture using EGLImageKHR object

    EGLImageKHR pObjTextureEglImage = eglCreateImageKHR(eglDisplay,
                                                        EGL_NO_CONTEXT,
                                                        EGL_NATIVE_PIXMAP_KHR,
                                                        pObjEglPixmap,
                                                        NULL);
    
    GLuint pObjTextureId;
    glGenTextures(1, &pObjTextureId);
    
    glBindTexture(GL_TEXTURE_EXTERNAL_OES, pObjTextureId);
    
    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, 
                                 (GLeglImageOES)pObjTextureEglImage);