tests/cuda4.1sdk/tests/postProcessGL/main.cpp
void processImage()
{
    // run the Cuda kernel
    process(image_width, image_height, blur_radius);

    // CUDA generated data in cuda memory or in a mapped PBO made of BGRA 8 bits
    // 2 solutions, here :
    // - use glTexSubImage2D(), there is the potential to loose performance in possible hidden conversion
    // - map the texture and blit the result thanks to CUDA API
#ifdef USE_TEXSUBIMAGE2D
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo_dest);

    glBindTexture(GL_TEXTURE_2D, tex_cudaResult);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 
                    image_width, image_height, 
                    GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    CUT_CHECK_ERROR_GL();
    glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
#else
    // We want to copy cuda_dest_resource data to the texture
    // map buffer objects to get CUDA device pointers
    cudaArray *texture_ptr;
    cutilSafeCall(cudaGraphicsMapResources(1, &cuda_tex_result_resource, 0));
    cutilSafeCall(cudaGraphicsSubResourceGetMappedArray(&texture_ptr, cuda_tex_result_resource, 0, 0));

    int num_texels = image_width * image_height;
    int num_values = num_texels * 4;
    int size_tex_data = sizeof(GLubyte) * num_values;
    cutilSafeCall(cudaMemcpyToArray(texture_ptr, 0, 0, cuda_dest_resource, size_tex_data, cudaMemcpyDeviceToDevice));

    cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_tex_result_resource, 0));
#endif
}
// copy image and process using CUDA
copy image and process using CUDA
copy image and process using CUDA
void processImage()
{
    process(image_width, image_height, blur_radius);
#ifdef USE_TEXSUBIMAGE2D
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo_dest);
    glBindTexture(GL_TEXTURE_2D, tex_cudaResult);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 
                    image_width, image_height, 
                    GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    CUT_CHECK_ERROR_GL();
    glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
#else
    cudaArray *texture_ptr;
    cutilSafeCall(cudaGraphicsMapResources(1, &cuda_tex_result_resource, 0));
    cutilSafeCall(cudaGraphicsSubResourceGetMappedArray(&texture_ptr, cuda_tex_result_resource, 0, 0));
    int num_texels = image_width * image_height;
    int num_values = num_texels * 4;
    int size_tex_data = sizeof(GLubyte) * num_values;
    cutilSafeCall(cudaMemcpyToArray(texture_ptr, 0, 0, cuda_dest_resource, size_tex_data, cudaMemcpyDeviceToDevice));
    cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_tex_result_resource, 0));
#endif
}
void processImage ( ) { process ( image_width , image_height , blur_radius ) ; #ifdef USE_TEXSUBIMAGE2D glBindBuffer ( GL_PIXEL_UNPACK_BUFFER_ARB , pbo_dest ) ; glBindTexture ( GL_TEXTURE_2D , tex_cudaResult ) ; glTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , image_width , image_height , GL_RGBA , GL_UNSIGNED_BYTE , NULL ) ; CUT_CHECK_ERROR_GL ( ) ; glBindBuffer ( GL_PIXEL_PACK_BUFFER_ARB , 0 ) ; glBindBuffer ( GL_PIXEL_UNPACK_BUFFER_ARB , 0 ) ; #else cudaArray * texture_ptr ; cutilSafeCall ( cudaGraphicsMapResources ( 1 , & cuda_tex_result_resource , 0 ) ) ; cutilSafeCall ( cudaGraphicsSubResourceGetMappedArray ( & texture_ptr , cuda_tex_result_resource , 0 , 0 ) ) ; int num_texels = image_width * image_height ; int num_values = num_texels * 4 ; int size_tex_data = sizeof ( GLubyte ) * num_values ; cutilSafeCall ( cudaMemcpyToArray ( texture_ptr , 0 , 0 , cuda_dest_resource , size_tex_data , cudaMemcpyDeviceToDevice ) ) ; cutilSafeCall ( cudaGraphicsUnmapResources ( 1 , & cuda_tex_result_resource , 0 ) ) ; #endif }
copy image and process using CUDA
copy image and process using CUDA
// run the Cuda kernel // CUDA generated data in cuda memory or in a mapped PBO made of BGRA 8 bits // 2 solutions, here : // - use glTexSubImage2D(), there is the potential to loose performance in possible hidden conversion // - map the texture and blit the result thanks to CUDA API // We want to copy cuda_dest_resource data to the texture // map buffer objects to get CUDA device pointers