test/opengl_interop/main.c
void
view_on_init(void* param)
{
    struct application* app = (struct application*)param;
    
    // Create image (image should be created after OpenGL is initialized)
    app->image = image_create(app->width, app->height);
    assert(app->image != NULL);
    
    // Create texture
    glGenTextures(1, &app->texture_id);
    glBindTexture(GL_TEXTURE_2D, app->texture_id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, app->width, app->height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glBindTexture(GL_TEXTURE_2D, 0);
    
    // Init JPEG params
    struct gpujpeg_parameters param_coder;
    gpujpeg_set_default_parameters(&param_coder);
    struct gpujpeg_image_parameters param_image;
    gpujpeg_image_set_default_parameters(&param_image);
    param_image.width = app->width;
    param_image.height = app->height;
    
    // Init JPEG encoder and decoder
    app->encoder = gpujpeg_encoder_create(&param_coder, &param_image);
    assert(app->encoder != NULL);
    app->decoder = gpujpeg_decoder_create();
    assert(app->decoder != NULL);
    assert(gpujpeg_decoder_init(app->decoder, &param_coder, &param_image) == 0);
    
    // Init JPEG texture
    app->texture = gpujpeg_opengl_texture_register(app->texture_id, GPUJPEG_OPENGL_TEXTURE_WRITE);
    assert(app->texture != NULL);

    // Init JPEG decoder output
    if ( app->transfer_type == TRANSFER_DEVICE ) {
        gpujpeg_decoder_output_set_texture(&app->decoder_output, app->texture);
    } else {
        gpujpeg_decoder_output_set_default(&app->decoder_output);
    }
#ifdef TEST_OPENGL_INTEROP_MULTI_THREAD
    // Set texture callbacks
    app->texture->texture_callback_param = (void*)app;
    app->texture->texture_callback_attach_opengl = &thread_image_attach_opengl;
    app->texture->texture_callback_detach_opengl = &thread_image_detach_opengl;
#endif
}
/**
 * On init callback for view.
 */
On init callback for view.
On init callback for view .
void
view_on_init(void* param)
{
    struct application* app = (struct application*)param;
    app->image = image_create(app->width, app->height);
    assert(app->image != NULL);
    glGenTextures(1, &app->texture_id);
    glBindTexture(GL_TEXTURE_2D, app->texture_id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, app->width, app->height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glBindTexture(GL_TEXTURE_2D, 0);
    struct gpujpeg_parameters param_coder;
    gpujpeg_set_default_parameters(&param_coder);
    struct gpujpeg_image_parameters param_image;
    gpujpeg_image_set_default_parameters(&param_image);
    param_image.width = app->width;
    param_image.height = app->height;
    app->encoder = gpujpeg_encoder_create(&param_coder, &param_image);
    assert(app->encoder != NULL);
    app->decoder = gpujpeg_decoder_create();
    assert(app->decoder != NULL);
    assert(gpujpeg_decoder_init(app->decoder, &param_coder, &param_image) == 0);
    app->texture = gpujpeg_opengl_texture_register(app->texture_id, GPUJPEG_OPENGL_TEXTURE_WRITE);
    assert(app->texture != NULL);
    if ( app->transfer_type == TRANSFER_DEVICE ) {
        gpujpeg_decoder_output_set_texture(&app->decoder_output, app->texture);
    } else {
        gpujpeg_decoder_output_set_default(&app->decoder_output);
    }
#ifdef TEST_OPENGL_INTEROP_MULTI_THREAD
    app->texture->texture_callback_param = (void*)app;
    app->texture->texture_callback_attach_opengl = &thread_image_attach_opengl;
    app->texture->texture_callback_detach_opengl = &thread_image_detach_opengl;
#endif
}
void view_on_init ( void * param ) { struct application * app = ( struct application * ) param ; app -> image = image_create ( app -> width , app -> height ) ; assert ( app -> image != NULL ) ; glGenTextures ( 1 , & app -> texture_id ) ; glBindTexture ( GL_TEXTURE_2D , app -> texture_id ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGB , app -> width , app -> height , 0 , GL_RGB , GL_UNSIGNED_BYTE , NULL ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; struct gpujpeg_parameters param_coder ; gpujpeg_set_default_parameters ( & param_coder ) ; struct gpujpeg_image_parameters param_image ; gpujpeg_image_set_default_parameters ( & param_image ) ; param_image . width = app -> width ; param_image . height = app -> height ; app -> encoder = gpujpeg_encoder_create ( & param_coder , & param_image ) ; assert ( app -> encoder != NULL ) ; app -> decoder = gpujpeg_decoder_create ( ) ; assert ( app -> decoder != NULL ) ; assert ( gpujpeg_decoder_init ( app -> decoder , & param_coder , & param_image ) == 0 ) ; app -> texture = gpujpeg_opengl_texture_register ( app -> texture_id , GPUJPEG_OPENGL_TEXTURE_WRITE ) ; assert ( app -> texture != NULL ) ; if ( app -> transfer_type == TRANSFER_DEVICE ) { gpujpeg_decoder_output_set_texture ( & app -> decoder_output , app -> texture ) ; } else { gpujpeg_decoder_output_set_default ( & app -> decoder_output ) ; } #ifdef TEST_OPENGL_INTEROP_MULTI_THREAD app -> texture -> texture_callback_param = ( void * ) app ; app -> texture -> texture_callback_attach_opengl = & thread_image_attach_opengl ; app -> texture -> texture_callback_detach_opengl = & thread_image_detach_opengl ; #endif }
On init callback for view.
On init callback for view .
// Create image (image should be created after OpenGL is initialized) // Create texture // Init JPEG params // Init JPEG encoder and decoder // Init JPEG texture // Init JPEG decoder output // Set texture callbacks