test/opengl_interop/main.c
void
view_on_render(void* param)
{    
    struct application* app = (struct application*)param;
    
#ifdef TEST_OPENGL_INTEROP_MULTI_THREAD
    if  ( (app->opengl_context & OPENGL_CONTEXT_ATTACHED) && (app->opengl_context & OPENGL_CONTEXT_REQUEST) ) {
        pthread_mutex_lock(&app->mutex);
        view_opengl_detach(app->view);
        app->opengl_context = OPENGL_CONTEXT_DETACHED;
        pthread_mutex_unlock(&app->mutex);
    }
    // If OpenGL context is detach we can't render
    while ( app->opengl_context & OPENGL_CONTEXT_DETACHED ) {
        if  ( app->opengl_context & OPENGL_CONTEXT_REQUEST ) {
            pthread_mutex_lock(&app->mutex);
            view_opengl_attach(app->view);
            app->opengl_context = OPENGL_CONTEXT_ATTACHED;
            pthread_mutex_unlock(&app->mutex);
        }
        usleep(1000);
    }
    
#endif

#ifndef TEST_OPENGL_INTEROP_MULTI_THREAD
    image_generate(app);
    app->new_image = 1;
#endif

    TIMER_INIT();
    TIMER_START();

    // Load image only when is new
    if ( app->new_image == 0 )
        return;
    app->new_image = 0;
    
    if ( app->decoder_output.type == GPUJPEG_DECODER_OUTPUT_OPENGL_TEXTURE ) {
        // Do nothing texture is already updated
    } else {
        // Set texture data from host memory
        glBindTexture(GL_TEXTURE_2D, app->texture_id);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, app->width, app->height, 0, GL_RGB, GL_UNSIGNED_BYTE, app->decoder_output.data);
    }
    glFinish();
    
    view_set_texture(app->view, app->texture_id);
        
    TIMER_STOP_PRINT("View: ImageLoad");
}
/**
 * On render callback for view. Check if cuda_context is available (means new 
 * image is available) and if it is, load new image to view.
 */
On render callback for view. Check if cuda_context is available (means new
image is available) and if it is, load new image to view.
On render callback for view . Check if cuda_context is available ( means new image is available ) and if it is load new image to view .
void
view_on_render(void* param)
{    
    struct application* app = (struct application*)param;
#ifdef TEST_OPENGL_INTEROP_MULTI_THREAD
    if  ( (app->opengl_context & OPENGL_CONTEXT_ATTACHED) && (app->opengl_context & OPENGL_CONTEXT_REQUEST) ) {
        pthread_mutex_lock(&app->mutex);
        view_opengl_detach(app->view);
        app->opengl_context = OPENGL_CONTEXT_DETACHED;
        pthread_mutex_unlock(&app->mutex);
    }
    while ( app->opengl_context & OPENGL_CONTEXT_DETACHED ) {
        if  ( app->opengl_context & OPENGL_CONTEXT_REQUEST ) {
            pthread_mutex_lock(&app->mutex);
            view_opengl_attach(app->view);
            app->opengl_context = OPENGL_CONTEXT_ATTACHED;
            pthread_mutex_unlock(&app->mutex);
        }
        usleep(1000);
    }
#endif
#ifndef TEST_OPENGL_INTEROP_MULTI_THREAD
    image_generate(app);
    app->new_image = 1;
#endif
    TIMER_INIT();
    TIMER_START();
    if ( app->new_image == 0 )
        return;
    app->new_image = 0;
    if ( app->decoder_output.type == GPUJPEG_DECODER_OUTPUT_OPENGL_TEXTURE ) {
    } else {
        glBindTexture(GL_TEXTURE_2D, app->texture_id);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, app->width, app->height, 0, GL_RGB, GL_UNSIGNED_BYTE, app->decoder_output.data);
    }
    glFinish();
    view_set_texture(app->view, app->texture_id);
    TIMER_STOP_PRINT("View: ImageLoad");
}
void view_on_render ( void * param ) { struct application * app = ( struct application * ) param ; #ifdef TEST_OPENGL_INTEROP_MULTI_THREAD if ( ( app -> opengl_context & OPENGL_CONTEXT_ATTACHED ) && ( app -> opengl_context & OPENGL_CONTEXT_REQUEST ) ) { pthread_mutex_lock ( & app -> mutex ) ; view_opengl_detach ( app -> view ) ; app -> opengl_context = OPENGL_CONTEXT_DETACHED ; pthread_mutex_unlock ( & app -> mutex ) ; } while ( app -> opengl_context & OPENGL_CONTEXT_DETACHED ) { if ( app -> opengl_context & OPENGL_CONTEXT_REQUEST ) { pthread_mutex_lock ( & app -> mutex ) ; view_opengl_attach ( app -> view ) ; app -> opengl_context = OPENGL_CONTEXT_ATTACHED ; pthread_mutex_unlock ( & app -> mutex ) ; } usleep ( 1000 ) ; } #endif #ifndef TEST_OPENGL_INTEROP_MULTI_THREAD image_generate ( app ) ; app -> new_image = 1 ; #endif TIMER_INIT ( ) ; TIMER_START ( ) ; if ( app -> new_image == 0 ) return ; app -> new_image = 0 ; if ( app -> decoder_output . type == GPUJPEG_DECODER_OUTPUT_OPENGL_TEXTURE ) { } else { glBindTexture ( GL_TEXTURE_2D , app -> texture_id ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGB , app -> width , app -> height , 0 , GL_RGB , GL_UNSIGNED_BYTE , app -> decoder_output . data ) ; } glFinish ( ) ; view_set_texture ( app -> view , app -> texture_id ) ; TIMER_STOP_PRINT ( " " ) ; }
On render callback for view.
On render callback for view .
// If OpenGL context is detach we can't render // Load image only when is new // Do nothing texture is already updated // Set texture data from host memory