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);

    free(data);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

   glGenTextures(1,&display_texture);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV,display_texture);

    glTexImage2D(GL_TEXTURE_RECTANGLE_NV,0,FLOAT_RGBA32,width/2,height/2,0,GL_RGBA,GL_FLOAT,NULL);

   // Display

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

   float* transfer_data;

    cudaGLRegisterBufferObject(cuda_opengl_bridge);    

    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 . . .

   cudaGLUnmapBufferObject(cuda_opengl_bridge);

    cudaGLUnregisterBufferObject(cuda_opengl_bridge);

   glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, cuda_opengl_bridge);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV,display_texture);

    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

    show(display_texture);

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:
http://www.nvidia.com/dev_content/nvopengl…uffer_float.txt

e.g.
glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);

Thanks for the suggestion; the call

glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);

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.

glTexImage2D(GL_TEXTURE_RECTANGLE_NV,0,FLOAT_RGBA32,width/2,height/2,0,GL_RGBA,GL_FLOAT,NULL);

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)

Peter

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

#define FLOAT_RGBA32 GL_RGBA32F_ARB

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.

Peter