Data is clamped when using Cuda-opengl interface?

I am using a routine to transfer data from a CUDA context to an opengl display routine. With some debugging, I have found that the data becomes clamped between 0 and 1 before reaching my display routine. The display routine works in a pure opengl environment with unclamped data, so I am sure that it is not the cause of the problem I am seeing.

The code I use to do the display is shown below:

   // Setup

    // -----------------------

   GLuint cuda_opengl_bridge;

    GLuint display_texture;

    float* cuda_mem;

   glGenBuffers(1, &cuda_opengl_bridge);

    glBindBuffer(GL_ARRAY_BUFFER, cuda_opengl_bridge);

   // buffer data

    int display_size = . . .;

    void* data = malloc(display_size);

    glBufferData(GL_ARRAY_BUFFER, display_size, data, GL_DYNAMIC_DRAW);


    glBindBuffer(GL_ARRAY_BUFFER, 0);




   // Display

    // -----------------------

   float* transfer_data;


    cudaGLMapBufferObject((void**)&transfer_data, cuda_opengl_bridge);

   // cuda routine that reorders the data in cuda_mem, copying to transfer_data

    pack_for_display(transfer_data, cuda_mem);

   // Data is clamped somewhere between here . . .



   glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, cuda_opengl_bridge);


    glTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, width, height, GL_RGBA, GL_FLOAT, NULL);

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

   // and here . . . 

   // my display routine


Please excuse any simple syntactic errors with the above, as I had to cut this down a bit from the real source. Any thoughts?

CUDA itself does not apply any clamping to floating point data. Are you sure the data is not being clamped at some point in the OpenGL pipeline?

The ARB_color_buffer_float spec has some options to control color clamping:…uffer_float.txt


Thanks for the suggestion; the call


after texture creation solved my issue. Is the above clamping mode set somwhere by default? The document you referenced seemed to indicate otherwise:

To rebut that, however, clearing it once after texture creation solved the issue, so I am sure that I am not inadvertently setting it after that point. I don’t use that call anywhere else; do any other common functions set this as a side effect? Thanks for your help/insight.


Are you sure the internal tex format is correct? What is the FLOAT_RGBA32 value? I expect some GL_ constant here. As you use texRect this should be GL_FLOAT_RGBA32_NV (= 0x888b)


Sorry, when including the above code I forgot the following:


You are mixing the GL_NV_float_buffer and the GL_ARB_texture_float extension. If you use the GL_TEXTURE_RECTANGLE_NV target, you have to use GL_FLOAT_RGBA32_NV. For GL_RGBA32F_ARB format, you need a GL_TEXTURE_2D target.