This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA2HG: 【OpenGL】 How to use the FBO with NV12

Part Number: TDA2HG
Other Parts Discussed in Thread: TDA2

Hello:

Environment

VisionSDK 3.05

As you known, the OpenGL on visonSDK only support the NV12 input, thus when we bind the texture, have to use 

    glGenTextures(1, outTexIndex);
    System_eglCheckGlError("glGenTextures");
    printf("outTexIndex 0x%x \n",*outTexIndex);

    glBindTexture(GL_TEXTURE_EXTERNAL_OES, *outTexIndex);
    System_eglCheckGlError("glBindTexture");

    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    System_eglCheckGlError("glTexParameteri");

    glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)textImg);
    System_eglCheckGlError("glEGLImageTargetTexture2DOES");	

and if we want to use the FBO(framebufferobject), like:

        glBindTexture(GL_TEXTURE_2D, m_stage_texture[i]);
#if GLOBAL_RUN_ENV_DESKTOP == 0 && defined APP_RUN_ON_IMX6
        // map addr to opengl viv
        (*g_pFNglTexDirectVIVMap)(GL_TEXTURE_2D, width, height, fbo_format,
            (void **)&(m_stage_fbo_vaddr[i]), (const GLuint *)(&m_stage_fbo_paddr[i]));
#else
        glTexImage2D(GL_TEXTURE_2D, 0, fbo_format, width, height,
            0, fbo_format, GL_UNSIGNED_BYTE, NULL);    
#endif
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
        // bind renderbuffer and create a 16-bit depth buffer
        // width and height of renderbuffer = width and height of
        // the texture
        glBindRenderbuffer(GL_RENDERBUFFER, m_stage_depth_render_buffer[i]);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);

        // bind the framebuffer
        glBindFramebuffer(GL_FRAMEBUFFER, m_stage_fbo[i]);
        // specify texture as color attachment
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_stage_texture[i], 0);
        eglCheckGlError("glFramebufferTexture2D");
        printf("andy debug test glFramebufferTexture2D \n");
        // specify depth_renderbufer as depth attachment
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_stage_depth_render_buffer[i]);
        // check for framebuffer complete
        GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

for above code, how we can use the FBO with NV12?

