AnsweredAssumed Answered

clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Question asked by zoomzoom on Aug 13, 2012



I am struggling with this error for some days already and I just can't figure out what I'm missing, so if any of you has any suggestion, I would be very grateful.


My application uses OpenCL for some data processing and OpenGL to display the results. During the application lifetime, the window displaying the results may be closed, and another window can be opened. In this case a new OpenGL-OpenCL context initialization must be run.


Beginning with the second initialization, clCreateFromGLBuffer fails returning CL_INVALID_GL_OBJECT. This happens on a HD 7850 running OpenCL 1.2 AMD-APP 938.1.


I get no errors if running the same code on NVIDIA GPU (8800GTX or 280 GTX).


Also, I get no errors if the previous OpenGL buffer object is not destroyed before initializing a new context.


Calling glIsBuffer just before clCreateFromGLBuffer always returns TRUE, so the buffer object must be valid.


Using gDEBugger I have noticed the following:

     clCreateContext - creates a new gl context by calling wglCreateContext and sets it to share lists with the input provided gl context by calling wglShareLists

     clCreateFromGLBuffer - works with the context created above (in clCreateContext). It also calls glIsBuffer to validate the input buffer object.


The big problem is that on the second call, clCreateContext does not create a new context anymore. I don't know why.

Moreover, clCreateFromGLBuffer will makeCurrent the context from the previous call (the first context initializations)! This is why I thing glIsBuffer will return FALSE in this situation. But what I don't understand is why the second context initialization uses data from the first one.


Attached is a simplified code showing this strange behavior. Just call SimpleGLCL() and then again SimpleGLCL(), and clCreateFromGLBuffer will throw the -60 error.


If you comment the two lines selecting and deleting the object buffer, there will be no errors.


Thank you!