per discussed before, the FBO only support the RGB, that means we can't use FBO with NV12?

  • Hello,

    Can you please describe your use case? Are you trying to read NV12 and write to an RGB FBO? Or are you trying to write YUV output to an FBO? Reading YUV textures and writing to an RGB framebuffer should work just fine. For your reference, I am attaching a text file with EGL and OpenGLES extensions that we support.

    sgx_extensions.txt
    EGL extensions: EGL_KHR_image EGL_KHR_image_base EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_IMG_cl_image EGL_KHR_fence_sync EGL_IMG_context_priority EGL
    _IMG_hibernate_process EGL_IMG_image_plane_attribs EGL_KHR_surfaceless_context EGL_KHR_wait_sync EGL_KHR_create_context EGL_WL_bind_wayland_display EGL_EXT_image_dma_buf_import
    EGL client APIs are: OpenGL_ES 
    
    OpenGL ES 1 Information:
    
    GLES 2 String Information :
     GL_VENDOR = Imagination Technologies 
     GL_RENDERER = PowerVR SGX 544MP 
     GL_VERSION = OpenGL ES 2.0 build 1.17@4948957 
     GL_SHADING_LANGUAGE_VERSION = OpenGL ES GLSL ES 1.00 build 1.17@4948957 
     GL_EXTENSIONS = GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth24 GL_OES_depth_texture GL_OES_egl_sync GL_OES_element_index_uint GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_fbo_render_mipmap GL_OE
    S_fragment_precision_high GL_OES_get_program_binary GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_required_internalformat GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_surfaceless_context GL_
    OES_texture_float GL_OES_texture_half_float GL_OES_texture_npot GL_OES_vertex_array_object GL_OES_vertex_half_float GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_EXT_draw_buffers GL_EXT_multi_draw_arr
    ays GL_EXT_multisampled_render_to_texture GL_EXT_occlusion_query_boolean GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_IMG_multisampled_rend
    er_to_texture GL_IMG_program_binary GL_IMG_read_format GL_IMG_shader_binary GL_IMG_texture_compression_pvrtc GL_IMG_texture_compression_pvrtc2 GL_IMG_texture_format_BGRA8888 GL_IMG_texture_npot GL_IMG_uni
    form_buffer_object GL_KHR_debug GL_EXT_texture_storage 
    
    OpenGL ES 1 Information:
    
    GLES String Information :
     GL_VENDOR = Imagination Technologies 
     GL_RENDERER = PowerVR SGX 544MP 
     GL_VERSION = OpenGL ES-CM 1.1 
     GL_EXTENSIONS = GL_OES_byte_coordinates GL_OES_fixed_point GL_OES_single_precision GL_OES_matrix_get GL_OES_read_format GL_OES_compressed_paletted_texture GL_OES_point_sprite GL_OES_point_size_array GL_O
    ES_matrix_palette GL_OES_draw_texture GL_OES_query_matrix GL_OES_texture_env_crossbar GL_OES_texture_mirrored_repeat GL_OES_texture_cube_map GL_OES_blend_subtract GL_OES_blend_func_separate GL_OES_blend_e
    quation_separate GL_OES_stencil_wrap GL_OES_extended_matrix_palette GL_OES_framebuffer_object GL_OES_rgb8_rgba8 GL_OES_depth24 GL_OES_stencil8 GL_OES_compressed_ETC1_RGB8_texture GL_OES_mapbuffer GL_OES_E
    GL_image GL_OES_EGL_image_external GL_EXT_multi_draw_arrays GL_OES_required_internalformat GL_OES_fbo_render_mipmap GL_IMG_read_format GL_IMG_texture_compression_pvrtc GL_IMG_texture_format_BGRA8888 GL_EX
    T_texture_format_BGRA8888 GL_OES_egl_sync GL_IMG_vertex_array_object GL_APPLE_texture_2D_limited_npot GL_EXT_texture_storage 
    
    

    Regards

    Hemant

  • Hello,

    Can you please describe your use case? Are you trying to read NV12 and write to an RGB FBO? Or are you trying to write YUV output to an FBO? Reading YUV textures and writing to an RGB framebuffer should work just fine. For your reference, I am attaching a text file with EGL and OpenGLES extensions that we support.

    7268.sgx_extensions.txt
    EGL extensions: EGL_KHR_image EGL_KHR_image_base EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_IMG_cl_image EGL_KHR_fence_sync EGL_IMG_context_priority EGL
    _IMG_hibernate_process EGL_IMG_image_plane_attribs EGL_KHR_surfaceless_context EGL_KHR_wait_sync EGL_KHR_create_context EGL_WL_bind_wayland_display EGL_EXT_image_dma_buf_import
    EGL client APIs are: OpenGL_ES 
    
    OpenGL ES 1 Information:
    
    GLES 2 String Information :
     GL_VENDOR = Imagination Technologies 
     GL_RENDERER = PowerVR SGX 544MP 
     GL_VERSION = OpenGL ES 2.0 build 1.17@4948957 
     GL_SHADING_LANGUAGE_VERSION = OpenGL ES GLSL ES 1.00 build 1.17@4948957 
     GL_EXTENSIONS = GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth24 GL_OES_depth_texture GL_OES_egl_sync GL_OES_element_index_uint GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_fbo_render_mipmap GL_OE
    S_fragment_precision_high GL_OES_get_program_binary GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_required_internalformat GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_surfaceless_context GL_
    OES_texture_float GL_OES_texture_half_float GL_OES_texture_npot GL_OES_vertex_array_object GL_OES_vertex_half_float GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_EXT_draw_buffers GL_EXT_multi_draw_arr
    ays GL_EXT_multisampled_render_to_texture GL_EXT_occlusion_query_boolean GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_IMG_multisampled_rend
    er_to_texture GL_IMG_program_binary GL_IMG_read_format GL_IMG_shader_binary GL_IMG_texture_compression_pvrtc GL_IMG_texture_compression_pvrtc2 GL_IMG_texture_format_BGRA8888 GL_IMG_texture_npot GL_IMG_uni
    form_buffer_object GL_KHR_debug GL_EXT_texture_storage 
    
    OpenGL ES 1 Information:
    
    GLES String Information :
     GL_VENDOR = Imagination Technologies 
     GL_RENDERER = PowerVR SGX 544MP 
     GL_VERSION = OpenGL ES-CM 1.1 
     GL_EXTENSIONS = GL_OES_byte_coordinates GL_OES_fixed_point GL_OES_single_precision GL_OES_matrix_get GL_OES_read_format GL_OES_compressed_paletted_texture GL_OES_point_sprite GL_OES_point_size_array GL_O
    ES_matrix_palette GL_OES_draw_texture GL_OES_query_matrix GL_OES_texture_env_crossbar GL_OES_texture_mirrored_repeat GL_OES_texture_cube_map GL_OES_blend_subtract GL_OES_blend_func_separate GL_OES_blend_e
    quation_separate GL_OES_stencil_wrap GL_OES_extended_matrix_palette GL_OES_framebuffer_object GL_OES_rgb8_rgba8 GL_OES_depth24 GL_OES_stencil8 GL_OES_compressed_ETC1_RGB8_texture GL_OES_mapbuffer GL_OES_E
    GL_image GL_OES_EGL_image_external GL_EXT_multi_draw_arrays GL_OES_required_internalformat GL_OES_fbo_render_mipmap GL_IMG_read_format GL_IMG_texture_compression_pvrtc GL_IMG_texture_format_BGRA8888 GL_EX
    T_texture_format_BGRA8888 GL_OES_egl_sync GL_IMG_vertex_array_object GL_APPLE_texture_2D_limited_npot GL_EXT_texture_storage 
    
    

    Regards

    Hemant

  • Hi Hemant:

      see the flow of my case:

      

    1. did the visionsdk OpenGL support the RGB as texture? all the glsl using samplerExternalOES which to load NV12
    2. for the FBO, as previous post said, FBO only support RGB, if so how can render it with NV12 texutue together
    3. did FBO support NV12?

    above all, the FBO input should be NV12,and which format does FBO output? RGB or NV12. and can you share some sample code to demo this?

    thanks....

  • Hello,

    Both RGB and YUV textures are supported.

    FBO supports RGB and the GPU will convert YUV to RGB.

    On TDA2, FBO has to be RGB. Does your use case need YUV output?

    Regards

    Hemant

  • Hi Hemant:

    Hemant Hariyani said:
    On TDA2, FBO has to be RGB. Does your use case need YUV output?

    it seem to use YUV, because other texture is YUV, we don't know whether the tda2 support use RGB and YUV mixed 

  • Hello,

    You can read YUV texture and output to RGB FBO. You can use EXT_image_dma_buf_import to create an NV12 EGL Image and then use GL_OES_EGL_image_external to read the image as a texture. Your FBO can continue to be RGB format.

    Regards

    Hemant

  • Hi Hemant:

      per discussion above, we looks need to use FBO with YUV not the RGB, can you share how to use FBO with YUV texture?

  • Hi Hemant:

    But the RGB FBO should render together with the YUV texture as it's the parts of whole rendering like card model, camera image.